How to add animation to a group sprite in phaser.js?

How can I create a sprite that has already been added to the group?

Here is my sprite:

game.load.spritesheet('enemyBullet', 'assets/games/invaders/enemy-bullet.png', 11, 19);

      

Here's the group:

// The enemy bullets
enemyBullets = game.add.group();
enemyBullets.enableBody = true;
enemyBullets.physicsBodyType = Phaser.Physics.ARCADE;
enemyBullets.createMultiple(30, 'enemyBullet');
enemyBullets.setAll('anchor.x', 0.5);
enemyBullets.setAll('anchor.y', 1);
enemyBullets.setAll('outOfBoundsKill', true);
enemyBullets.setAll('checkWorldBounds', true);

      

Here is the code I think I should add.

enemyBullets.animations.add('fly3', [ 0, 1, 2, 3], 20, true);
enemyBullets.play('fly3');

      

However, if I add that anywhere in the above group code block, I get the error "enemyBullets.animations". undefined.

Any ideas?

+3


source to share


1 answer


I figured out my answer:

enemyBullets.callAll('animations.add', 'animations', 'fly3', [0,1,2,3], 16, true);
enemyBullets.callAll('play', null, 'fly3');

      



Tested and working.

+8


source







All Articles