prateek.pradeep Posted April 8, 2014 Share Posted April 8, 2014 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 formatCollisionBetweenBirdAndWall(){ 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 More sharing options...
mariogarranz Posted April 8, 2014 Share Posted April 8, 2014 Where did you define animation frames? Link to comment Share on other sites More sharing options...
prateek.pradeep Posted April 11, 2014 Author Share Posted April 11, 2014 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 More sharing options...
Recommended Posts