When checking the index on event.selfElement during collisions, the index is being reported incorrectly on the exited event.phase.
In the following example, when the complex body enters the ground, 2, 1 is printed to the console as "groundSensor" and then "playerBodyShape" enter the ground collider (this is correct).
However, when the complex body exits the ground (when jumping for example), -123, -123 is printed to the console (not correct).
I created a simple project so you can easily test this yourself, download it here: http://dl.dropbox.com/u/3302748/selfElementBug.zip
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | local physics = require "physics" physics.start() physics.setGravity(0, 20) physics.setDrawMode( "hybrid" ) -- create player with "complex body" local player = display.newImage( "player.png",100,100 ) local playerBodyShape = { -4,-10 , 4,-10 , 4,10 , -4,10 } -- index 1 local groundSensor = { -4,12 , 4,12 , 4,20 , -4,20 } -- index 2 physics.addBody( player, "dynamic", { density=3, friction=0, bounce=0, shape=playerBodyShape }, { density=0, friction=0, bounce=0, shape=groundSensor, isSensor = true } ) player.isFixedRotation = true -- create ground local ground = display.newRect(0, 300, 480, 20); ground:setFillColor(0,0,200) physics.addBody( ground, "static", { density=3.0, friction=0.5, bounce=0 } ) -- jump button local function touchMyRectangle(event) local phase = event.phase if phase == "began" then player:applyLinearImpulse( 0, -5, player.x, player.y ) end end local myRectangle = display.newRect(0, 0, 480, 320); myRectangle:setFillColor(0,0,0,0) myRectangle:addEventListener( "touch", touchMyRectangle ) -- player collision local function OnPlayerCollision(self, event) if event.phase == "began" then print (event.selfElement) -- selfElement index # is correct elseif event.phase == "ended" then print (event.selfElement) -- selfElement index # is not correct end end player.collision = OnPlayerCollision player:addEventListener("collision", player) |
I am also experiencing this behavoir. Only in "ended"...suks...
Hey tim10,
I'm assuming you have filed this as a bug, what's the #?
Thanks
Peach :)
I opened 6773 last Friday, which appears to be a duplicate of this one. Please close mine and sorry for not researching better.