Jump to content

Playing new animation on sprite not updating


Recommended Posts

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;

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() {
    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 "[email protected]". I need some help. Thank you a bunch.

Link to comment
Share on other sites

Thank you. This helps a bunch. I should have specified that the animations are separate. As in, I have separate sprite sheets for move left, right, etc. Would this be the root of the problem? If so, do you think this should be an enhancement in 3.0?

Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...