Here are just two simple two ways to switch between scenes.
void Pushscene (Scene *sn) and void Popscene (scene *sn) are a pair. The former puts the current scene into the scene stack and switches to the next scene, while the latter is the scene that goes back to the top of the stack (typically the previous scene). Also, the prototype of the stack here is vector<scene*>. Usually, they are triggered by an event callback.
The code below is to press the current scene into the stack and automatically switch to the next scene (in fact, a new scene is created in the return function ^_^):
Menuitemimage *settingmenuitem = menuitemimage::create ("menu/setting-up.png"" Menu/setting-down.png " this));
void Helloworld::menuitemsettingcallback (REF *psender) { = setting::createscene (); Director::getinstance (),Pushscene (SC);}
The code below is the top of the stack scene outbound, and the top of the stack to restore the scene:
Auto Okmenuitem = menuitemimage::create ("menu2/ok-down.png""menu2/ Ok-up.png"This)");
void Setting::menuokcallback (REF *psender) { director::getinstance ()popscene ();}
Operation Result:
Figure 1 HelloWorld Scene
Figure 2 Setting scene
Click on the button shown in the red arrow to switch back and forth between the two scenes.
Looking back at the code, we'll find that we've been just subclasses of layers, not subclasses of the scene classes. This is mainly because the life cycle of the scene is reflected through the life cycle of the layer. Understanding this is an understanding of the relationship between layers and scenes.
Cocos2d-x Study notes (ix) scene switching