Book Image

Cocos2d-x Cookbook

By : Akihiro Matsuura
Book Image

Cocos2d-x Cookbook

By: Akihiro Matsuura

Overview of this book

Table of Contents (18 chapters)
Cocos2d-x Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating scenes


In Cocos2d-x, your games should have one or more scenes. A scene is basically a node. In this recipe, we will explain how to create and use a Scene class.

How to do it...

In this recipe, we will use the project that was created in Chapter 1, Getting Started with Cocos2d-x.

  1. Firstly, duplicate the HelloWorldScene.cpp and HelloWorldScene.h files at Finder and rename them as TitleScene.cpp and TitleScene.h. Secondly, add them to the Xcode project. The result is shown in the following image:

  2. Next, we have to change HelloWorldScene to TitleScene and place the search and replace method in the tips section.

    Tip

    How to search for and replace a class name?

    In this case, select TitleScene.h and then the Find | Find and Replace … menu in Xcode. Then, enter HelloWorld in the String Matching area and TitleScene in the Replacement String area. Execute all replacements. Follow the same process for TitleScene.cpp. The result is the following code for TitleScene.h:

    The result obtained for TitleScene...