hi,
* in collision documentation (https://docs.coronalabs.com/api/event/collision/index.html) it is written:
[lua]-- Local collision handling
local function onLocalCollision( self, event )[/lua]
which does not work but:
[lua]-- Local collision handling
local function onLocalCollision( event )[/lua]
works.
EDITED:
I was wrong. There are function and object listener and both work. Just different syntax.
* function listener:
local function onLocalCollision_1 ( event )
object:addEventListener( “collision”, onLocalCollision_1 )
* object listener:
local function onLocalCollision_2 ( self, event )
object.collision = onLocalCollision_2
object:addEventListener( “collision”, object)
* second is that mapping (from same documentation) is not correct:
[lua]local physics = require(“physics”)
physics.start()
physics.setGravity(0, 0)
local wall = display.newRect( 100, 200, 300, 10 )
physics.addBody(wall, “static”, {density = 1.0, friction = 0, bounce = 0, isSensor = false})
– create a ball and set it in motion
ball = display.newCircle( 80, 130, 15 )
physics.addBody(ball, “dynamic”, {density = 1.0, friction = 0.0, bounce = 0.5, isSensor = false, radius = 15} )
ball.name = “my ball”
ball.isBullet = true
ball:setLinearVelocity( 0, 50 )
– Local collision handling
local function onLocalCollision( event )
print( “LC” )
print( event.target.name ) --the first object in the collision >> prints: "my ball"
print( event.other.name ) --the second object in the collision >> prints: nil
end
ball:addEventListener( “collision”, onLocalCollision )
– Global collision handling
local function onGlobalCollision( event )
print( “GC” )
print( event.object1.name ) --the first object in the collision >> prints: nil
print( event.object2.name ) --the second object in the collision >> prints: "my ball"
end
Runtime:addEventListener( “collision”, onGlobalCollision )
[/lua]
so mapping is done: target <–> object 2 , other <–> object 1
What is happening here ? (doc. error or …)