Book Image

Learning iPhone Game Development with Cocos2D 3.0

By : Kirill Muzykov
Book Image

Learning iPhone Game Development with Cocos2D 3.0

By: Kirill Muzykov

Overview of this book

Table of Contents (19 chapters)
Learning iPhone Game Development with Cocos2D 3.0
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – restarting and exiting the game


There are still two buttons in the pause dialog that currently simply output to the console instead of actually doing something. Let's add the code for the Exit and Restart buttons. In addition, we are going to create a LoadingScene class, which will help us to avoid memory errors and will use UIAlertView to confirm the exit from the game.

Looks like a lot of work, so let's start:

  1. Open the Xcode project and create a new scene named LoadingScene in the Scenes group.

  2. Then, open the PauseDialog.m file and import the LoadingScene.h and MenuScene.h headers:

    #import "LoadingScene.h"
    #import "MenuScene.h"
  3. Find the btnRestartTapped: method and replace its contents with the following code:

    -(void)btnRestartTapped:(id)sender
    {
        LoadingScene *loadingScene = [[LoadingScene alloc] init];
        CCTransition *transition = 
          [CCTransition transitionCrossFadeWithDuration:1.0f];
        
        [[CCDirector sharedDirector] replaceScene:loadingScene 
                ...