problem with collision need help

hello everybody, i got some problem when i set a collision.

my idea is that:
i want that an object, on collision with another, is removed and then another different object is displayed.
the problem start when i want remove also the second object!
how can i write that right?
i’m new in corona and lua so i’m sure there is something that i miss :slight_smile:

that’s my code :
local physics = require("physics")physics.start()physics.setGravity(0,3)local background = display.newImage("sky.png")local grass = display.newImage( "grass.png", true )grass.x = 160grass.y = 440physics.addBody( grass, "static", { friction=0.5, bounce=0.3 } )grass.myName = "grass" local egg1 = display.newImage("egg.png")egg1.x = 150egg1.y = 100egg1.myName = "egg"physics.addBody(egg1, "dinamic",{ density=1.0, friction=0.1, bounce=0.5, radius=25 })local function eggcrack()eggcrack1 = display.newImage("egg_cracked.png")eggcrack1.x = 100eggcrack1.y = 100return trueendlocal function eggckremove(e)if eggcrack1 ~= nil then eggcrack1:removeSelf()endendlocal function collision(event)if event.other.myName == "grass" then timer.performWithDelay(500, eggckremove, 0) timer.performWithDelay(50, eggcrack, 0) egg1:removeSelf() endendegg1:addEventListener("collision", collision)[/code] [import]uid: 99803 topic_id: 18134 reply_id: 318134[/import]

  1. at line 16 the spelling should be dynamic

now if you want to remove second object also then you should have to register collision listener for that also or may be runtime listener will be fine
:slight_smile: [import]uid: 12482 topic_id: 18134 reply_id: 69359[/import]

  1. tnx!! xD
  2. how i can set the collision for that body? i want that when egg1 hit the floor ( “grass” ) egg1 is removed and then is displayed another object the eggcrak. at this point is all ok!

but how can i do if i want that this items is removed after some second? it doesnt collide with anything! create and remove the eggcraked is related only with egg1 collision. is that possible to do? [import]uid: 99803 topic_id: 18134 reply_id: 69366[/import]

see if this is working or not

[lua]local physics = require(“physics”)
physics.start()
physics.setGravity(0,3)
local background = display.newImage(“sky.png”)
local grass = display.newImage( “grass.png”, true )
grass.x = 160
grass.y = 440
physics.addBody( grass, “static”, { friction=0.5, bounce=0.3 } )
grass.myName = “grass”
local function collision(event)

if event.other.myName == “grass” then
timer.performWithDelay(500, eggckremove, 0)
timer.performWithDelay(50, eggcrack, 0)
egg1:removeSelf()

end
end

local egg1 = display.newImage(“egg.png”)
egg1.x = 150
egg1.y = 100
egg1.myName = “egg”
physics.addBody(egg1, “dinamic”,{ density=1.0, friction=0.1, bounce=0.5, radius=25 })
local function eggcrack()
eggcrack1 = display.newImage(“egg_cracked.png”)
eggcrack1.x = 100
eggcrack1.y = 100
eggcrack1:addEventListener(“collision”, collision)
return true
end
local function eggckremove(e)
if eggcrack1 ~= nil then
eggcrack1:removeSelf()

end
end
egg1:addEventListener(“collision”, collision)[/lua] [import]uid: 12482 topic_id: 18134 reply_id: 69497[/import]

yes if i put the local function collision at the end then the eggcrack is removed but… dont follow the timer delay…it takes like
1 ms also if i setted more :D, some idea on that? [import]uid: 99803 topic_id: 18134 reply_id: 69526[/import]