我的新分数是重叠的,而不是擦除旧分数?

在代码下面显示“I分数:100”或其他内容,但分数/点变化时,总分重叠在一起,你看不清它们... 我想在显示新的分数/点之前擦除/删除旧的分数 有什么想法如何解决这个问题...这是LUA和使用CORONA SDK 在测试中,我已经发送了打印语句来尝试解决问题

--分数在另一个位置计算 --更新分数点

local function updateScore(Points)

  if WTF == 1 then
    print ("分数:-->",Points)

    --PointsText:removeSelf(PointsText)

        PointsText = display.newText(Points,0,0,native.sytemFont,42)
        PointsText.text = Points
        PointsText.xscale = 0.5; PointsText.yscale = 0.5
        PointsText:setTextColor(155,155,225)
        PointsText.x = centerX * 1
        PointsText.y = centerY - 150

        ScoreTxt = display.newText("分数:",0,0,native.systemFont,40)
        ScoreTxt:setTextColor(220,50,50)
        ScoreTxt.x = display.contentCenterX
        ScoreTxt.y = display.contentCenterY-100
    end
end
点赞
用户1124622
用户1124622

每次调用 updateScore 函数时,你都会创建一个新的文本对象。该代码可确保你仅在首次创建文本时去创建。

local function updateScore(Points)
    if PointsText == nil then
        PointsText = display.newText(Points,0,0,native.sytemFont,42)
    end

    PointsText.text = Points
    PointsText.xscale = 0.5; PointsText.yscale = 0.5
    PointsText:setTextColor(155,155,225)
    PointsText.x = centerX * 1
    PointsText.y = centerY - 150

    ScoreTxt = display.newText("Score: ",0,0,native.systemFont,40)
    ScoreTxt:setTextColor(220,50,50)
    ScoreTxt.x = display.contentCenterX
    ScoreTxt.y = display.contentCenterY-100
end

你也可以这样做:

local function updateScore(Points)
    if PointsText then
        PointsText:removeSelf()
    end

    PointsText = display.newText(Points,0,0,native.systemFont,42)
    PointsText.text = Points
    PointsText.xscale = 0.5; PointsText.yscale = 0.5
    PointsText:setTextColor(155,155,225)
    PointsText.x = centerX * 1
    PointsText.y = centerY - 150

    ScoreTxt = display.newText("Score: ",0,0,native.systemFont,40)
    ScoreTxt:setTextColor(220,50,50)
    ScoreTxt.x = display.contentCenterX
    ScoreTxt.y = display.contentCenterY-100
end
2013-11-10 04:38:10