Hi everyone 
I have a problem with collision detection in my class
I wrote a file, Object.lua which I use as a class object.
I used this article first, for creating my class :
Lua Classes and Packages in Corona
So here is the code:
Object.lua code
local physics = require( "physics" )
physics.start()
physics.setGravity( 0, 0 )
Object = {}
function Object:new( nameParam, startX, startY)
local object = display.newImage ("object.png")
object.myName = nameParam
object.x = startX
object.y = startY
physics.addBody( object, { bounce=0, density=1.0 } )
object.isSensor = true
-- Collision listener function
function object:collision( event )
if ( event.phase == "began" ) then
print( "Collision : " .. event.object1.myName .. " & " .. event.object2.myName )
end
end
-- touch listener function
function object:touch( event )
-- begin focus
display.getCurrentStage():setFocus( self, event.id )
self.isFocus = true
if event.phase == "began" then
self.markX = self.x -- store x location of object
self.markY = self.y -- store y location of object
elseif self.isFocus then
if event.phase == "moved" then
-- drag touch object
local x = (event.x - event.xStart) + self.markX
local y = (event.y - event.yStart) + self.markY
-- move object based on calculations above
self.x = x
self.y = y
elseif event.phase == "ended" or event.phase == "cancelled" then
-- end focus
display.getCurrentStage():setFocus( self, nil )
self.isFocus = false
end
end
return true
end
object:addEventListener( "collision", object )
object:addEventListener( "touch", object )
return object
end
return Object
As you can see I have a touch listener for my object, which I use for drag and drop, and itās working fine.
Iāve also a collision listener for my object, which is triggered during collision, itās working fine too.
My problem is in this line :
print( "Collision : " ⦠event.object1.myName ⦠" & " ⦠event.object2.myName )
>> event.object1 and event.object2 are both nil.
And I canāt understand why. Iām trapped 
I need these references to the objects which are in collision.
Normally, the event parameter has these referencesā¦
I did something wrong, but I canāt figure out what is the problemā¦
Here is the code for main.lua. You can try the example if you want to see by yourself.
main.lua code
local background = display.newRect( 0, 0, display.contentWidth, display.contentHeight )
background:setFillColor(255 , 255, 255 )
display.setStatusBar( display.HiddenStatusBar )
require "Object"
local object1 = Object:new( "object1", 100, 100)
local object2 = Object:new( "object2", 100, 200)
if anyone can help me, It will be very cool.
Thanks
Olivier
[import]uid: 160159 topic_id: 28801 reply_id: 328801[/import]