Hi,
I’m trying to gave collision with object which has 3 elements, everything works when I check for “began” collision but “ended” fires on it’s own but when I check to register collision between two objects, nothing happen. If you have any ideas please let me know.
Here’s the code:
function newRock1()
local rock1 = display.newImageRect("art/rock1.png", 38, 20 )
rock1.myName = "ground"
rock1.myName2 = "obstacle"
physics.addBody( rock1, {density=rock1body.density, friction=rock1body.friction, bounce=rock1body.bounce, shape=rock1body},
{ isSensor = true, radius=20 },
{ isSensor = true, radius=32 })
local function delete( self, event )
if ( event.phase == "began" ) then
if event.selfElement == 1 and event.other.myName == "delete" then
print("obstacle removed")
self:removeEventListener( "collision", self )
self:removeSelf()
self = nil
elseif event.selfElement == 3 and event.other.myName == "player" then
rock1score = 1
print(rock1score)
elseif event.selfElement == 2 and event.other.myName == "player" then
rock1score = 2
print(rock1score)
elseif event.selfElement == 1 and event.other.myName == "player" then
rock1score = 0
print(rock1score)
end
elseif ( event.phase == "ended" ) then
if event.selfElement == 1 and event.other.myName == "player" then
print("Goodccc")
if rock1score == 1 then
print("Good")
score = score + 10
elseif rock1score == 2 then
print("great")
elseif rock1score == 0 then
print("miss")
end
end
end
end
rock1.collision = delete
rock1:addEventListener( "collision", rock1 )
return rock1;
end
when player collides with elements during “began” event all works fine, but at the “ended” nothing happening. The “ended” event fires on it’s own but nothing is happening between objects.
Help… [import]uid: 27699 topic_id: 10606 reply_id: 310606[/import]