Jump to content

Animation does not work


Recommended Posts

Hi guys,

I have a little problem with my character animations. My player can go into different directions. The movement is based on a body.velocity change. I want to play a different animation based on the direction my player is heading. I use a simple switch statement in which I call 

    playee.animations.add(texture, null, 30, true);

While the texture changes and loads the first frame of my spritesheet, the animation does not play until the velocity is at 0 again. So while the player is moving nothing plays.

Any one any ideas what is going on?

Link to comment
Share on other sites

You might need to show a bit more, but I have one wild guess:

If you are constantly checking for the direction/velocity of the character that switch will constantly be triggered as well. As long as the character is moving in one direction this will keep loading and starting the animation. Because this is repeated nonstop it can only show the first sprite of the animation before the next animation is started over and over. If this is the case you can simply build in a check that it can only activate the animation once for each time you switch direction.

Link to comment
Share on other sites

Yes, it looks like you want something more like:

// Create:
playee.animations.add('left',  null, 30, true);
playee.animations.add('right', null, 30, true);

// Update:
switch (true) {
    case (velocity.x > 0) : animations.play('right'); break;
    case (velocity.x < 0) : animations.play('left') ; break;
    default               : animations.play('idle') ;

See http://phaser.io/examples/v2/arcade-physics/platformer-basics . It will be simpler if you can combine all your animations into a single texture (spritesheet).

Link to comment
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.

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.


  • Recently Browsing   0 members

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