Jump to content

Stop all animations in a sprite group


CyborgNachte
 Share

Recommended Posts

Hey there! 

I was wondering how you stop all animations in a sprite group when clicking one of them. I can't seem to get it to work.

Heres my code that deals with it: 

function create(){
cardPack = game.add.group();
	
	cardPack.create(game.world.centerX - 250, game.world.centerY, 'card');
	cardPack.create(game.world.centerX - 75, game.world.centerY, 'card');
	cardPack.create(game.world.centerX + 100, game.world.centerY, 'card');
	cardPack.callAll('animations.add', 'animations', 'flip', [0,1,2,3], 12, true);
	cardPack.callAll('play', null, 'flip');
	cardPack.setAll('inputEnabled', true);
	cardPack.setAll('input.useHandCursor', true);
	cardPack.setAll('events.onInputDown.addOnce', stopAnimation, this); 
	cardPack.setAll('input.priorityID', 1);
}


function stopAnimation(){
	
	cardPack.callAll('animations.stop', 'animations', null,  true);
	
	
	
}

Is the error in the callAll for the animation stop or in the setAlll for event onInputDown? I've tried manipulating both and looking for examples for this but I'm coming up empty handed or just not searching correctly.

 

Link to comment
Share on other sites

Ah, I solved it myself, thanks to catching the difference in this example: https://phaser.io/examples/v2/groups/call-all-input

this line :

  • cardPack.setAll('events.onInputDown.addOnce', stopAnimation, this);

Should read:

  • cardPack.callAll('events.onInputDown.addOnce', 'events.onInputDown',  stopAnimation); 

In case anybody else ends up with this confusion.

 

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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