Stop sprite listener from picking up after pause?

I have a sprite animation that launches another image when it completes it’s animation sequence. It does this with a sprite listener.

I have a button that “turns off” the game. Included in this process is stopping the sprite animation from above (actually, it pauses since there is no stop) as follows:

animation:pause() animation:setFrame(1)

The problem is, when I turn the game back “on”, the sprite animation seems to have ended and still launches the other image instead of starting from the beginning and bypassing the steps in the sprite listener.

I have a setFrame(1) in the code above, but it still seems as if the sprite animation wants to finish where it left off.

Should I just let it finish the animation sequences with the elements hidden?

Or, is there a way to totally reset the sprite animation to the beginning?

So your saying that after pausing the animation it continues to play the animation regardless until the end of the animation sequence?

Hi @fly4,

You may try removing the sprite listener(s) when the game “stops”, although I realize this may not be practical if you have dozens of sprites to loop through for this. Another possible option is to set a flag variable on the sprite, i.e. when you stop the game, set .reset = true on the sprite(s). Then, when the game resumes, if .reset is true, you just return (false) from the function that is triggered by the sprite completion listener, thus skipping that process.

Brent

Wait, I think I got it.

I needed to initialize the frame when I call the animation the first time. Otherwise, if I interrupt it, it just picks up where it left off even though I set the frame to 1 when I stop it.

I just added the animation.setFrame(1) every time I call the routine to start the animation and it seems to work fine now.

Thanks everyone!

So your saying that after pausing the animation it continues to play the animation regardless until the end of the animation sequence?

Hi @fly4,

You may try removing the sprite listener(s) when the game “stops”, although I realize this may not be practical if you have dozens of sprites to loop through for this. Another possible option is to set a flag variable on the sprite, i.e. when you stop the game, set .reset = true on the sprite(s). Then, when the game resumes, if .reset is true, you just return (false) from the function that is triggered by the sprite completion listener, thus skipping that process.

Brent

Wait, I think I got it.

I needed to initialize the frame when I call the animation the first time. Otherwise, if I interrupt it, it just picks up where it left off even though I set the frame to 1 when I stop it.

I just added the animation.setFrame(1) every time I call the routine to start the animation and it seems to work fine now.

Thanks everyone!