我试图使用Lua在Corona SDK中创建计时器倒计时。我对编码很陌生,所以我从未设置过。任何想法我将如何去做。

这是我到目前为止所拥有的

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)

最佳答案

这会做到的...

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)

10-08 14:37