Game Development Reference
In-Depth Information
Listing 6-16
.
The GameMenuLayer class receives applicationWillResignActive: and runs
shouldPauseGame
-(void) applicationWillResignActive:(UIApplication
*)application
{
[self shouldPauseGame];
}
If you build and run the app now, press the Home button once the game is running to close
the app. Actually, the app won't close—it will be sent to the background for an indefinite
time.
Then tap the app's icon again to relaunch the app. You should see that the app continues
from where you closed it, but the game is paused and the pause popover menu is shown.
Killing the Player
The Game Over state can be handled just like pause with a popover menu, with nearly the
same functionality, allowing the player either to restart the level or to exit the current
game session.
And, of course, the player needs to die! And what better way to kill the player than by sli-
cing it up with a circular saw?
Creating a “Game Over” Popover
In SpriteBuilder, right-click the
Popovers
folder and add a
New File
. Name the new docu-
ment
GameOverMenuLayer.ccb
, set its type to
Layer
, and then click
Create
. Editing the
Game over
menu follows the same basic principle as the pause menu, so I will only note
the differences here.
For instance, the predesigned graphics for the
Game over
menu all start with a
G_
, though
you are free to use other images. And there should be no resume button, only exit and re-
start buttons. Since there's no resume function, you needn't add the
resume game
Timeline either. And the label's text shouldn't read
Game Paused
, but rather
Game Over
.
Be sure to set the
Custom class
of the
GameOverMenuLayer.ccb
root node to
GameMenuLayer
; otherwise, none of the buttons will work. Likewise, the exit and re-
Search WWH ::
Custom Search