Game Development Reference
In-Depth Information
But keep in mind that CCLabelTTF is slow only when changing its string frequently.
If you create the CCLabelTTF once when the scene begins and never or rarely change
it, it's just as fast as any other CCSprite of the same dimensions.
You should also update the resetGame method so that it resets the score and
scoreLabel variables:
-(void) resetGame
{
[self resetSpiders];
score = 0;
[scoreLabel setString:@"0"];
}
To frequently change the label for testing, you can add the following line to the up-
date method. It simply prints the number of total frames rendered so far:
score = [CCDirector sharedDirector].totalFrames;
[scoreLabel setString:[NSString stringWithFormat:@"%i", score]];
Introducing CCLabelBMFont
Labels that update fast at the expense of more memory usage, like any other CCS-
prite , are the specialty of the CCLabelBMFont class. I've replaced the CCLa-
belTTF with a CCLabelBMFont in DoodleDrop04. The code change is relatively
straightforward; you have to change the line in the init method, as shown here:
scoreLabel = [CCLabelBMFont labelWithString:@"0" fntFile:@"bitmapfont.fnt"];
Note Bitmap fonts are a great choice for games because they're fast, but
they do have one disadvantage: the size of any bitmap font is fixed. If you need
the same font but larger or smaller in size, you can scale the CCLa-
Search Nedrilad ::




Custom Search