infinite loop transition.to

Hello,

how do I run these in infinite loop?

local function listener1() transition.to( bballoon, { time=6000, x=(cx - 450), xScale = .8, yScale = .8, rotation = -10, onComplete=listener2 } ) end local function listener2() transition.to( bballoon, { time=6000, x=(cx - 250), xScale = .9, yScale = .9, rotation = 10, onComplete=listener1 } ) end local function listener3() transition.to( wballoon, { time=10000, x=(cx + 200), xScale = 1, yScale = 1, rotation = -10, onComplete=listener4 } ) end local function listener4() transition.to( wballoon, { time=10000, x=(cx + 500), xScale = 1.1, yScale = 1.1, rotation = 10, onComplete=listener3 } ) end local function balloonAnimation() listener2() listener4() end balloonAnimation()

the loop runs only once but I need to execute it infinitely. If I remove “local” in front of function then it works but I prefer to avoid global functions

nevermind, I figured it out :slight_smile:

local function listener1() transition.to( bballoon, { time=6000, x=(cx - 450), onComplete=function() transition.to( bballoon, { time=6000, x=(cx - 250), onComplete=listener1 } ) end } ) end

the method when listener is calling itself in an infinite loop is very slow when using transition.cancel(bballoon). The game effectively freezes for about half a second. Any idea why or any suggestions for improvement?

I think you are creating a stack of closures or transitions or something or both. It strikes me as not a good way to do something if you want it to repeatedly follow a pattern.

I turned this out for someone, it runs a sequences of transitions without using closures. It could be fairly easily amended to run transitions continually indefinitely, adding a boolean and a test where it starts a new transition.  So it is only every running one transition at once rather than piling them on top of each other with local functions.

It’s difficult to know exactly what’s going on without knowing exactly how Corona implements transactions, but the code just makes me think, “that’s asking for trouble”.

-- -- List of current transitions - each has a list (list of transitions) -- and an index (current transition) -- -- transitions can have onComplete defined, if not will go automatically -- to next. local transitionLists = {} function defineExtTransition(displayObject, transitionList) transitionLists[displayObject] = {} transitionLists[displayObject].list = transitionList transitionLists[displayObject].index = 0 end function runExtTransition(displayObject) assert(transitionLists[displayObject] ~= nil) local n = transitionLists[displayObject].index + 1 if n \<= #transitionLists[displayObject].list then transitionLists[displayObject].index = n local tdef = transitionLists[displayObject].list[n] tdef.onComplete = tdef.onComplete or runExtTransition transition.to(displayObject,tdef) else transitionLists[displayObject] = nil end end local ob1 = display.newCircle(160,240,15) ob1:setFillColor( 1,1,0 ) local ob2 = display.newCircle(10,10,15) ob2:setFillColor( 0,1,0 ) defineExtTransition(ob1, { { time = 1000, x = 0, y = 0}, { time = 500, x = 0, y = 400 }, { time = 2500, x = 320, y = 0, alpha = 0 } }) defineExtTransition(ob2, { { time = 1000, x = 310, y = 10}, { time = 1000, x = 310 , y = 470}, { time = 1000, x = 0, y = 470 }, { time = 1000, x = 10, y = 10, onComplete = function() print("Hello, world!") end } }) runExtTransition(ob1) runExtTransition(ob2)

nevermind, I figured it out :slight_smile:

local function listener1() transition.to( bballoon, { time=6000, x=(cx - 450), onComplete=function() transition.to( bballoon, { time=6000, x=(cx - 250), onComplete=listener1 } ) end } ) end

the method when listener is calling itself in an infinite loop is very slow when using transition.cancel(bballoon). The game effectively freezes for about half a second. Any idea why or any suggestions for improvement?

I think you are creating a stack of closures or transitions or something or both. It strikes me as not a good way to do something if you want it to repeatedly follow a pattern.

I turned this out for someone, it runs a sequences of transitions without using closures. It could be fairly easily amended to run transitions continually indefinitely, adding a boolean and a test where it starts a new transition.  So it is only every running one transition at once rather than piling them on top of each other with local functions.

It’s difficult to know exactly what’s going on without knowing exactly how Corona implements transactions, but the code just makes me think, “that’s asking for trouble”.

-- -- List of current transitions - each has a list (list of transitions) -- and an index (current transition) -- -- transitions can have onComplete defined, if not will go automatically -- to next. local transitionLists = {} function defineExtTransition(displayObject, transitionList) transitionLists[displayObject] = {} transitionLists[displayObject].list = transitionList transitionLists[displayObject].index = 0 end function runExtTransition(displayObject) assert(transitionLists[displayObject] ~= nil) local n = transitionLists[displayObject].index + 1 if n \<= #transitionLists[displayObject].list then transitionLists[displayObject].index = n local tdef = transitionLists[displayObject].list[n] tdef.onComplete = tdef.onComplete or runExtTransition transition.to(displayObject,tdef) else transitionLists[displayObject] = nil end end local ob1 = display.newCircle(160,240,15) ob1:setFillColor( 1,1,0 ) local ob2 = display.newCircle(10,10,15) ob2:setFillColor( 0,1,0 ) defineExtTransition(ob1, { { time = 1000, x = 0, y = 0}, { time = 500, x = 0, y = 400 }, { time = 2500, x = 320, y = 0, alpha = 0 } }) defineExtTransition(ob2, { { time = 1000, x = 310, y = 10}, { time = 1000, x = 310 , y = 470}, { time = 1000, x = 0, y = 470 }, { time = 1000, x = 10, y = 10, onComplete = function() print("Hello, world!") end } }) runExtTransition(ob1) runExtTransition(ob2)