Hi all,
I want to move a series of objects (simple rectangles) that are stored in a table. I am using a for loop to do this, but I want to make it so that they move with a slight delay between each.
Whatever I try, it seems to move all the objects at the same time. Here’s some sample code:
[lua] local _W = display.contentWidth
local _H = display.contentHeight
– BACKGROUND
local bg = display.newRect ( 0, 0, _W, _H )
bg.x = _W * 0.5
bg.y = _H * 0.5
– CREATE BOX TABLE & BOXES
local boxTable = {}
for i = 1, 5 do
boxTable[i] = display.newRect( 0, 0, 40, 40 )
boxTable[i].x = (i * 80)
boxTable[i].y = (_W * 0.5)
boxTable[i]:setFillColor(math.random(1, 255), math.random(1, 255), math.random(1, 255))
end
– MOVE BOXES FUNCTION
local function moveBox()
for i = 1, #boxTable do
transition.to( boxTable[i], { y = _H * 0.8, time=300} )
end
end
bg:addEventListener(“tap”, moveBox)
[/lua]
If you run that, you’ll see that the objects move at the same time. I want each to start to move with a delay (500ms or so) after the previous one has started to move.
How is this done? Thanks in advance. [import]uid: 74503 topic_id: 26193 reply_id: 326193[/import]