【问题标题】:Corona SDK Storyboard EnterScene/ExitSceneCorona SDK 故事板 EnterScene/ExitScene
【发布时间】:2013-10-07 19:12:59
【问题描述】:

我在关闭计时器和事件时遇到了一些问题

这是我的 enterScene(事件)

function scene:enterScene( event )

storyboard.purgeScene("menu")

timer.performWithDelay(1, update, -1)
Runtime:addEventListener("touch", touched, -1)
yesButton:addEventListener("touch", yesListener )
noButton:addEventListener("touch", noListener )

end

这是我的退出场景(事件)

function scene:exitScene( event )
  timer.pause()
    Runtime:removeEventListener("touch", touched, -1)
    yesButton:removeEventListener("touch", yesListener )
    noButton:removeEventListener("touch", noListener )
end

我在“time.pause()”有错误。

关闭计时器和事件的正确语法是什么?

【问题讨论】:

    标签: storyboard coronasdk


    【解决方案1】:

    您可以将计时器分配给一个变量,并在需要时取消它。

    local myTimer -- Reference for the timer
    
    function scene:enterScene(event)
        storyboard.purgeScene("menu")
        myTimer = timer.performWithDelay(1, update, -1)
        Runtime:addEventListener("touch", touched, -1)
        yesButton:addEventListener("touch", yesListener )
        noButton:addEventListener("touch", noListener )
    end
    
    function scene:exitScene(event)
        --> Cancel the timer
        timer.cancel(myTimer)
    
        Runtime:removeEventListener("touch", touched, -1)
        yesButton:removeEventListener("touch", yesListener )
        noButton:removeEventListener("touch", noListener )
    
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-20
      • 1970-01-01
      相关资源
      最近更新 更多