我是 Corona 的新手,我的评分系统有点问题。看看会发生什么,当你开始游戏时,分数从 0 开始,这是应该的。当玩家获得分数时,它应该增加 2。好吧,它确实增加了它,而不是数字 0 变为数字 2,我得到的是数字 0,然后是 0 顶部的数字 2。所以它覆盖了。我找不到任何实际解决此问题的帖子,所以我认为我在这里做错了。有什么帮助吗?或者只是指出我正确的方向?预先感谢。:)
问问题
550 次
2 回答
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)
继续编码............ :)
于 2013-08-17T08:02:56.733 回答
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
于 2013-08-17T08:02:18.323 回答