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 – displaying stats when losing and winning


There are a few more dialogs that we need to add quickly. The first one is the dialog that is displayed when we win or lose the game. In this dialog, we will display the gathered statistics and again the same buttons to restart or exit the game. Otherwise, you cannot do anything when you win or lose.

  1. Open an Xcode project and create a new CCNode subclass called WinLoseDialog. It is better to place this too in the Scenes group in order to keep things more organized.

  2. Open the GameStats.h file and add the timeSpent property; we will use it to count the time that the player spent to beat or lose the level:

    @property (nonatomic, assign) float timeSpent;
  3. Open the GameStats.m file and initialize this property to 0 inside the init method:

    self.timeSpent = 0;
  4. Open the GameScene.m file and find the update: method. Add the following line, right after the line where we check that the game state is GameStatePlaying:

    -(void)update:(CCTime)dt
    {
        if...