游戏结束后停止计分。

当事件发生时,我想有一个触发器停止计分:

function restartStopScore()
     score = score + 0
end

无效

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

local function getScore() -- 每次调用都会增加速度值
 score = score + 1
 scoreText.text = "Score: " .. score
 print("score" .. score)
 end
 timer.performWithDelay(1000, getScore, 0)

function restartScore()
    -- 重置得分
     score = 0
end
 timer.performWithDelay(5000, restartScore, 1)--测试触发器重置得分
点赞
用户1281701
用户1281701

你需要设置一个 布尔变量(true/false)来表示是否计分。在顶部初始化 keeping_score 变量。

keeping_score = true

使用以下代码来增加分数:

if keeping_score then
    score = score + 1
end

然后,你的开始/停止函数应该看起来像这样:

function restartStopScore()
    keeping_score = false
end
function restartContinueScore()
    keeping_score = true
end
2013-02-22 17:11:32