Book Image

Cocos2d Game Development Blueprints

By : Jorge Jordán
Book Image

Cocos2d Game Development Blueprints

By: Jorge Jordán

Overview of this book

Table of Contents (15 chapters)
Cocos2d Game Development Blueprints
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Adding a menu to the game


Usually, games show an initial menu where players can, for instance, access the configuration screen or choose to start the game, so in this section, we are going to develop an initial menu where the user will be able to select the difficulty level of the game.

We're going to create a separate scene class for this purpose, so follow these steps:

  1. Right-click on the Classes group in the project navigator and select New File….

  2. Click on iOS | cocos2d v3.x | CCNode class and make this class a subclass of CCScene.

  3. Call it MenuScene and click on Create.

In MenuScene.h, add the following imports:

#import "cocos2d-ui.h"
#import "GameScene.h"

The first import corresponds to the library that contains the buttons class, and the second one is needed as we will use it to initialize the game scene from the menu.

So, we now add the following constant definition:

#define kGameDifficulty @"Game_Difficulty"

We will take advantage of this constant to store the difficulty level selected by the...