Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

How to set killOnComplete for a group animation


Gorpomon
 Share

Recommended Posts

Hello all, I'm trying to re-use sprites like so:

squareTargets = game.add.group();
    squareTargets.enableBody = true;
    squareTargets.physicsBodyType = Phaser.Physics.ARCADE;
    squareTargets.createMultiple(maxSquareTargets, 'square target sheet');
    squareTargets.setAll('checkWorldBounds', true);
    squareTargets.setAll('outOfBoundsKill', true);
    squareTargets.setAll('hasOverlapped', false);  //my own property I use in my logic
    squareTargets.setAll('frame', 1);  // so it displays on the 1 index of my sprite sheet
    squareTargets.callAll('animations.add', 'animations', 'explode', [1, 2, 3, 0], 5, false);

 

I also want the individual sprite to kill() when the explode animation is run, how do I set this at the group level?

I see that I can individually set animations on a sprite and do this:

var explode = singleTarget.animations.add('explode', [1, 2, 3, 0], 5,);
explode.killOnComplete = true;

But I'd rather find a way set the animation on the group and killOnComplete for the animation in one go, rather than loop through the group and define the animation and property (which I suspect is wasteful from a memory point of view).

Link to comment
Share on other sites

I think I see what was wrong, I wasn't passing in the killOnComplete boolean to my .callAll call, like so:

 squareTargets.callAll('animations.add', 'animations', 'explode', [1, 2, 3, 0], 5, false, true);

but I would still appreciate any elaboration on what you can use .callAll to do!

Link to comment
Share on other sites

You use callAll to call a function on every member of a Group, that's it really. setAll sets a property, callAll invokes a function.

Groups are just containers, they can't have animations themselves, as they don't have any visual properties (they don't actually render themselves). Only Sprites can. Which is why only Sprites have animation signals (like killOnComplete)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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