Jump to content

Only First Frame of Animation Plays


Barrerayy
 Share

Recommended Posts

Trying to add an explode animation to the game I'm making. I'm trying to add an explosion animation which plays when the player collides with an asteroid. I've looked at the examples and the Invader game on the phaser website but still can only get the 1st frame to play only instead of all of them. The 1st frame plays then stays on screen. I'm using the same explosion spritesheet from this example: http://phaser.io/examples/v2/games/invaders . There are no errors on the console

function asteroidCollisionHandler(player, asteroid)
{
    live = lives.getFirstAlive();

    if (live)
    {
        live.kill();
    }

    explosion = explosions.getFirstExists(false);
    explosion.reset(player.body.x, player.body.y);

    explosion.play('explosion', 30, false, true);

    if (lives.countLiving() < 1)
    {
        player.kill();
    }
}

This is called from the update  function as such

game.physics.arcade.collide(asteroids, player, asteroidCollisionHandler, null, this);

I'm initializing the explosion group in my create function as such

explosions = game.add.group();
explosions.createMultiple(30, 'explosion');

Sprite sheet loaded in the preloader

this.load.spritesheet('explosion', 'images/explode.png', 128, 128);

 

Link to comment
Share on other sites

I would suggest explicitly including the indexes when the animation is added to the sprite. Try something like this and see if it works:

game.load.spritesheet("explosion", x, y, how_many);

sprite.animations.add("explosion_animation", "explosion", [0, 1, 2, 3, ...]);

 

Essentially what you do is include the explicit array argument so Phaser knows where to parse the spritesheet.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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