How can i make a transition repeat once its completed?

how can i make this cloud image repeat the transition once its completed? thanks!

local cloud = display.newImage( "cloud.png" ) cloud.x = 390 cloud.y = 70 transition.to(cloud, {time=6000, x=-100, y=70}) [import]uid: 10827 topic_id: 6537 reply_id: 306537[/import]

[lua]local cloud = display.newImage(“cloud.png”)

local moveCloudComplete – forward reference

local function moveCloud()
cloud.x = 390
cloud.y = 70
transition.to(cloud, {time=6000, x=-100, y=70, onComplete=moveCloudComplete)}
end

function moveCloudComplete() – still local, due to fwd ref
moveCloud()
end[/lua]
[import]uid: 6645 topic_id: 6537 reply_id: 22669[/import]

Basically what he’s saying is use the onComplete parameter to call a function and set the same transition in that function. [import]uid: 12108 topic_id: 6537 reply_id: 22688[/import]

thanks a lot but for some reason the cloud doesn’t even move now, it just stays on one spot… any help? [import]uid: 10827 topic_id: 6537 reply_id: 22753[/import]

post your code

Off the top of my head, I’m guessing you typed onComplete=moveCloudComplete() instead of onComplete=moveCloudComplete

Putting in the parentheses causes the function to run immediately instead of waiting for the transition to finish. [import]uid: 12108 topic_id: 6537 reply_id: 22758[/import]

its the same code that the other guy posted… doesnt work for me though :frowning:

[code]
local cloud = display.newImage(“cloud.png”)

local moveCloudComplete

local function moveCloud()
cloud.x = 390
cloud.y = 70
transition.to(cloud, {time=6000, x=-100, y=70, onComplete=moveCloudComplete})
end

function moveCloudComplete()
moveCloud()
end
[/code] [import]uid: 10827 topic_id: 6537 reply_id: 22789[/import]

I don’t think it’s necessary to do it as two functions that call each other. Try:

local cloud = display.newImage("cloud.png")  
  
local function moveCloud()  
 cloud.x = 390  
 cloud.y = 70  
 transition.to(cloud, {time=6000, x=-100, y=70, onComplete=moveCloud})  
end  

ADDITION: oh wait duh you need to actually call the function. Code in a function doesn’t run automatically, it waits until you tell it to. So at the bottom of the code write:

moveCloud() [import]uid: 12108 topic_id: 6537 reply_id: 22791[/import]

i seee, thanks! works perfectly, thanks again! [import]uid: 10827 topic_id: 6537 reply_id: 22877[/import]