Jump to content

Tweening a numeric part of a BitmapText


BattyMilk
 Share

Recommended Posts

I have a BitmapText object displaying a numeric score. i.e "Score: 50". Is there any way I can affect the score value with a tween when the score increases so that the number rolls up to to the new value, rather than just changing the text in one hit with: 

 

this.scoreLabel.text = "Score: 100";

 

I know that I could achieve this with the update function with checks for a flag that I set when the score goes up to increase the score until the desired value is reached, however it seems a little unnecessary and wasteful to be checking for this flag every cycle of the update function.

 

Does anyone have any bright ideas how I could achieve this?

Ta

Link to comment
Share on other sites

To prevent the build up of tumbleweeds, here's how I achieved this if anyone comes across a similar issue:

 

DecoratorBonusScene.prototype.tweenScore = function(obj, startValue, endValue, time) {        var scoreValue = {};        scoreValue.score = startValue;        var scoreTween = this.game.add.tween(scoreValue).to({score: endValue}, time);                scoreTween.onUpdateCallback(function() {          obj.text = "Score: "+scoreValue.score;        });                scoreTween.start();        }
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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