I finally got it to work. but there are still one problem.
local objectTable = {} local object2Table = {} --to make sure that the two objects wont hit each other and only the bottom can be hit bottomCollisionFilter = {categoryBits=1, maskBits=6} objectCollisionFilter = {categoryBits=2, maskBits=1} object2CollisionFilter = {categoryBits=4, maskBits=1} local function objectOnTap(self,event) objectTable[self] = nil display.remove(self) return true end local function object2OnTap(self,event) if (event.numTaps == 2) then object2Table[self] = nil display.remove(self) return true else return false end end local function objectOnCollision(self,event) objectTable[self] = nil display.remove(self) return true end local function object2OnCollision(self,event) object2Table[self] = nil display.remove(self) end local function onCollision(event) print("Im Hit") end local function spawnObject() local objectTmp = dislay.newRect.... objectTmp.y = (math.random(1,50) \* -1) objectTmp.x = math.random(1,display.contentWidth) objectTmp.tap = objectOnTap objectTmp:addEventListener( "tap" ) objectTmp.collision = objectOnCollision objectTmp:addEventListener( "collision") physics.addBody( objectTmp,{ bounce = 0 ,friction = 0.5 ,filter = objectCollisionFilter}) objectTmp.linearDamping = 1.5 --how fast they go down end --the code of object2 is pretty much the same with spawnobject local bottom = display.newRect..... bottom.width = display.contentWidth bottom.height = 15 physics.addBody( bottom, "static", { friction = 0.5, bounce = 0 ,filter = bottomCollisionFilter} ) bottom:addEventListener( "collision", onCollision ) objectTimer = timer.performWithDelay( 1000, spawnObject, -1) object2Timer = timer.performWithDelay( 1000, spawnObject2, -1 )
if i comment out the bottom.addEventListener, the object’s collision handler works perfectly. But I want to know that if the objects touched bottom or not, and if they touched it. they will simply disappear.
But when I put the bottom.AddEventListener(delete comment) the objects stays above the bottom as if that their collision handler doesn’t work. But I can see in the console that “Im hit” which means the bottom handler is hit by the objects.
P.S I just typed this code. if there are some typepo error it doesnt hurt that much, cuz I typed it