local function hasCollided(obj1, obj2)
if obj1 == nil then
return false
end
if obj2 == nil then
return false
end
local sqrt = math.sqrt
local dx = obj1.x - obj2.x; – error points to this line
local dy = obj1.y - obj2.y;
local distance = sqrt(dx*dx + dy*dy);
local objectSize = (obj2.contentWidth/2) + (obj1.contentWidth/2)
if distance < objectSize then
return true
end
return false
end
objects = {object1,object2,object3}
local function testCollisions()
for i=1,3 do
for j=1,3 do
if i ~= j then
if hasCollided(objects[i], objects[j]) then
--do my collision stuff here
end
end
end
end
end
Runtime:addEventListener(“enterFrame”, testCollisions)
In destroyScene, I do Runtime:removeEventListener(“enterFrame”, testCollisions).
When I try to exit the scene, it returns me an error saying it’s attempting to return an arithmetic value on x (a nil value) on the line above. Is there any reason for this behaviour?