我有一个从3开始的倒计时器,并倒计时到0.我试图让它将计时器显示为3位小数。这样用户就可以看到毫秒倒计时。例如:2.765
等。
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 )
答案 0 :(得分:1)
尝试:
display.newText(string.format("%.3f",timeLimit),...