2015-04-14 131 views
1

我有一個倒數計時器,從3開始計數到0。我試圖讓計時器顯示3位小數。這樣用戶可以看到毫秒數減少。例如:2.765將計時器更改爲小數點後3位

local function choice (event) 
    randCircle = circle[ math.random(#circle) ] 
    randCircle:setFillColor(1,0,0); 

    local timeLimit = 3.000 
     timeLeft = display.newText(timeLimit, randCircle.x, randCircle.y, native.systemFontBold, 36) 
     timeLeft:setTextColor(0,0,0) 
     sceneGroup:insert(timeLeft) 

     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 
    aTimer = timer.performWithDelay(1000,timerDown,timeLimit) 

end 
timer.performWithDelay(2000, choice, 0) 

回答

1

嘗試:

display.newText(string.format("%.3f",timeLimit),... 
相關問題