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?
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++]];
}