Lua 时间会在电晕中消失
我正在尝试使用Lua在Corona SDK中创建计时器倒计时。我对编码很陌生,所以我从来没有设置过。你知道我该怎么做吗 这是我到目前为止所拥有的Lua 时间会在电晕中消失,lua,coronasdk,countdowntimer,Lua,Coronasdk,Countdowntimer,我正在尝试使用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, na
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 timeCounter = n
local myTimer=timer.performWithDelay( 1000, function() timeCounter = timeCounter - 1 end, n )
这一行将把timeCounter变量减少n倍。当你完成了时间,你可以简单地删除它
timer.cancel( myTimer )
这样就可以了
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)
非常感谢。工作很有魅力。谢谢你的提示。工作得很好。