Unwanted delay between functions

Hello,

I want to create a loop animation of two objects with the small delay between them. This is the code I wrote:

local function heartbeat() local heart1beat1, heart1beat2 heart1beat1 = function() transition.to(Heart1, {time=130, xScale=1, yScale=1, onComplete=heart1beat2 }) local heartbeat = audio.play( heartBSound ) end heart1beat2 = function() transition.to(Heart1, {delay = 750, time=100, xScale=1.15, yScale=1.15, onComplete=heart1beat1 }) end local heart2beat1, heart2beat2 heart2beat1 = function() transition.to(Heart2, {time=130, xScale=1, yScale=1, onComplete=heart2beat2 }) end heart2beat2 = function() transition.to(Heart2, {delay = 750, time=100, xScale=1.1, yScale=1.1, onComplete=heart2beat1 }) end heart1beat1() timer.performWithDelay( 300, heart2beat1) end heartbeat()

It works but after some time the delay doesn’t stay the same and the timing gets messed up. I want the loop to stay the same all the time. I guess when I put these two functions one after another it creates a small gap. I am new to Lua, please tell me how can I close the gap?

You might want to look into the animation plugin (http://docs.coronalabs.com/plugin/animation/index.html). It’s the transition.*'s newer more modern replacement. It has timeline support and other looping functions and it can be better for chaining animations together.

Rob

Thank you Rob! This is excellent, very useful for my project. Here is the code:

local function timelineListener( obj ) obj:setPosition("marker\_start") end local timelineParams = { tweens = { { startTime=0, tween={ Heart1, { xScale=1.15, yScale=1.15 }, { delay=500, time=115, iterations=2, reflect=true} } }, { startTime=270, tween={ Heart2, { xScale=1.1, yScale=1.1 }, { delay=500, time=115, iterations=2, reflect=true} } } }, markers = { { name="marker\_start", time=0 }, }, onComplete = timelineListener } local newTimeline = animation.newTimeline( timelineParams ) newTimeline:resume()

You might want to look into the animation plugin (http://docs.coronalabs.com/plugin/animation/index.html). It’s the transition.*'s newer more modern replacement. It has timeline support and other looping functions and it can be better for chaining animations together.

Rob

Thank you Rob! This is excellent, very useful for my project. Here is the code:

local function timelineListener( obj ) obj:setPosition("marker\_start") end local timelineParams = { tweens = { { startTime=0, tween={ Heart1, { xScale=1.15, yScale=1.15 }, { delay=500, time=115, iterations=2, reflect=true} } }, { startTime=270, tween={ Heart2, { xScale=1.1, yScale=1.1 }, { delay=500, time=115, iterations=2, reflect=true} } } }, markers = { { name="marker\_start", time=0 }, }, onComplete = timelineListener } local newTimeline = animation.newTimeline( timelineParams ) newTimeline:resume()