Game Development Reference
In-Depth Information
Figure 11-1. User Playing Other Audio from the Background Menu
In Figure 11-1 , the user has double-clicked the Home button and is about to press Play and listen
to the Beastie Boys. What you can't see in this picture is that the audio of the game stopped as
soon as the Background menu opened. The game also paused. Additionally, after the user hits Play
and returns to the game, the game will resume, but no more sound will be produced by the game.
The ON/OFF switch controls whether or not nonbackground sound effects will be played over the
Beastie Boys, but more on that later.
To understand how the application responds to the Background menu's opening and closing, look at
the code in Listing 11-3.
Listing 11-3. UIApplicationDelegate Tasks from AppDelegate.m
- (void)applicationWillResignActive:(UIApplication *)application
{
[self.viewController applicationWillResignActive];
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
[self.viewController applicationDidBecomeActive];
}
In Listing 11-3, we see the tasks applicationWillResignActive and applicationDidBecomeActive
of the class AppDelegate . These are called whenever the application resigns being active or just
becomes active. We simply call a corresponding method on our GameController —in this case,
referenced by this.viewController . Listing 11-4 shows how our GameController responds to
these events.
Listing 11-4. applicationWillResignActive and applicationDidBecomeActive (GameController.m)
-(void)applicationWillResignActive{
[self setIsPaused:YES];
[backgroundPlayer pause];
Search WWH ::




Custom Search