如何在游戏中加入计时器?

时间:2014-10-08 23:55:48

标签: timer corona scoring

我一直试图为Corona SDK中的游戏做一个得分守护者,但无济于事。如何让得分管理员每秒加一个然后保存高分?

1 个答案:

答案 0 :(得分:4)

我通常不会给出这样的解决方案,以便将来尝试将问题分解为更小的问题。首先,如何在屏幕上显示文字?然后去,我如何更新屏幕上的文字?然后开始寻找每秒更新的方法。等等让它变得容易多了。

-- Variables
local score = 0
local scoreTxt = display.newText( "Score: "..score, 100, 200, native.systemFont, 16 )
scoreTxt:setFillColor( 1, 0, 0 )

-- Listener for your timer, updates score variable and updates the text
local function scoreKeeper( event )
    score = score + 1
    scoreTxt.text = "Score: "..score
end

-- Timer
timer.performWithDelay( 1000, scoreKeeper, -1 )
相关问题