Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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 ;

Where

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

1 Answer 1

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.
    TweenLib.stop();

    //  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
1  
You'll pardon me if I'm hesitant to Google 'Tweens'... –  Amadeus9 Oct 23 '13 at 19:32

Your Answer

 
discard

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.