0

I'm trying to create a score using a CCLabelTTF to show the score on the screen. But I would display the score scrolling numbers until they arrive at the final score. I make this in update method :

    if(currentScore < finalScore)
    {
    currentScore ++;
    [labelScore setString:[NSString stringWithFormat:@"%d", currentScore]];
     }

This is perfect when I have small scores but when I have a big number like 10.000 I have to wait a lot for seeing the final score. How can I solve this?

swifferina
  • 293
  • 4
  • 16
  • Do *not* use a CCLabelTTF for strings that change often. Every time the string changes a new texture is created, a font rendered onto it, and then the texture is bound to OpenGL. This is a **slow** operation. You should rather be using a CCLabelBMFont, use bmGlyph or Glyph Designer to create bitmap fonts. – CodeSmile Sep 13 '14 at 07:51

1 Answers1

0

Updating the score label in the update method means that your label will be updated 60 times per second which might be a little slow for large increments. There are two ways to solve this problem , either increase the increment value , i.e. increment by more than 1 for larger numbers or schedule a selector with an interval calculated on the basis of the increment required or both. Decide on a duration for which you would like the score label to update and then schedule a selector with an appropriate interval to make the user wait for the same amount of time irrespective of the score increment. For example:-

float waitDuration = 2.0f;
float increment = finalScore - currentScore;
float interval  = 2/increment;
[self schedule:@selector(updateScoreLabel) interval:interval repeat:increment delay:0];

where,

-(void) updateScoreLabel{
     [labelScore setString:[NSString stringWithFormat:@"%d", currentScore++]];
}
Abhineet Prasad
  • 1,271
  • 2
  • 11
  • 14