Jump to content

Sprite's new animation does not play !


prateek.pradeep
 Share

Recommended Posts

Hi i have a body which on  collision with wall blasts.
Actual: But as soon as it collides with only the first frame of the animation is seen. And when I move the body (by clilcking anywhere) the rest of the animation loads and body dies.
 
Expected: As soon as the body touches the wall it should play the blast animation and die.
 
Code is below.
preload()
{
this.load.spritesheet('bird-dead','assets/bird-sprite1-dead.png', 50, 50, 3);
}

 Image1:Image2:Image3  //sprite in following format

CollisionBetweenBirdAndWall()
{
        this.bird.body.velocity.setTo(0,0);                           //stop the bird movement
        this.bird.animations.stop();   //stop current animation of bird
        this.bird.loadTexture('bird-dead',2);   // load the dead animation
        this.bird.animations.add('bird-dead-kill');         //add the animation name
        this.bird.animations.play('bird-dead-kill',60,false,true);       //play the bird animation
 
}

Link to comment
Share on other sites

I got it. When the bird collided with the wall, the collision funciton was being called continuosly and therefore the animation stoped because the second line in CollisionBetweenBirdAndWall() stops the bird dying animaiton.

I added a new porperty of the bird and the collision funciton is not called the second time.

 

Here is the code now.

 

preload()
{
this.load.spritesheet('bird-dead','assets/bird-sprite1-dead.png', 50, 50, 3);
}

 Image1:Image2:Image3  //sprite in following format

 

Create()

{

       this.bird.dying = false;

}

CollisionBetweenBirdAndWall()
{

     if( !this.bird.dying )

{
        this.bird.body.velocity.setTo(0,0);                           //stop the bird movement
        this.bird.animations.stop();   //stop current animation of bird
        this.bird.loadTexture('bird-dead',2);   // load the dead animation
        this.bird.animations.add('bird-dead-kill');         //add the animation name
        this.bird.animations.play('bird-dead-kill',60,false,true);       //play the bird animation

       this.bird.dying=true;
}

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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