So I'm running into this problem where I initialize a sprite with multiple animations, but only the animation specified in the creation of the sprite is ever played. When I attempt to update the sprite with a new animation, it simply changes the framerate. I have debugged the game to see if it is actually updating the currentAnim, and it is. Also, I have tested the other animations too see if they loaded correctly by inputting them into the initializing sprite animation. Now, code:
player = this.game.add.sprite(400, 400, 'player_idle');
this.game.physics.p2.enable(player, false);
player.body.fixedRotation = true;
player.animations.add('player_idle');
player.animations.add('player_left');
player.animations.add('player_right');
controls.left.onDown.add(() => {
console.log("Begin left: " + player.animations.currentAnim.name);
player.animations.play('player_left', 14, true);
console.log("End left: " + player.animations.currentAnim.name);
}, this);
controls.right.onDown.add(() => {
console.log("Begin right: " + player.animations.currentAnim.name);
player.animations.play('player_right', 14, true);
console.log("End right: " + player.animations.currentAnim.name);
}, this);
update() {
player.body.setZeroVelocity();
controls.up.isDown ? player.body.moveUp(200) : null
controls.down.isDown ? player.body.moveDown(200) : null
controls.left.isDown ? player.body.moveLeft(200) : null
controls.right.isDown ? player.body.moveRight(200) : null
if(!controls.left.isDown && !controls.right.isDown && !controls.up.isDown && !controls.down.isDown) {
player.animations.play('player_idle', 3, true);
}
}
I am using "phaser-ce@2.8.3". I need some help. Thank you a bunch.