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.
One is to use the
Director::replaceScene
method. This method replaces a scene outright.auto scene = HelloWorld::createScene(); Director::getInstance()->replaceScene(scene);
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...