[Solved] How do I build an animated counter that adds hundreds or thousands of points to a score display?

Hello,

My game has rounds that accumulate points. After each round, I'd like to add the new points to the beginning score in an animated fashion much like a pinball table adds points as the ball strikes things.

I want the numbers to count up (or down) kind of in a blurr and then end on the final score.

I first just used performWithDelay and set the iteration value to the number of points to add or subtract.

1
2
3
4
5
6
7
local function incrementScore ( event )
        totalScore = totalScore + sessionScore
        totalScoreValue.text = totalScore
end
 
 
timer.performWithDelay(20, incrementScore, sessionScore )

try using

1
totalScore = totalScore + math.round(sessionScore/100)

When you add 100's and 1000's do you want the player to see the score being added or just provide an illusion of a counter?

You can create a blurry animation of a counter moving from 0 to 9 and back, then play that animation for a period of time that is proportional to the magnitude of your score, it will give the effect of the counter being moved, where you will have each digit at a different speed to match up with the rolling.

otherwise, the same above is fine, as it will show the score increasing.

cheers,

?:)

Thanks for the replies.

The use of math.round doesn't work for me (and I wouldn't think it would anyway). Rounding the values loses data of course. In the above example, the final result I get is 3000, not 3009 as it should be.

The animation it provides is fine but the final result is non-deterministic.

Tom

Solved this one well enough I think.

Basically, I keep track of how many times my increment counter is called and on the last call by performWithDelay, I set the final score, overriding any rounding errors from math.round

1
2
3
4
5
6
7
8
        local function incrementScore ( event )
                totalScore = totalScore + math.round(sessionScore/100)
                totalScoreValue.text = totalScore
                animateScoreCounter = animateScoreCounter + 1
                if animateScoreCounter == 100 then
                        setFinalScore()
                end
        end
views:1489 update:2011/10/11 8:57:46
corona forums © 2003-2011