event.contact

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

概述

在碰撞过程中,会发生多个接触点。您可以操作这些接触点来创建特定效果。

注意事项

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

属性

示例

local platform = display.newRect( 0, 0, 280, 30 )
platform.surfaceType = "superbounce"
platform.x, platform.y = display.contentCenterX, display.contentCenterY+80
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 onCollision( self, event )

   local collideObject = event.other
   if ( collideObject.surfaceType == "superbounce" ) then
      event.contact.bounce = 20  -- Magnify bounce for this specific collision
   end
end

ball.collision = onCollision
ball:addEventListener( "collision" )