infinite loop
hello there
i want to move an object for infinite loop .. just like a sky to go from point to another point
is that right ?
"
while true do
transition.to( sky, { time=3000, x=80, y=55 } )
local function listener( event )
transition.to( sky, { time=3000, x=385, y=55 } )
end
timer.performWithDelay(3000, listener )
end
"
Replies
i dont know to use the repeatLoop ..
so can u guide me how to use it to as example move a object from x= 250 to x=50 then get back to the initial point
Something like this would do what you are describing.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | -- load sky graphic local sky = display.newImage("sky.png", true) sky.x = 250 -- function to reset and move sky object local function moveSky() -- reset to starting location sky.x = 250 -- transition sky, when finished start over again transition.to(sky,{time=5000, x=50, onComplete=moveSky}) end moveSky() -- start moving sky |
In my code 'repeatLoop' is not anything special - its just the name I chose for the function.
What's happening in my code (and in the next sample posted) is a regular transition (Corona library function) is being used to move the sky image by gradually altering the .x value. Then, when the transition finishes, it will automatically call the function named in the 'onComplete' parameter. Because the transition is started in that same function, it starts again, like an infinite loop.
The short of it is: When the animation (transition) finishes, it calls itself to start again. The magic bit is the 'onComplete' parameter.
ya thats right >>> but i want
sky.x = 250.. to be transition way to get back to x =250
how can i do this ?
Hello @oamer_11,
Note that you can "stack" transitions as well, putting a delay on the next in the stack so it executes after the first one is done.
1 2 3 | sky.x = 250 transition.to(sky,{time=5000, x=50 }) transition.to(sky,{time=5000, x=250, delay=5000}) --delay of 5000 to equal time of 1st transition |
The caveat is that this approach can get messy if you have dozens of transitions going on, and/or if you need to pause them or cancel them before they complete. If that is your intention, then you are better off making a more robust solution using the "onComplete" methods and a tracking variable to determine which transition is next in the queue.
Brent



Actually, you're better off using the onComplete parameter of the transition.to function: