Type String Event sprite Revision Release 2024.3703 Keywords sprite, phase
A string indicating the phase which the SpriteObject animation is currently in.
"began"
— The animation began playing."ended"
— The animation showed its final frame."bounce"
— The animation bounced from forward to backward while playing."loop"
— The animation looped from the beginning of the sequence."next"
— The animation played a subsequent frame that’s not one of the above phases.In a theoretical example of a sprite animation of 4 frames, here are the possible
-- Loop twice "began" 1 "next" 2 "next" 3 "next" 4 "loop" 1 "next" 2 "next" 3 "ended" 4 -- Loop indefinitely, no bounce (like above but no "ended" phase occurs) "began" 1 "next" 2 "next" 3 "next" 4 "loop" 1 "next" 2 "next" 3 "next" 4 --etc. -- Loop indefinitely, with bounce "began" 1 "next" 2 "next" 3 "bounce" 4 "next" 3 "next" 2 "loop" 1 "next" 2 "next" 3 --etc. -- Loop twice, with bounce "began" 1 "next" 2 "next" 3 "bounce" 4 "next" 3 "next" 2 "loop" 1 "next" 2 "next" 3 "bounce" 4 "next" 3 "next" 2 "ended" 1
-- Assumes "imageSheet" is already created via "graphics.newImageSheet()" local sequenceData = { name = "walking", start =3, count = 6, time = 100, loopCount = 0, -- Optional; default is 0 (loop indefinitely) loopDirection = "bounce" -- Optional; values include "forward" or "bounce" } local character = display.newSprite( imageSheet, sequenceData ) local function spriteListener( event ) print( event.name, event.target, event.phase, event.target.sequence ) end -- Add sprite listener character:addEventListener( "sprite", spriteListener )