Tip) implement popScene with Transition

ahlwong, I think your solution is great! You just need to add ); after the lambda expressions when calling.

Here are some preprocessor macros that I’ve found useful in simplifying program readability:

#define TO_SCENE(scene, transition, duration)
Director::getInstance()->replaceScene(transition::create(duration,scene::createScene()))

#define PUSH_SCENE(scene, transition, duration)
Director::getInstance()->pushScene(transition::create(duration,scene::createScene()))

#define POP_SCENE(transition, duration)
Director::getInstance()->popScene([](Scene* scene){return transition::create(duration,scene);})

Hi!

Here is a non-intrusive adapter class I’ve crafted that allows one to pop scene with transition without having to change any of the cocos2d sources: http://bit.ly/cocos-pop-transition-hpp

Instead of calling cocos2d::Director::getInstance()->popScene() just call:

cocos2d::Director::getInstance()->pushScene(
     pop_scene_with<cocos2d::TransitionFlipX>::create(1.0f, cocos2d::TransitionScene::Orientation::LEFT_OVER)
);

Note that there is no typical 2nd argument taking the scene for the transition, one simply passes all the arguments they would pass to the transition’s create method except for the 2nd argument carrying the scene.

2 Likes