Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Unwanted delay between functions
Started by cognibird Jan 17 2019 04:28 PM

2 replies to this topic

Best Answer Rob Miracle , 17 January 2019 - 04:45 PM

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

[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

cognibird

[GLOBAL: userInfoPane.html]
cognibird
  • Observer

  • 17 posts
  • Corona SDK

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?



[TOPIC: post.html]
#2

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,461 posts
  • Enterprise

  Best Answer

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



[TOPIC: post.html]
#3

cognibird

[GLOBAL: userInfoPane.html]
cognibird
  • Observer

  • 17 posts
  • Corona SDK

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()



[topic_controls]
[/topic_controls]