2013-03-20 60 views
2

我試圖創建一個計時器倒計時在Corona SDK使用Lua。我對編碼很陌生,所以我從來沒有設置過。任何想法我會如何去做這件事。在科羅納sdk時間coutdown

這裏是我迄今爲止

infoBar = display.newImage('infoBar.png', 280) 
score = display.newText('0', 65, -2, native.systemFontBold, 14) 
score:setTextColor(0) 
timeLeft = display.newText('20', 175, -2, native.systemFontBold, 14) 
timeLeft:setTextColor(0) 

回答

5

這將做到這一點...

local timeLimit = 20 
timeLeft = display.newText(timeLimit, 160, 20, native.systemFontBold, 14) 
timeLeft:setTextColor(255,0,0) 

local function timerDown() 
    timeLimit = timeLimit-1 
    timeLeft.text = timeLimit 
    if(timeLimit==0)then 
     print("Time Out") -- or do your code for time out 
    end 
    end 
timer.performWithDelay(1000,timerDown,timeLimit) 
+1

非常感謝。像魅力一樣工作。 – 2013-03-21 14:28:33

3

您可以使用

local timeCounter = n 
local myTimer=timer.performWithDelay(1000, function() timeCounter = timeCounter - 1 end, n) 

這條線將減少timeCounter變量n次。當你完成時,你可以簡單地將其刪除

timer.cancel(myTimer) 
+0

謝謝你的提示。工作很好。 – 2013-03-21 14:29:17