Question

im new to Corona and im having a bit of a problem with my scoring system. See what happens is that when you begin the game, the score starts at 0, which it should. When the player gets a score, it should increment by two. Well it does increment its just that instead of the number 0 changing to the number 2, what i get is the number 0 and then the number 2 ON TOP of 0. So it overlays. I couldnt find any posts that actually addressed this issue, so i think im doing something wrong here. Any help? Or just point me in the right direction? Thank in advance. :)

Was it helpful?

Solution 2

the problem with your code is that everytime you call displayScore() function it creates another newText because you always calls

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

try to declare the scoreText outside the function displayScore() just like this

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

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

end

OTHER TIPS

Try this and change your code:

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)

Keep Coding............ :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top