类型 PhysicsContact(物理接触) 事件 preCollision(预碰撞) 修订 版本 2024.3703 关键词 preCollision, contact
在预碰撞期间,会发生多个接触点。您可以操作这些接触点来创建某些效果,例如
您不应该持有接触对象。它仅在碰撞侦听器的范围内有效。
event.contact.isEnabled
— 启用或禁用与接触相关的碰撞。event.contact.isTouching
— 指示两个对象是否接触event.contact.bounce
— 指定碰撞的反弹系数event.contact.friction
— 指定碰撞的摩擦系数local platform = display.newRect( 0, 0, 280, 30 ) platform.x, platform.y = display.contentCenterX, display.contentCenterY+80 platform.collType = "passthru" physics.addBody( platform, "static", { bounce=0.0, friction=0.3 } ) local function preCollisionEvent( self, event ) local collideObject = event.other if ( collideObject.collType == "passthru" ) then event.contact.isEnabled = false -- Disable this specific collision end end local ball = display.newCircle( 0, 0, 15 ) ball.x, ball.y = display.contentCenterX, display.contentCenterY-40 physics.addBody( ball, "dynamic", { bounce=0.0, radius=20 } ) ball.preCollision = preCollisionEvent ball:addEventListener( "preCollision", ball )