Cocos2d-x Study notes (ix) scene switching

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.