Skip to content

Instantly share code, notes, and snippets.

Created May 12, 2014
What would you like to do?
ExplosionGroup subclass of Phaser.Group for #LOWREZJAM
function ExplosionGroup(game) {
// Call the Phaser.Group constructor, game);
// Have the game add this group;
ExplosionGroup.prototype = Object.create(Phaser.Group.prototype);
ExplosionGroup.prototype.constructor = ExplosionGroup;
ExplosionGroup.prototype.explode = function(x, y) {
// Get the first 'dead' member of the group
var explosion = this.getFirstDead();
// If 'explosion' is null, there weren't any 'dead' memebers
if (explosion === null) {
// Create a sprite using the 'explosion' cache key
explosion =, 0, 'explosion');
// Center its anchor
explosion.anchor.setTo(0.5, 0.5);
// Create an animation based on the 'explosion' cache key
// and label it 'boom' for later playing.
// (We also need to save a reference to the create animation.)
var animation = explosion.animations.add('boom', [0, 1, 2, 3], 50, false);
// Tell the animation to kill() itself when done
animation.killOnComplete = true;
// All the sprite + animation to the group
// If there was a 'dead' member in the group, revive it.
// Otherwise, 'revive' the new member.
// Reset its position to those passed into this function
explosion.reset(x, y);
// Pick a random angle for the sprite (and thus animation)
explosion.angle =, 360);
// Play the 'boom' animation.
// (When it is done, it will kill the animation.)'boom');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment