Barrerayy Posted April 8, 2016 Share Posted April 8, 2016 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 More sharing options...
johncintron Posted April 9, 2016 Share Posted April 9, 2016 There might be a problem in the last line of your code. You should add a fifth argument that specifies how many sprites are in the spritesheet. I'd assume in your case this is the x*y of the spritesheet divided by 128*128. Link to comment Share on other sites More sharing options...
Barrerayy Posted April 9, 2016 Author Share Posted April 9, 2016 I've already tried it like that, didn't make any difference Link to comment Share on other sites More sharing options...
johncintron Posted April 9, 2016 Share Posted April 9, 2016 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. drhayes 1 Link to comment Share on other sites More sharing options...
Recommended Posts