Vocojax

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;
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.

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

Yes, I think you'll be much better off using one spritesheet. That's what Phaser anticipates and it's more efficient. I don't know what's planned for Phaser 3, but only one texture per animation is still a good rule.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.