best way to repeat a short animation?

What is the best way to repeat a short animation in LUA?

here’s what I have:

local halomove = display.newImage( “haloLg.png” )
transition.to( halomove, { time=1100, alpha=0} )
transition.to( halomove, { time=1100, delay=2200, alpha=1.0 } )
transition.to( halomove, { time=1100, delay=4400,alpha=0} )

I want to repeat the above sequence - I basically want an image to fade in & out repeatedly - is there a better way to do this than the direction I’m taking?
Thanks in advance for any advice,
Will [import]uid: 2862 topic_id: 462 reply_id: 300462[/import]

You could put the annimation sequence into a function, then use timer.performWithDelay, and give it a number of repetitions:

timer.performWithDelay( 1000, animationFunction, 25 )

Alternatively, make the last number zero, and it’ll repeat forever (until you cancel the timer). See page 39 of the API reference for more… [import]uid: 3007 topic_id: 462 reply_id: 895[/import]

How about the following? The timer.performWithDelay() could also work, but in this case you don’t incur the polling overhead of timer.performWithDelay() since the transition class allows you to register onComplete listeners that you can use to queue up another fade in/out:

local function fadeInOut( target )
transition.to( target, { time=1100, alpha=0} )
transition.to( target, { time=1100, delay=2200, alpha=1.0, onComplete=fadeInOut } )
end

local halo = display.newImage( “haloLg.png” )
fadeInOut( halo ) [import]uid: 26 topic_id: 462 reply_id: 915[/import]

Thanks walter - that worked! There is some flickering, but I think I can figure that out.
evank - I’m not sure how to attach the function … [import]uid: 2862 topic_id: 462 reply_id: 946[/import]