Created
April 29, 2015 08:51
-
-
Save netgfx/17c0ba8cb556f667f132 to your computer and use it in GitHub Desktop.
Phaser.io animate number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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