Not sure if you are actually intending to remove the object when it leaves the X-axis (horizontal) or when it falls out the bottom on the Y-axis (vertical), at any rate a good approach for this might be to go the “samarai fruit” pattern route from the example code and create a rectangle to act as a platform that catches objects and disposes of them.
Again, just tailor according to the correct axis, if you want to catch stuff that falls off the bottom of the screen and remove it you can do something like this:
Look this up in the Samarai Fruit example and it should get you going in the right direction.
-- Adding a collision filter so the crates do not collide with each other, they only collide with the catch platform
local crate = {density = 1.0, friction = 0.3, bounce = 0.2, filter = {categoryBits = 2, maskBits = 1}}
local catchPlatformProp = {density = 1.0, friction = 0.3, bounce = 0.2, filter = {categoryBits = 1, maskBits = 2}}
-- Create a platform at the bottom to "catch" the crate and remove it
function setUpCatchPlatform()
local platform = display.newRect( 0, 0, display.contentWidth \* 4, 50)
platform.x = (display.contentWidth / 2)
platform.y = display.contentHeight + display.contentHeight
physics.addBody(platform, "static", catchPlatformProp)
platform.collision = onCatchPlatformCollision
platform:addEventListener( "collision", platform )
end
function onCatchPlatformCollision(self, event)
-- Remove the object that collided with the platform
event.other:removeSelf()
end
Last thing to do is just to call SetUpCatchPlatform() when you are setting up your level…
Now, everytime a crate falls out the bottom and hits the platform it will get destroyed.
Good luck!
Croisened
[import]uid: 48203 topic_id: 10104 reply_id: 36887[/import]