diff options
author | Justin Worthe <justin.worthe@gmail.com> | 2014-07-19 11:58:25 +0200 |
---|---|---|
committer | Justin Worthe <justin.worthe@gmail.com> | 2014-07-19 11:58:25 +0200 |
commit | 10d101e5fee782f6370c93ac2e39ebc96054ea4b (patch) | |
tree | 4904a8da7aded89b3d588ac43c0d64d13dbd3f5b /game/prefabs/player.js | |
parent | 76c53168629511ec46124ed221044d210e4f87c6 (diff) |
Fixed animation issue on players
Diffstat (limited to 'game/prefabs/player.js')
-rw-r--r-- | game/prefabs/player.js | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/game/prefabs/player.js b/game/prefabs/player.js index 98179d9..95ea761 100644 --- a/game/prefabs/player.js +++ b/game/prefabs/player.js @@ -2,6 +2,9 @@ var Player = function(game, x, y, key, frame) { Phaser.Sprite.call(this, game, x, y, key, frame); + this.animations.add('active', [0]); + this.animations.add('waiting', [1]); + this.baseKey = key; this.moving = false; this.scale = {x: 0.01, y: 0.01}; @@ -11,16 +14,16 @@ var Player = function(game, x, y, key, frame) { this.score = 0; this.isMyTurn = false; + this.animIsMyTurn = true; }; Player.prototype = Object.create(Phaser.Sprite.prototype); Player.prototype.constructor = Player; Player.prototype.update = function() { - var newKey = this.baseKey + (this.isMyTurn ? '' : '-dim'); - if (this.key !== newKey) { - console.log('Setting sprite to ' + newKey); - this.loadTexture(newKey); + if (this.isMyTurn !== this.animIsMyTurn) { + this.animIsMyTurn = this.isMyTurn; + this.play(this.animIsMyTurn ? 'active' : 'waiting'); } }; |