Transitioning scenes with effects
Popular games display some effects when transitioning scenes. These effects can be natural, dramatic, and so on. Cocos2d-x has a lot of transitioning effects. In this recipe, we will explain how to use a transitioning effect and the effect produced.
How to do it...
You can add visual effects to a scene transition by using the Transition
class. Cocos2d-x has many kinds of Transition
classes. However, there is only one pattern for how to use them.
auto nextScene = HelloWorld::createScene(); auto transition = TransitionFade::create(1.0f, nextScene); Director::getInstance()->replaceScene(transition);
It can be used when a scene was pushed.
auto nextScene = HelloWorld::createScene(); auto transition = TransitionFade::create(1.0f, nextScene); Director::getInstance()->pushScene(transition);
How it works...
Firstly, you need to create the nextscene
object. Then, you need to create a transition
object with a set duration and an incoming scene object. Lastly, you...