What's the best way to listen to the actual "ended" phase of a SpriteObject?

Hi!

As you might know, the “ended” phase of a “sprite” event is fired the moment that the last frame is shown.

Most likely this is intended to be, but in my usecase it’s pretty annoying.

For example when I’m spawning an explosion somewhere, I would like to listen to the “ended” phase to detect when I should remove it from the screen, using the “ended” phase here would cause the last frame of the explosion animation to not be shown…

Currently I can think of 3 solutions for a possible work around

  1. Writing a wrapper around display.newSprite that handles the “frames” or “start&count” params to add an extra frame (eg. frames = {1,2,3,4} will become {1,2,3,4,4}
  2. Adding a timer.performWithDelay with the time of 1 frame before I handle the “ended” phase
  3. Supplying the extra frame myself (see example solution 1), but this won’t let me do it with start&count params

How would you guys solve this problem?

I do something like:

local function spriteListener( event ) if event.phase == "ended" then timer.performWithDelay(10, function() event.target:removeSelf(); event.target = nil; end, 1) end end

and make sure I have a fully transparent last frame. 

Rob

I do something like:

local function spriteListener( event ) if event.phase == "ended" then timer.performWithDelay(10, function() event.target:removeSelf(); event.target = nil; end, 1) end end

and make sure I have a fully transparent last frame. 

Rob