event.contact

类型 PhysicsContact(物理接触)
事件 preCollision(预碰撞)
修订 版本 2024.3703
关键词 preCollision, contact

概述

在预碰撞期间,会发生多个接触点。您可以操作这些接触点来创建某些效果,例如单侧平台。

陷阱

您不应该持有接触对象。它仅在碰撞侦听器的范围内有效。

属性

示例

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 )