So on my current game, I want to display the highscore on the gameover scene, which is easy to do.
However I cannot work out how to get the highscore display to count up from 0 to the highscore achieved in the prior scene. An example of this would be at the end of an Angry Birds level, the score counts up.
I have tried a while loop but it is too quick between iterations and just displays the highscore instantly. Is there anyway to delay this?
Here is what I’ve tried so far:
[lua]-- works too fast and doesnt show count up animation
highScore = 500
countStart = 0
while countStart ~= highScore do
countStart = countStart + 1
highScoreText.text = countStart
end[/lua]
[lua]-- gets stuck in while loop and doesn’t call function
highScore = 500
countStart = 0
function countupScores()
local function countStuff()
countStart = countStart + 1
highScoreText.text = countStart
end
while countStart ~= highScore do
timer.performWithDelay(50, countStuff)
end
end[/lua]
Edit: Managed to fix it
[lua]rightAnswers = 100
rightAnswers2 = 0
local rightText = display.newText( "Total Score: "…rightAnswers2, 25, 50, native.systemFontBold, 20 )
rightText:setTextColor( 255, 255, 255 )
function countupScores(event)
if rightAnswers2 < rightAnswers then
rightAnswers2 = rightAnswers2 + 1
rightText.text = "Total Score: "…rightAnswers2
else
timer.cancel(event.source)
end
end
timer.performWithDelay(100, countupScores, 0)[/lua] [import]uid: 62706 topic_id: 33093 reply_id: 333093[/import]