How do I animate a sprite that's already been added to a group?
Here's my spritesheet:
game.load.spritesheet('enemyBullet', 'assets/games/invaders/enemy-bullet.png', 11, 19);
Here's the group:
// The enemy's 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's 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?
I figured out my answer:
enemyBullets.callAll('animations.add', 'animations', 'fly3', [0,1,2,3], 16, true);
enemyBullets.callAll('play', null, 'fly3');
Tested and it works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With