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

Transitioning between scenes


Your games have to transition between scenes. For example, after launching your games, the title scene is displayed. Then, it is transitioned into the level selection scene, game scene, and so on. In this recipe, we will explain how to facilitate transition between scenes, which would improve the gameplay and the flow of the game.

How to do it...

A game has a lot of scenes. So, you might need to move between scenes in your game. Perhaps, when a game is started, a title scene will be displayed. Then, a game scene will appear in the next title scene. There are two ways to transition to a scene.

  1. One is to use the Director::replaceScene method. This method replaces a scene outright.

    auto scene = HelloWorld::createScene();
    Director::getInstance()->replaceScene(scene);
  2. The other is to use the Director::pushScene method. This method suspends the execution of the running scene and pushes a new scene on the stack of the suspended scene.

    auto scene = HelloWorld::createScene...