在Corona中评分叠加

时间:2013-08-17 04:49:43

标签: lua overlay corona scoring

我是Corona的新手,我的评分系统有点问题。看看当你开始游戏时,分数从0开始,它应该是。当玩家获得分数时,它应该增加2。那么它确实增加了它而不是数字0变为数字2,我得到的是数字0然后数字2 ON TOP为0.所以它覆盖。我找不到任何实际解决这个问题的帖子,所以我认为我在这里做错了。有帮助吗?或者只是指出我正确的方向?预先感谢。 :)

2 个答案:

答案 0 :(得分:1)

试试这个并更改您的代码:

score = 0
local scoreText = display.newText(score, 100, 100, native.systemFont, 50)
scoreText:setTextColor(255, 255, 255)

function displayScore()
    --[[ The problem was here. You are creating new label over and over in 
          your code. So, you need to either remove the old label and add 
          new using 'scoreText:removeSelf()' or just update the code --]]
    score = score + 1
scoreText.text = score
end
Runtime:addEventListener("tap",displayScore)

保持编码............:)

答案 1 :(得分:0)

您的代码存在的问题是,每当您调用displayScore()函数时,它都会创建另一个newText,因为您总是调用

local scoreText = display.newText("Score: ", 415, 100, native.systemFont, 50)

尝试在函数scoreText之外声明displayScore()就像这样

local scoreText = display.newText("Score: ", 415, 100, native.systemFont, 50)

function displayScore()
    scoreText:setTextColor(255, 255, 255)
    scoreText.text = scoreText.text = "Score: "..score

end