My score doesn't stop when my main object hits an obstacle (keeps running on the storyboard restart and start screen). I want it to stop and be able to save it and show it to the gamer next time (even share it on facebook if it's possible ). an image will pop out where the player can find its best score ever, and his current score.
score = 0
local scoreNumber = display.newText(score, 200, 0, nil, 50)
scoreNumber.xScale = 1.2
scoreNumber.yScale = 1.2
local function updateScore()
score = score + 1
scoreNumber.text = score
end
timer.performWithDelay(100, updateScore, -1)
local scoreText = display.newText("score:", 0, 0, nil, 50)
scoreText.xScale = 1.2
scoreText.yScale = 1.2
end
You know when to stop the score, so
score = 0
local scoreTimer
local scoreNumber = display.newText(score, 200, 0, nil, 50)
scoreNumber.xScale = 1.2
scoreNumber.yScale = 1.2
local function updateScore()
score = score + 1
scoreNumber.text = score
end
scoreTimer = timer.performWithDelay(100, updateScore, -1)
local scoreText = display.newText("score:", 0, 0, nil, 50)
scoreText.xScale = 1.2
scoreText.yScale = 1.2
end
so once the game is over cancel the timer using timer.cancel(scoreTimer). To save your score use check it here ,