停止计算比赛结果

kev*_*ver 2 lua coronasdk

我希望有一个触发器可以在事件发生时停止计算得分,

function restartStopScore()
     score = score + 0
end
Run Code Online (Sandbox Code Playgroud)

不管用

score = 0
local scoreText = display.newText( "Score: " .. score, 20, 20,nil, 40)
scoreText:setTextColor(255,255,255)

local function getScore() -- increments Speed value every time it is called
 score = score + 1
 scoreText.text = "Score: " .. score 
 print("score" .. score)
 end
 timer.performWithDelay(1000, getScore, 0)


function restartScore()
     --reset the score
     score = 0   
end
 timer.performWithDelay(5000, restartScore, 1)--test trigger reset the score
Run Code Online (Sandbox Code Playgroud)

Ble*_*rer 5

你想要保留得分时想要设置一个布尔变量(true/false).将retain_score初始化为顶部.

keeping_score = true
Run Code Online (Sandbox Code Playgroud)

用这个换算你的分数:

if keeping_score then
    score = score + 1
end
Run Code Online (Sandbox Code Playgroud)

您的启动/停止功能将如下所示:

function restartStopScore()
    keeping_score = false
end
function restartContinueScore()
    keeping_score = true
end
Run Code Online (Sandbox Code Playgroud)