Hi EHO,
There are two good ways of doing this. The first example is using a collision listener to see what hits it and destroys them.
The second is on a runtime listener. You dont need to use a runtime listener for every object, just deal with all objects in the one runtime listener. Just remember to remove this runtime listener when exiting scene.
Here is the 2 sets of code to show you how it can be used.
Collision Listener ( best option)
display.setStatusBar(display.HiddenStatusBar) physics = require("physics") physics.start() -- set y threshold level local threshold = 300 local box = {} local numbox = 5 for i=1,numbox do box[i] = display.newRect(i\*50,50,40,40) physics.addBody(box[i], {density=1}) box[i].gravityScale = i\*0.2 -- set varying gravity end local colsensor = display.newRect(0,threshold,320,20) -- collision sensor bar physics.addBody(colsensor, "static", {isSensor = true}) local function hitsensor(self,e) if e.phase == "began" then display.remove(e.other) e.other = nil end end colsensor.collision = hitsensor colsensor:addEventListener("collision")
Runtime Listener:
display.setStatusBar(display.HiddenStatusBar) physics = require("physics") physics.start() -- set y threshold level local threshold = 300 local box = {} local numbox = 5 for i=1,numbox do box[i] = display.newRect(i\*50,50,40,40) physics.addBody(box[i], {density=1}) box[i].gravityScale = i\*0.2 -- set varying gravity end local function checkthreshold(e) for i=1,numbox do if box[i] then -- checks to see if box is not nil if box[i].y \> threshold then -- remove box if greater than threshold display.remove(box[i]) box[i] = nil end end end end Runtime:addEventListener("enterFrame", checkthreshold)