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...