Remove created stuff...

Hi all, i am new to corona and i come from OOP. I can’t enter the corona way yet… so i need your help to understand some concepts. Here is my example

[code]local function newTomato()
local tomato=display.newImageRect( “tomato.png”, 60, 60 )

tomato.x = 676
spown=math.random(4)
if spown==1 then
tomato.y =561
elseif spown==2 then
tomato.y =386
elseif spown==3 then
tomato.y =698
elseif spown==4 then
tomato.y =242
end

tomato.rotation = 90
physics.addBody(tomato, { density=0.3, friction=0.2, bounce=0} )
local xf=math.random(10,13)
local yf=math.random(-7,7)
tomato:applyLinearImpulse(xf,yf)
tomato.angularVelocity=math.random(-300,300)
Runtime:addEventListener( “collision”, collisioni)

end
local dropCrates = timer.performWithDelay(1000, newTomato, 0 )[/code]

i create random display objects (tomatoes) and i want to delete them when they collide with the ground…

local ground = display.newImageRect( "ground.png", 1024, 74 ) ground.x = 36 ground.y = 511 ground.rotation = 90 physics.addBody( ground, "static", { friction=0.5, bounce=0.3 } )

Can you help me?
Thanks.
I can’t understand how access the single object…
Sorry for the English. [import]uid: 70929 topic_id: 23199 reply_id: 323199[/import]

This should do it

[code]
local function newTomato()
local tomato=display.newImageRect( “tomato.png”, 60, 60 )
tomato.myName = “tomato”
tomato.x = 676
spown=math.random(4)
if spown==1 then
tomato.y =561
elseif spown==2 then
tomato.y =386
elseif spown==3 then
tomato.y =698
elseif spown==4 then
tomato.y =242
end

tomato.rotation = 90
physics.addBody(tomato, { density=0.3, friction=0.2, bounce=0} )
local xf=math.random(10,13)
local yf=math.random(-7,7)
tomato:applyLinearImpulse(xf,yf)
tomato.angularVelocity=math.random(-300,300)
Runtime:addEventListener( “collision”, collisioni)

end
local dropCrates = timer.performWithDelay(1000, newTomato, 0 )
local ground = display.newImageRect( “ground.png”, 1024, 74 )
ground.x = 36
ground.y = 511
ground.rotation = 90
ground.myName = “ground”
physics.addBody( ground, “static”, { friction=0.5, bounce=0.3 } )
local function onCollision(event)
local obj1 = event.object1
local obj2 = event.object2

if event.phase == “began” then
if obj1.myName == “tomato” and obj2.myName == “ground” then
local function removeObj()
display.remove(obj1)
end
timer.performWithDelay(1, removeObj)
end
end

return true
end

Runtime:addEventListener:(“collision”, onCollision) [import]uid: 84637 topic_id: 23199 reply_id: 92867[/import]

i love you. [import]uid: 70929 topic_id: 23199 reply_id: 92967[/import]