I have a runtime event that moves an object:
local rotationDirection = 1
local _W = display.contentWidth / 2
local _H = display.contentHeight / 2
local function moveObject ( event )
if(object.x > _W - 100) then
object.x = object.x + 1 * rotationDirection
end
if(object.x >= _W + 100) then
rotationDirection = -1
elseif (object.x <= _W - 100) then
rotationDirection = 1
end
end
** I want to collide with the object and add 1 to the level count but when I try to remove the object or remove the runtime listener I get an error and the program crashes.
**Can someone help me with this?
local function collide1 ( event )
if event.phase == “began” then
print(“Collision 1 occuring”)
levelCount = levelCount + 1
Runtime:removeEventListener(“enterFrame”, moveObject)
object:removeSelf()
end
end
Runtime:addEventListener(“enterFrame”, moveObject) [import]uid: 42126 topic_id: 8751 reply_id: 308751[/import]