1
votes

in code below it displays "SCORE: 100" or whatever however as the score / points change the totals are over lapping one on top of the other and you cant read them ... i want the old score erased / removed before displaying new score/points ANY THOUGHTS HOW TO FIX this...this is LUA and using CORONA SDK during my test i have sent print statements to try to troubleshoot sections

--Points is being calculated in another location --UPDATE SCORE POINTS

local function updateScore(Points)

  if WTF == 1 then
    print ("SCORE: -->",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("Score: ",0,0,native.systemFont,40) 
        ScoreTxt:setTextColor(220,50,50)
        ScoreTxt.x = display.contentCenterX
        ScoreTxt.y = display.contentCenterY-100
    end
end
1

1 Answers

3
votes

Every time you call updateScore you're creating a new text object. This code ensures you only create the text once.

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

You could also do:

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