Game Development Reference
In-Depth Information
Bitmap fonts in Cocos2d-x
The Cocos2d-x Label class has a static create method that uses bitmap images for the
characters.
The bitmap image we are using here was created with the program GlyphDesigner, and in
essence, it works just as a sprite sheet does. As a matter of fact, Label extends
SpriteBatchNode , so it behaves just like a batch node.
You have images for all individual characters you'll need packed inside a PNG file
( font.png ), and then a data file ( font.fnt ) describing where each character is. The
following screenshot shows how the font sprite sheet looks like for our game:
The difference between Label and a regular SpriteBatchNode class is that the data
file also feeds the Label object information on how to write with this font. In other words,
how to space out the characters and lines correctly.
The Label objects we are using in the game are instantiated with the name of the data file
and their initial string value:
_scoreDisplay = Label::createWithBMFont("font.fnt", "0");
And the value for the label is changed through the setString method:
_scoreDisplay->setString("1000");
Search WWH ::




Custom Search