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?


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);
  • 1
    \$\begingroup\$ You'll pardon me if I'm hesitant to Google 'Tweens'... \$\endgroup\$
    – Tin Wizard
    Oct 23 '13 at 19:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .