Game Development Reference
In-Depth Information
But the usual premature-optimization caveat applies: if you don't experience any perform-
ance or memory issues, choose whatever type of font works well enough to do the job.
Creating and Importing a Bitmap Font
To create a bitmap font, you'll typically use a tool made for the job. The most popular
tools on OS X are Glyph Designer and bmGlyph, which cost in the range of $10 to $30.
Both tools can export the format supported by Cocos2D, which is an .fnt file alongside a
.png file of the same name. If your tool allows you to choose the encoding for the .fnt file,
choose text and not XML.
The .fnt format is a plain-text format; you can open it with any text editor. Unfortunately,
the extension .fnt is used by a number of different formats. To verify that an .fnt file you
created or downloaded is in the correct format, the first couple lines should look very sim-
ilar to the ones in Listing 11-16 . If your file looks very different from this, it's probably
not in a format that Cocos2D understands. You may need to re-export the file or use a dif-
ferent glyph tool.
Listing 11-16 . An excerpt of an .fnt file when viewed in a text editor (indentation is not
representative)
info face="Fixed" size=64 bold=0 italic=0 charset=""
unicode=0
stretchH=100 smooth=1 aa=1 spacing=2,2
common lineHeight=84 base=82 scaleW=1024 scaleH=512 pages=1
packed=0
page id=0 file="gd.png"
chars count=95
char id=32 x=424 y=277 width=0 height=0 xoffset=0 yoffset=80
xadvance=38 page=0 chnl=0 letter="space"
char id=33 x=268 y=214 width=21 height=58 xoffset=26
yoffset=11
xadvance=46 page=0 chnl=0 letter="!"
...
While all tools can export in the .fnt format that Cocos2D understands, SpriteBuilder has
additional requirements that some glyph tools may not adhere to. SpriteBuilder requires
Search WWH ::




Custom Search