Hey.
I have a skateboarder and board set up as follows
function setPlayer()
player1 = display.newRect (0, 0, 30, 30)
skaterShape = { -15,-10, 15,-10, 15,15, -15,15 }
skaterShape.myName = "skater"
boardShape = { -15, -15, 15, -15, 15, -10, -15, -10 }
boardShape.myName = "board"
player1.x = \_W / 2 + 150
player1.y = 41 + player1.contentHeight / 2 -- was 35
player1:setFillColor(0, 0, 255)
player1.myName = "player1"
playergroup:insert(player1)
physics.addBody( player1, "dynamic",
{ density=1, friction=0, bounce=0, shape=skaterShape },
{ density=1, friction=0, bounce=0, shape=boardShape }
)
player1.collision = onLocalCollision
player1:addEventListener( "collision", player1 )
end
I need to detect which “shape” skater or board has collided with the ground.
I already have it set up so that “player1” collides perfectly with the terrain, and thought it would be a simple matter of using something like
boardShape.myName = "board"
in the local collision event.
I’ve tried adding an event listener to skater and board respectively, but it gave a “nil” error, probably because skater and board are tables rather than display objects.
Can anyone help, I’m sure it’s something really simple.
Thanks in advance.
*** EDIT ***
I used
event.selfElement == 2
to sort this out, in case anyone else has the same problem (and doesn’t read the documentation properly
[import]uid: 67933 topic_id: 16156 reply_id: 316156[/import]