Properly Removing Object On Post Collision

In my game I have collisions in which I need to break objects and make them disappear. I am using the Director Class. Here is a stripped down sample of my code.

1
2
3
4
5
6
7
8
9
local function onPostCollision( event )
    if event.force > 2 then 
        event.object1:removeSelf()
       --I have also tried if event.object1 then event.object1:removeSelf end
    end
end 
Runtime:addEventListener("postCollision", onPostCollision)
--later on when changing scene
Runtime:removeEventListener("postCollision", onPostCollision)

Furthermore, I noticed that the Runtime function does not turn off when I leave the scene. I have added a delay with the timer in my code and after the first time, I noticed that the pieces start being removed and the delay is nonexistent.

views:1631 update:2011/10/4 8:06:35
corona forums © 2003-2011