Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm adding to the player's score, and I'm using a per-frame formula like:

int score, displayedScore ;// score is ACTUAL score player has,
// displayedScore is what is shown this frame to the player
// (the creeping/"rolling" number)

float disparity = score - displayedScore ;
int d = disparity * .1f ; // add 1/10 of the difference,
if( !d )  d = signum( disparity ) ; // last 10 go by 1's
score += d ;


inline int signum( float val ){
  if( val > 0 )  return 1 ;
  else if( val < 0 )  return -1 ;
  else return 0 ;

So, it kind of works where it makes big changes rapidly, then it creeps in the last few one at a time.

But I'm looking for better (or possibly well known?) score-creeping functions. Any one?

share|improve this question

Tweens work great for this, and any tween library would have what you need.

The function below is what I've used before in a couple of games. It scrolls very quickly at first and then slows down a bit near the end, reminiscent of slot machines.

void addToScore( float val ) {
    score += val;

    //  Stop the current tween, in case one is still running.

    //  Tween displayedScore to the value of score over the period
    //  of one second with a cubic easing function.
    TweenLib.tween( displayedScore, score, 1.0, Cubic.EaseOut);
share|improve this answer
You'll pardon me if I'm hesitant to Google 'Tweens'... – Amadeus9 Oct 23 '13 at 19:32

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.