In the game I’m developing, two objects collide with each other, and they are both supposed to run their own collision function when that happens. The problem I am having is, when the two objects collide, only one object runs its collision function, and the second object continues on like nothing happened.
This is the basic layout I have for the program collisions.
function moveIMG1Again(img1)
img1.myTransition = transition.to(img1, {time=1000, x=img1.x + 90, onComplete=moveIMG1Again})
end
function moveIMG2Again(img2)
img2.myTransition = transition.to(img2, {time=1000, x=img2.x - 90, onComplete=moveIMG2Again})
end
function img1Collision(event)
if (event.phase == "began") then
img1.myTransition = transition.to(img1, {time=1000, x=img1.x - 90, onComplete=moveIMG1Again})
print("img1 collided")
return true
elseif (event.phase =="ended") then
print("img1 stopped colliding")
return true
end
end
function img2Collision(event)
if (event.phase == "began") then
img2.myTransition = transition.to(img2, {time=1000, x=img2.x + 90, onComplete=moveIMG2Again})
print("img2 collided")
return true
elseif (event.phase =="ended") then
print("img2 stopped colliding")
return true
end
end
img1 = display.newRect(0, 100, 50, 50)
img1.myTransition = transition.to(img1, {time=1000, x=img1.x + 90, onComplete=moveIMG1Again})
img2 = display.newRect(100, 100, 50, 50)
img2:setFillColor (255,25,25)
img2.myTransition = transition.to(img2, {time=1000, x=img2.x - 90, onComplete=moveIMG2Again})
physics.addBody(img1, "dynamic", { bounce = 0 , density = 0.3, friction=0.7})
physics.addBody(img2, "dynamic", { bounce = 0, density = 0.3, friction=0.7})
img1.collision = img1Collision
img1:addEventListener("collision", img1Collision)
img2.collision = img2Collision
img2:addEventListener("collision", img2Collision)
What do I need to do to make sure both objects run their collision functions when they collide with each other? [import]uid: 45667 topic_id: 23039 reply_id: 323039[/import]