Hello,
I’m very new to corona and programming so please bear with me…
I’m trying to create a game where objects fall from the sky.
When the objects hit the ground, I want them to be removed after a period of time.
This is where I struggle with -
local function dropAction()
local crate= display.newImage(“crate.png”)
crate.width = 50
crate.height= 50
crate.y=-30
crate.x= math.random(5,1000)
crate.rotation=50
physics.addBody(crate, “dynamic”, {bounce=0.5})
local function onCollisionRemove(box, event)
if(event.phase==“began”) then
timer.performWithDelay(5000,box:removeSelf())
end
end
Runtime:addEventListener(crate.collision, onCollisionRemove(crate, crate.collision))
end
the bold part is the part where I try to remove the object after it’s had a collision, which obviously isn’t working…
i also tried this but it removes the object instantly -
**local function onLocalCollision( self, event )
if ( event.phase == “began” ) then
timer.performWithDelay(5000, crate:removeSelf())
end
end
crate.collision = onLocalCollision
crate:addEventListener( “collision”, crate )**
Can someone please point me in the right direction??