Jump to content

tween a numeric value?


pranadevil
 Share

Recommended Posts

hi all,

im wondering how can i tween a numeric value lets say.

var number1;


/// in create function
number1 = 100;




///tween from 100 to 10 and show it by a text
text1.setText( " from 100 to 10:  " + number1+ " ");

its possible?

im chasing a way to show player his score after complete world. but i wanna show him the time bonus and move the time left to zero on screen.

 

any suggestion?

Link to comment
Share on other sites

Yes, tweening a score is totally possible. Check out my Enclave Phaser Template - there's a Game.js file with gameOverScreen function, or see this commit in particular:

 
gameoverScoreTween: function() {
	this.screenGameoverScore.setText('Score: 0');
	if(this._score) {
		this.tweenedPoints = 0;
		var pointsTween = this.add.tween(this);
		pointsTween.to({ tweenedPoints: this._score }, 1000, Phaser.Easing.Linear.None, true, 500);
		pointsTween.onUpdateCallback(function(){
			this.screenGameoverScore.setText('Score: '+Math.floor(this.tweenedPoints));
		}, this);
		pointsTween.onComplete.addOnce(function(){
			this.screenGameoverScore.setText('Score: '+this._score);
		}, this);
		pointsTween.start();
	}
},

It's good to remember that when tweening the score you can hook up to onUpdateCallback to update the score text during tween.

Link to comment
Share on other sites

1 hour ago, end3r said:

Yes, tweening a score is totally possible. Check out my Enclave Phaser Template - there's a Game.js file with gameOverScreen function, or see this commit in particular:

 

gameoverScoreTween: function() {
	this.screenGameoverScore.setText('Score: 0');
	if(this._score) {
		this.tweenedPoints = 0;
		var pointsTween = this.add.tween(this);
		pointsTween.to({ tweenedPoints: this._score }, 1000, Phaser.Easing.Linear.None, true, 500);
		pointsTween.onUpdateCallback(function(){
			this.screenGameoverScore.setText('Score: '+Math.floor(this.tweenedPoints));
		}, this);
		pointsTween.onComplete.addOnce(function(){
			this.screenGameoverScore.setText('Score: '+this._score);
		}, this);
		pointsTween.start();
	}
},

It's good to remember that when tweening the score you can hook up to onUpdateCallback to update the score text during tween.

was exactly what i was looking for, thanks!

Link to comment
Share on other sites

8 minutes ago, end3r said:

I suppose it depends on the type of tween you used - in my case it was linear, so I didn't have such problems, I also used Math.floor to show only the integers.

Very curious cause i also used linear.

So did u tested yours and it reaches the final value?

Did u used a function outside update function to start the tween right?

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...