CoronaApril 25th, 2012shinu.s
When detected with a table listener within an object, each Physics preCollision event includes event.other, which contains the ID of the other Corona display object involved in the collision.
Syntax:
event.other
Example:
local physics = require("physics")
physics.start()
local crate1 = display.newImage( "crate.png" )
physics.addBody( crate1, { density=3.0, friction=0.5, bounce=0.3 } )
crate1.myName = "first crate"
local ground = display.newImage( "ground.png" )
ground.y = display.contentHeight
ground.myName = "ground"
local function onLocalPreCollision( self, event )
-- The preCollision event type fires shortly before a collision occurs, so you can use this if you want
-- to override some collisions in your game logic. For example, you might have a platform game
-- where the character should jump "through" a platform on the way up, but land on the platform
-- as they fall down again.
-- Note that this event is very "noisy", since it fires whenever any objects are somewhat close!
print( "preCollision: " .. self.myName .. " is about to collide with " .. event.other.myName )
end
-- Here we assign the above two functions to local listeners within crate1 only, using table listeners:
crate1.preCollision = onLocalPreCollision
crate1:addEventListener( "preCollision", crate1 )