изключване на времето в corona sdk

Опитвам се да създам обратно отброяване на таймера в Corona SDK с помощта на Lua. Аз съм нов в кодирането, така че никога не съм настройвал такъв. Някакви идеи как да направя това.

Ето какво имам досега

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)

person Dips    schedule 20.03.2013    source източник


Отговори (2)


това ще го направи...

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)
person Krishna Raj Salim    schedule 21.03.2013
comment
Благодаря много. Работи като чар. - person Dips; 21.03.2013

Можеш да използваш

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

Този ред ще намали променливата timeCounter за n пъти. Когато приключите с времето, можете просто да го премахнете

timer.cancel( myTimer )
person Doğancan Arabacı    schedule 21.03.2013
comment
Благодаря за бакшиша. Работи страхотно. - person Dips; 21.03.2013