Skip to content

Instantly share code, notes, and snippets.

@netgfx
Created April 29, 2015 08:51
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save netgfx/17c0ba8cb556f667f132 to your computer and use it in GitHub Desktop.
Save netgfx/17c0ba8cb556f667f132 to your computer and use it in GitHub Desktop.
Phaser.io animate number
GameState.prototype.animateNumber = function(num, fn, step, speed, endFn) {
var _step = step || 10;
var _speed = speed || 10; // in seconds because this is total
var repeats = Math.ceil(num / _step);
var animSpeed = (_speed / repeats) * 1000; // in ms
var _endFn = endFn || function() {
game.time.events.remove(this);
};
var _timer = game.time.create(true);
_timer.start();
_timer.onComplete.add(_endFn);
_timer.repeat(animSpeed, repeats, fn, this, [_step]);
};
GameState.prototype.updateScore = function(amount) {
this.score.text = Number(this.score.text) + Number(amount);
this.score.update();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment