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
"
[import]uid: 96162 topic_id: 35032 reply_id: 335032[/import]

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

[lua]local function repeatLoop()
transition.to( obj, { time=5000, onComplete=repeatLoop } )
end
repeatLoop()[/lua] [import]uid: 8271 topic_id: 35032 reply_id: 139313[/import]

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 [import]uid: 96162 topic_id: 35032 reply_id: 139365[/import]

Something like this would do what you are describing.

[code]
– 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
[/code] [import]uid: 56820 topic_id: 35032 reply_id: 139380[/import]

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. [import]uid: 8271 topic_id: 35032 reply_id: 139432[/import]

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

[lua]local function repeatLoop()
transition.to( obj, { time=5000, onComplete=repeatLoop } )
end
repeatLoop()[/lua] [import]uid: 8271 topic_id: 35032 reply_id: 139313[/import]

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 [import]uid: 96162 topic_id: 35032 reply_id: 139365[/import]

Something like this would do what you are describing.

[code]
– 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
[/code] [import]uid: 56820 topic_id: 35032 reply_id: 139380[/import]

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. [import]uid: 8271 topic_id: 35032 reply_id: 139432[/import]

ya thats right >>> but i want

sky.x = 250… to be transition way to get back to x =250

how can i do this ? [import]uid: 96162 topic_id: 35032 reply_id: 142322[/import]

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.

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 [import]uid: 200026 topic_id: 35032 reply_id: 142538[/import]

ya thats right >>> but i want

sky.x = 250… to be transition way to get back to x =250

how can i do this ? [import]uid: 96162 topic_id: 35032 reply_id: 142322[/import]

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.

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 [import]uid: 200026 topic_id: 35032 reply_id: 142538[/import]