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.
- Firstly, duplicate the
HelloWorldScene.cpp
andHelloWorldScene.h
files atFinder
and rename them asTitleScene.cpp
andTitleScene.h
. Secondly, add them to the Xcode project. The result is shown in the following image: - Next, we have to change
HelloWorldScene
toTitleScene
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, enterHelloWorld
in the String Matching area andTitleScene
in the Replacement String area. Execute all replacements. Follow the same process forTitleScene.cpp
. The result is the following code forTitleScene.h
:The result obtained for...