Game Development Reference
In-Depth Information
+(GameState*) sharedGameState
{
static GameState* sharedInstance;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[GameState alloc] init];
OALSimpleAudio audio = [OALSimpleAudio
sharedInstance];
audio.effectsVolume = sharedInstance.effectsVolume;
audio.bgVolume = sharedInstance.musicVolume;
});
return sharedInstance;
}
This sets the volumes of OALSimpleAudio to the volumes restored from the
GameState sharedInstance , which ensures the volumes are loaded from
NSUserDefaults the first time the class GameState is used. This is guaranteed to
happen very early in the game, but it could be forced by adding a seemingly nonsensical
line like the following:
[GameState sharedGameState];
This would just initialize the singleton (if it isn't already), discarding the returned in-
stance.
Working with Labels
Thus far, I haven't provided a thorough introduction to label-specific properties. And I
haven't mentioned the fact that you can localize them or explained why there are two
types of labels: TTF (TrueType font) and BM-Font (bitmap font).
Importing a Custom TrueType Font
In principle, adding a custom TrueType font to SpriteBuilder is as simple as dragging and
dropping it onto the project. In the topic's Graphics archive, you'll find a Fonts folder that
you should drag and drop onto SpriteBuilder's File View . Alternatively, create a Fonts
folder and drag and drop a custom .ttf file into it. You can easily find TrueType fonts on
Search WWH ::




Custom Search