Hi, i have a problem with my code. i want to disable touching for an object when the object collide with another object. but when i execute the code, it reports a lot of collision and it idoesn’t response any more. :wacko: for any other button or touching event. Thanks.
Code is here:
object1 = display.newImage("tire2.png", centerX, 500) object1.myName = "object1" object1.bodyType = "dynamic" object1.isBullet = true physics.addBody( object1, { density=0.9, friction=0.5, bounce=0.6, radius=60 } ) object1.isSleepingAllowed = false object1:addEventListener( "touch", dragBody ) object2 = display.newImage("tire3.png", centerX-centerX/2-180, 500) object2.myName = "object2" object2.bodyType = "dynamic" object2.isBullet = true physics.addBody( object2, { density=0.9, friction=0.5, bounce=0.6, radius=60 } ) object2.isSleepingAllowed = false object2:addEventListener( "touch", dragBody ) button = display.newImage("button.png", 145,145) button.anchorX = 1 button.anchorY = 0 button.x = \_W-52 button.y =72.5 button.myName = "button" function collision1 (event) if ( event.phase == "began" ) then if (event.object1.myName == "object1" and event.object2.myName == "object2" ) then print (event.object1.myName .." and " .. event.object2.myName ) object2:removeEventListener( "touch", dragBody ) end end end function buttonfunc(event) if event.phase == "ended" then message = display.newText( "Button pressed.", 0, 0, "ContenuBook-Display", 40 ) end end Runtime:addEventListener( "collision", collision1) button:addEventListener("touch", buttonfunc)