Method #1 - Co-routines
One way to achieve a delay is via a co-routine. SSK2 comes with StarCrunch’s wait utilities :
-- Method 1 (Co-routines) local foos = {} local waitTime = 500 local function newFoo( x, y ) local foo = display.newCircle( x, y, 30 ) foos[#foos+1] = foo print( "Foo# " .. #foos .. " created at \<" .. foo.x .. " ," .. foo.y .. "\> @ time: " .. system.getTimer() ) end local function waitLoop() local sy = 50 local sx = 112 for r = 1, 10 do sx = 112 for c = 1, 14 do newFoo( sx, sy, foo ) sx = sx + 40 ssk.wait.ms( 500 ) end sy = sy + 40 end end ssk.wait.run( waitLoop )
Method #2 - performWithDelay
-- Method 2 Timers local foos = {} local delayTime = 500 local function createLoop() local count = 0 local sy = 50 local sx = 112 for r = 1, 10 do sx = 112 for c = 1, 14 do local x,y = sx,sy -- Important, or all objects will be created at last sx,sy timer.performWithDelay( count \* delayTime, function() local foo = display.newCircle( x, y, 30 ) foos[#foos+1] = foo print( "Foo# " .. #foos .. " created at \<" .. foo.x .. " ," .. foo.y .. "\> @ time: " .. system.getTimer() ) end ) count = count + 1 sx = sx + 40 end sy = sy + 40 end end nextFrame( createLoop )