Having issues with remove on collision

hey so im trying to remove both images/objects when they collide, i put this code in, doesn’t work for me though, can anyone help me? Thanks!

[code]
local crate1 = display.newImage( “scroll.png”, 180, 170 )
physics.addBody( crate1, { density = 3.0, friction = 0.3, bounce = 0.1 } )
crate1.myName = “first crate”
localGroup:insert(crate1)

local crate2 = display.newImage( “ground.png”, 160, 400 )
physics.addBody( crate2, “static”, { friction=1.5, bounce=0.1 } )
crate2.myName = “second crate”
localGroup:insert(crate2)

local function onCollision( event )
if ( event.phase == “began” ) then

print( "began: " … event.object1.myName … " & " … event.object2.myName )

elseif ( event.phase == “ended” ) then
lives = lives - 1
livesDisplay.text = lives
if lives == 0 then
director:changeScene(“level1success”)
event.object2:removeSelf()

end
end

Runtime:addEventListener( “collision”, onCollision )
[/code] [import]uid: 10827 topic_id: 10013 reply_id: 310013[/import]

You are only calling removeSelf once, in the same function used to change scenes.

To remove both objects, you would need to specifically state removeSelf on BOTH, not just on one and not when the scene is changing as, unless you are using a timer, you wont be able to tell if the object is being removed (unless you print something to indicate as much) if the scene immediately changes to something else using director.

Peach :slight_smile: [import]uid: 52491 topic_id: 10013 reply_id: 36567[/import]