Press the return key to return to the menu page.

Source: Internet
Author: User
Tags what interface

After studying for half a day, I found that I had to press the return key to exit, no matter what interface you are on (that is, the scenario ). If you think about it, it is actually an interface, and the scenario is added by yourself. Therefore, when you press the return key, it means you press the return key on the initial interface and then exit. Therefore, we only need to perform the return key operation.

After a review, we found that CCDirector. shareddire(). runningScene has this, so we can obtain the current running scenario. This is enough.

First, your game page must be a class that inherits CCScene. If it is a layer, it will be difficult to operate. It does not matter if the menu page is a layer.

Then find the Update function in Game1.cs. You can see the operation for processing the return key.

The idea is to first determine whether it is a game interface. If it is a game scenario, switch to the menu scenario. Otherwise, exit.

The Code is as follows:

 

if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)            {                CCScene pScene = CCDirector.sharedDirector().runningScene;                //Debug.WriteLine(pScene.GetType().ToString());                if (pScene.GetType().ToString() == "cocos2dPeopleRun.Classes.RunScene")                {                    CCScene mainScene = cocos2dPeopleRunScene.scene();                    CCDirector.sharedDirector().replaceScene(mainScene);                }                else                    this.Exit();            }

 


In this way, you can press the return key in the game to exit the menu page... It's almost a curve to save the country...

 

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.