类型 布尔值 对象 PhysicsContact 库 physics.* 修订 版本 2024.3703 关键词 物理接触, isEnabled 另请参阅 preCollision(碰撞前)
启用或禁用与此接触相关的碰撞。这通常在 preCollision(碰撞前) 事件侦听器中使用,可用于构建
该接触仅在当前时间步长内启用/禁用。未来的接触将照常注册。
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 ball = display.newCircle( 0, 0, 15 ) ball.x, ball.y = display.contentCenterX, display.contentCenterY-40 physics.addBody( ball, "dynamic", { bounce=0.0, radius=20 } ) local function preCollisionEvent( self, event ) local collideObject = event.other if ( collideObject.collType == "passthru" ) then event.contact.isEnabled = false --disable this specific collision end end ball.preCollision = preCollisionEvent ball:addEventListener( "preCollision" )