Game Development Reference
In-Depth Information
Listing 12-2. RootViewController.m (extrasButtonClicked: and playButtonClicked:)
- (IBAction)extrasButtonClicked:(id)sender {
[self pushViewController:extrasController animated:YES];
}
- (IBAction)playButtonClicked:(id)sender {
[self pushViewController:beltCommanderController animated:YES];
[beltCommanderController doNewGame: [extrasController gameParams]];
}
In Listing 12-2, we see two tasks responsible for handling a button click. The task
extrasButtonClicked : is called when the user presses the Extras button on the Start view. This task
simply uses task pushViewController:animated: , as defined by UINavigationController , to present
extrasController . Similarly, the task playButtonClicked : uses the same
beltCommandController , as well as calls doNewGame: on
. Listing 12-3 shows how we navigate back to the Start view.
RootViewController.m (backFromExtras:)
- (IBAction)backFromExtras:(id)sender {
[self popViewControllerAnimated:YES];
backFromExtras: that is called when the user clicks the Back button
popViewControllerAnimated: to
remove the Extras view showing the Start view. The task popViewControllerAnimated: is defined by
UINavigationController , of which RootViewController is a subclass.
There is one last piece of code that handles navigation, and that is the code that responds to the two
dialogs that appear on the game view, as shown in Listing 12-4.
Listing 12-4. RootViewController.m (alertView:clickedButtonIndex:)
- (void)alertView:(UIAlertView *)alertView
clickedButtonAtIndex:(NSInteger)buttonIndex{
if (alertView == pauseGameAlerTView){
if (buttonIndex == 0) {
[self endOfGameCleanup];
[self popViewControllerAnimated:YES];
} else {
[beltCommanderController setIsPaused:NO];
}
}
if (alertView == newGameAlertView){
if (buttonIndex == 0) {
[beltCommanderController doNewGame: [extrasController gameParams]];
} else {
[self popViewControllerAnimated:YES];
}
}
}
Search WWH ::




Custom Search