Evening all.
Another question from someone just starting out with Corona.
I've now got my player and item objects jumping around the screen, and I set up a global collisions listener to see if the player collides with any items and reward them for it.
1 2 3 4 5 6 7 8 9 10 11 | -- score gui local score = display.newText( "0", player.x, player.y-70, "Helvetica", 34) local function onCollision(event) if (event.object1.name == "item" and event.object2.name == "player") then score.text = score.text + 100 item:removeSelf() end end Runtime:addEventListener ("collision", onCollision) |
Should it be like this (presuming that obj1 is the item your trying to remove)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | -- score gui local score = display.newText( "0", player.x, player.y-70, "Helvetica", 34) local function onCollision(event) local obj1 = event.object1 local obj2 = event.object2 if (obj1.name == "item" and obj2.name == "player") then score.text = score.text + 100 obj1:removeSelf() end end Runtime:addEventListener ("collision", onCollision) |
Nope, item is the name of the thing being removed.
It actually does remove it. 100% of the time.
However, sometimes the item is removed, and the player passes through.
But every so often, say 1 in 50 times, the item is removed, but, the player object bounces off the item object for a split second before its removed.
Could the item be a sensor body ?
I'm still not sure that you got the question I was asking Danny, but, I looked up the API and read about sensor bodies and that was exactly what I was looking for.
100+ test cases now, and they all worked perfectly.
Cheers Danny.
Yeah i got the question :)
Sorry for not going into more detail in my previous post