0

好的,这是我目前的分数 - 计时器

local scoreTxt = display.newText( "Score: 0", 0, 0, "Helvetica", 40 )
scoreTxt:setReferencePoint(display.TopLeftReferencePoint)
scoreTxt.x = display.screenOriginX + 10
scoreTxt.y = display.screenOriginY + 32

local function updateScore()
     score = score + 20
     scoreText.text = string.format("Score: %d", score)
end

local scoreTimer = timer.performWithDelay(1000, updateScore, 0)

我希望那个计时器在什么时候暂停

function explode()
    exp.x = bird.x
    exp.y = bird.y
    exp.isVisible = true
    exp:play()
    bird.isVisible = false
    timer.performWithDelay(1500, gameOver, 1)

之后游戏重定向到你死了的屏幕,分数应该是可见的,但我希望它回到 0 时

function start(event)
    if event.phase == "began" then
        storyboard.gotoScene("game", "fade", 50)
    end
end

那么,我该怎么做呢?

4

2 回答 2

1

尝试这个

score = 0 -- You need to set the score to 0 everytime you create the game scene
local scoreTxt = display.newText( "Score: 0", 0, 0, "Helvetica", 40 )
scoreTxt:setReferencePoint(display.TopLeftReferencePoint)
scoreTxt.x = display.screenOriginX + 10
scoreTxt.y = display.screenOriginY + 32

local function updateScore()
     score = score + 20
     scoreText.text = string.format("Score: %d", score)
end

local scoreTimer = timer.performWithDelay(1000, updateScore, 0)

function explode()
    timer.cancel(scoreTimer) --This will cancel the timer and eventually stop
    ...
end
于 2013-09-10T02:00:25.540 回答
0

代码不够清晰,无法告诉我发生了什么,但是如果您试图忽略计时器的功能,请执行以下操作:

EnableScoreTimer = true -- Make It Global so you can call It from other files too.

local function updateScore()
     if not EnableScoreTimer then return end
     score = score + 20
     scoreText.text = string.format("Score: %d", score)
end

local scoreTimer = timer.performWithDelay(1000, updateScore, 0)

这种方式创建了一个布尔值来检查何时禁用计时器,它不会结束计时器,但它只是使它不运行其他操作。每当您想关闭得分计时器时,只需使用简单的真/假检查即可打开/关闭它。

function explode()
    EnableScoreTimer = false
于 2013-09-09T17:22:40.803 回答