我需要从exitScene函数中删除计时器,因为我删除了所有的侦听器,但我没有找到如何。这是代码:
function scene:enterScene(event)
planeta.enterFrame = rotarPlaneta
Runtime:addEventListener("enterFrame", planeta)
Runtime:addEventListener("touch", touchScreen)
timer.performWithDelay( 1000, throwBrickEnemigo,0 )
end
function scene:exitScene(event)
Runtime:removeEventListener("enterFrame", planeta)
Runtime:removeEventListener("enterFrame", touchScreen)
Runtime:removeEventListener("enterFrame", planeta)
end
答案 0 :(得分:4)
您需要为计时器分配一个变量并取消它。
local throwBrickTimer -- Reference for the timer
function scene:enterScene(event)
planeta.enterFrame = rotarPlaneta
Runtime:addEventListener("enterFrame", planeta)
Runtime:addEventListener("touch", touchScreen)
--> Give the timer a variable
throwBrickTimer = timer.performWithDelay( 1000, throwBrickEnemigo,0 )
end
function scene:exitScene(event)
--> Cancel the timer
timer.cancel(throwBrickTimer)
Runtime:removeEventListener("enterFrame", planeta)
Runtime:removeEventListener("enterFrame", touchScreen)
Runtime:removeEventListener("enterFrame", planeta)
end