1

I need to remove the timer from the exitScene function as I remove all the listeners but I didn't found how. This is the code:

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
4

1 回答 1

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
于 2013-05-02T01:35:22.297 回答