Call a function when a sprite is on a specific frame

similar to: 

 if ( event.phase == “ended” ) then

dofunction()

end

however I would like to call this function during a specific frame of a sprites animation (eg. frame 16).  I think I found what I need to do at:

https://docs.coronalabs.com/api/type/SpriteObject/frame.html 

but im just not sure how to type it out.  Any type of example of this would be wonderful -thanks.

Inside your event listener, do this:

if event.target.frame == 16 then foo() end

Although I’m just guessing that will work – I’ve never done it. :slight_smile:

 Jay

Hi @k.murray,

To expand on this, you can sense the “next” event.phase and then check the frame number during that event. It’s outlined in the last section of this tutorial:

http://coronalabs.com/blog/2012/10/02/animated-sprites-and-methods/

Best regards,

Brent

Thanks for the replies, got it working :slight_smile:

Inside your event listener, do this:

if event.target.frame == 16 then foo() end

Although I’m just guessing that will work – I’ve never done it. :slight_smile:

 Jay

Hi @k.murray,

To expand on this, you can sense the “next” event.phase and then check the frame number during that event. It’s outlined in the last section of this tutorial:

http://coronalabs.com/blog/2012/10/02/animated-sprites-and-methods/

Best regards,

Brent

Thanks for the replies, got it working :slight_smile: