我使用了Rob Miracle從GitHub獲得的代碼。它工作正常,但我的問題是,無論何時到達00:00或負面,它遵循我的指令去另一個場景,但它仍在更新。如何停止計時器,如果低於或等於0 corona sdk
local secondsLeft = 2 * 60 -- 2 minutes * 60 seconds
local clockText = display.newText("02:00", 280, 1, native.systemFontBold, 25)
clockText:setFillColor(1, 0, 0)
local function updateTime()
-- decrement the number of seconds
secondsLeft = secondsLeft - 1
-- time is tracked in seconds. We need to convert it to minutes and seconds
local minutes = math.floor(secondsLeft/60)
local seconds = secondsLeft % 60
-- make it a string using string format.
local timeDisplay = string.format("%02d:%02d", minutes, seconds)
clockText.text = timeDisplay
end
-- run them timer
local countDownTimer = timer.performWithDelay(1000, updateTime, secondsLeft)
什麼仍在更新?你的問題不清楚。 –
添加此代碼:if timeDisplay <=「00:00」然後 \t \t \t打印「遊戲結束」 \t \t \t GAMEOVER() \t \t端我試圖跟蹤的時間,但文它轉到功能遊戲結束,它仍然在遞減。 – int21h
我檢查你的代碼。它工作正常。文本對象在達到「00:00」時間後不會更新。 – ldurniat