How to slow down a while true do loop?

I have some basic code which would run instantly but I would need it to yield before restarting the loop.

MapGroup = display.newGroup() frameN = 0 &nbsp; function DrawPath() somerandomoffset = math.random(5,10) display.newRect(MapGroup,frameN\*20,25,20,50+somerandomoffset) display.newRect(MapGroup,frameN\*20,display.actualContentHeight-25,20,50+somerandomoffset) frameN = frameN + 1 end &nbsp; for i = 1,30 do -- draws the start DrawPath() end &nbsp; while frameN \< 500 do -- just to prevent a crash but it would normally be while true do for i = 1, 5 do -- moves the map 20 pixels and draws a new column MapGroup.x = MapGroup.x - 4 -- this should work I believe to scroll the map --Needs a way to yield right here for x miliseconds end DrawPath() print(frameN) end &nbsp; &nbsp;

I’ve looked up and could not find any sleep function other than a function which creates a seperate thread to run a function x miliseconds later

the goal was to create a scrolling display.

Corona SDK is event driven. There is no sleep function. You don’t maintain things in loops like this. If you want to move an object over time you use the transition.to API Call (or other appropriate transition.* function).

Corona also is frame based. That is we try to update the screen either 30 times per second or 60 times per second. We have an event listener called “enterFrame” where you can write a function that gets called every screen update and you can move things in that function by hand.

Finally we have timer.performWithDelay() where you can have events fire at specific time intervals. So if you want something to happen every 50 ms, you could do:

timer.performWithDelay( 50, function() do stuff every update; end, 0 ) – loop for ever.

Rob

Thanks!

Corona SDK is event driven. There is no sleep function. You don’t maintain things in loops like this. If you want to move an object over time you use the transition.to API Call (or other appropriate transition.* function).

Corona also is frame based. That is we try to update the screen either 30 times per second or 60 times per second. We have an event listener called “enterFrame” where you can write a function that gets called every screen update and you can move things in that function by hand.

Finally we have timer.performWithDelay() where you can have events fire at specific time intervals. So if you want something to happen every 50 ms, you could do:

timer.performWithDelay( 50, function() do stuff every update; end, 0 ) – loop for ever.

Rob

Thanks!