Game Development Reference
In-Depth Information
IBOutlet ExtrasController *extrasController;
IBOutlet UIButton *leaderBoardButton;
IBOutlet UIButton *tweetButton;
IBOutlet UIButton *facebookButton;
UIAlertView* newGameAlertView;
UIAlertView* pauseGameAlerTView;
GKLocalPlayer* localPlayer;
ACAccountStore* accountStore;
ACAccount* facebookAccount;
BOOL isPlaying;
}
-(void)doPause;
-(void)endOfGameCleanup;
-(void)initGameCenter;
-(void)initFacebook;
-(void)initTwitter;
-(void)notifyGameCenter;
-(void)notifyFacebook;
-(BOOL)handleOpenURL:(NSURL *)url;
-(void)applicationWillResignActive;
-(void)applicationDidBecomeActive;
@end
In Listing 12-1, we see the header for the class
RootViewController
. The class
RootViewController
is responsible for managing the application state that does not involve the actual playing of the
game. This includes transitioning from view to view, handling the application startup, and managing
the social services from Chapter 9. As we can see in Listing 12-1, we have
IBOutlets
for the three
UIViewControllers
:
welcomeController
,
beltCommanderController
, and
extrasController
.
Listing 12-1 also shows that the class
RootViewController
has
IBOutlets
for two buttons:
leaderBoardButton
and
tweetButton
. A reference to these objects is required, as they will be enabled
or disabled at runtime. The
GKLocalPlayer
is used to manage Game Center and the
ACAccountStore
and
ACAccount
objects are used to manage interactions with Facebook. Let's take a look at how we
handle the navigation across views.
View Navigation
In order to change views when a user clicks a button, we have created a number of
IBAction
tasks
in the implementation of
RootViewController
and are wired up in the XIB file to the corresponding
buttons. Listing 12-2 shows two of these
IBAction
tasks.