Game Development Reference
In-Depth Information
the web—just be careful that the font is distributed under a permissive license or is in the
public domain.
You can then select the font on the Item Properties tab of a Label TTF node. Click on the
Font name drop-down list in the CCLabelTTF section, select the User Fonts section, and
browse into the Fonts folder. The System Fonts are the fonts that are built into iOS and al-
ways available.
In practice, there are several hurdles that may prevent you from using the custom
TrueType font. First of all, it needs to be a valid file. Double-clicking the .ttf file in Finder
should open the Font Book app, displaying an alphabet of glyphs. If that doesn't happen
or you get an error, the font is most likely corrupt or not in the correct format.
Next you have to consider that the font name does not necessarily refer to the font's file
name. There are three names for a font: its file name, its family name, and its font name.
For use in SpriteBuilder, the font name and file name (excluding the file extension) should
match; otherwise, the font will not work.
Once you have added a TrueType font to SpriteBuilder, publish and add the code fragment
in Listing 11-15 to any method that runs when the app launches—for instance, the
didLoadFromCCB method in MainScene.m .
Listing 11-15 . Logging a font family and names
for (NSString* family in [UIFont familyNames])
{
NSLog(@"%@ (family)”, family);
for (NSString* name in [UIFont
fontNamesForFamilyName:family])
{
NSLog(@"
%@ (name)“, name);
}
}
Check the Debug Console in Xcode. If you added the PARPG.ttf font file from the Graph-
ics archive, the log will print something like this amidst many other fonts:
2014-09-09 16:36:25.433 LearnSpriteBuilder[91808:60b] Fixed
(family)
2014-09-09 16:36:25.434
LearnSpriteBuilder[91808:60b]
PARPG (name)
Search WWH ::




Custom Search