类型 事件 修订 版本 2024.3703 关键词 preCollision, 物理 另请参阅 碰撞检测 (指南) collision postCollision physics.setAverageCollisionPositions() physics.setReportCollisionsInContentCoordinates()
与 physics 库结合使用。物理引擎"preCollision"
。除了这些事件和标准的 collision 事件之外,Corona 还提供了 postCollision 事件。
根据预碰撞是在本地还是全局检测到的,所涉及对象的引用会有所不同。有关这两种碰撞处理方法的更多信息,请参阅 碰撞检测 指南。
本地碰撞事件 | 全局碰撞事件 | |
---|---|---|
event.target 或 self |
event.object1 |
|
event.other |
event.object2 |
|
event.selfElement |
event.element1 |
|
event.otherElement |
event.element2 |
请比较这两个示例函数以了解引用变量
-- Local preCollision handling local function onLocalPreCollision( self, event ) print( event.target ) --the first object in the collision print( event.other ) --the second object in the collision print( event.selfElement ) --the element (number) of the first object which was hit in the collision print( event.otherElement ) --the element (number) of the second object which was hit in the collision end object.preCollision = onLocalPreCollision object:addEventListener( "preCollision" ) -- Global preCollision handling local function onGlobalPreCollision( event ) print( event.object1 ) --the first object in the collision print( event.object2 ) --the second object in the collision print( event.element1 ) --the element (number) of the first object which was hit in the collision print( event.element2 ) --the element (number) of the second object which was hit in the collision end Runtime:addEventListener( "preCollision", onGlobalPreCollision )
物理引擎"preCollision"
事件。