Hi, :mellow:
I have added a timer.performwithdelay to a function to spawn objects (Box) 1 by 1 in every 2 secs in a random y point.
[lua]------Spawn Box Function
function spawnBox ()
height = math.random ( display.contentCenterY - 160, display.contentCenterY + 160)
Box = display.newImageRect ( “Redbox.png”, 110, 350)
Box.x = display.contentCenterX
Box.y = height
end
------Spawn with delay
timer.performWithDelay ( 2000, spawnBox, -1)[/lua]
Also, I created a Btn to remove the spawn objects
[lua]------ Create btn
local btn = display.newRect ( 100, 100, 50, 50 )
function removeBox ()
if event.phase == “began” then
display.remove (Box)
end
end
btn:addEventListener (“touch”, removeBox)[/lua]
However, I can’t remove the first one when the objects spawn more than 2.
( The Btn can only remove the latest spawned object )
Thanks For Reading and answering my question