I have an issue with my collision listener; it is failing to detect the collision at all. Can someone please tell me what is wrong and provide a solution? Thanks.
Here is the code:
[lua]
local escapesensor = display.newImage(“PlanetCollisionSensor.png”)
escapesensor.x = display.contentWidth/2
escapesensor.y = -20
physics.addBody(escapesensor, “static”)
escapesensor.isSensor = true
escapesensor.alpha = 0.01
escapesensor.rotation = 90
local escapesensor2 = display.newImage(“PlanetCollisionSensor.png”)
escapesensor2.x = display.contentWidth/2
escapesensor2.y = 340
physics.addBody(escapesensor2, “static”)
escapesensor2.isSensor = true
escapesensor2.alpha = 0.01
escapesensor2.rotation = 90
local function escapeSensorCollision(self,event)
if (event.phase == “began”) then
if (event.other.name == “bluespaceship” or “redspaceship” or “purplespaceship” or “greenspaceship” or “bluegreenspaceship” or “pinkpurplespaceship”) then
spaceshipLives = spaceshipLives - 1
print(“Collision Received!”)
display.remove(event.other)
event.other = nil
end
end
end
escapesensor.collision = escapeSensorCollision
escapesensor:addEventListener(“collision”, escapesensor)
escapesensor2.collision = escapeSensorCollision
escapesensor2:addEventListener(“collision”, escapesensor2)
[/lua]
Basically, I have two rectangular sensors that detect whether a spaceship has hit it or not, and they are failing to detect the collisions.