gpt4 book ai didi

lua - 游戏结束时停止计分

转载 作者:行者123 更新时间:2023-12-02 05:13:25 25 4
gpt4 key购买 nike

我喜欢有一个触发器在事件发生时停止计算分数,

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() -- 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

最佳答案

您将要设置一个 boolean variable (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

关于lua - 游戏结束时停止计分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15029489/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com