oh ok that makes life a little more difficult, i assumed you were making a background, in that case i would create a finite no. of boxes and then you can individually manipulate them.
----------------------------------------------------------------------------------------- -- Localize to improve performance ----------------------------------------------------------------------------------------- local W = display.contentWidth local H = display.contentHeight local XCentre = display.contentCenterX local YCentre = display.contentCenterY local screenLeft = display.screenOriginX local screenRight = display.viewableContentWidth + display.screenOriginX local screenTop = display.screenOriginY local screenBottom = display.viewableContentHeight + display.screenOriginY local random = math.random ---------------------------------------------------------------------------------------- -- This is a forward reference to a funciton i call later on ---------------------------------------------------------------------------------------- local Fall ---------------------------------------------------------------------------------------- -- Resets the postion of the boxes ---------------------------------------------------------------------------------------- local function Restart\_Box (obj) print("obj restarted") obj.x = random(screenLeft,screenRight) obj.y = -20 local FallerCaller = Fall (obj) end ---------------------------------------------------------------------------------------- -- Makes the boxes fall ---------------------------------------------------------------------------------------- function Fall (obj) transition.to( obj ,{time = random (3000,9000), delay = random (100,900), y = screenBottom + 20, onComplete = Restart\_Box} ) end local function onBoxTouch (event) local target = event.target target:setFillColor( 0,1,1 ) print("lol") end ---------------------------------------------------------------------------------------- -- A table to hold our boxes ---------------------------------------------------------------------------------------- local Boxes = {} for i = 1,10 do Boxes[i] = display.newRect(random(screenLeft,screenRight), -20, 40,40 ) Boxes[i]:addEventListener( "touch", onBoxTouch ) local Faller = Fall (Boxes[i]) end
btw if you wanted them to fall at the same speed, just change the time of the transition and if you dont want them to reset then you can remove the OnComplete phrase from the transition. ! Hope i helped