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