Sign in to follow this  
BattyMilk

Tweening a numeric part of a BitmapText

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

Share this post


Link to post
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();        }

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.