In actual situations, we sometimes need to determine the "scenario" of WP based on different game scenarios ".
Therefore, we can first create a constant class with a constant in it to mark the representative values of different pages,
For example:
class GameMain { public static int CurrentScreen; }
Then assign a value to the class constructor in different scenarios.
class ChooseScreen : CCScene { private static ChooseScreen _current; public static ChooseScreen Current { get { GameMain.CurrentScreen = 1; if (_current == null) { _current = new ChooseScreen(); } return _current; } } private ChooseScreen() { this.addChild(new ChooseLayer()); } }
Finally, rewrite the function in game1.cs.
protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { switch (GameMain.CurrentScreen) { case -1: case 0: this.Exit(); break; case 1: CCDirector.sharedDirector().replaceScene(MainMenuScreen.Current); break; case 2: string msg = "Quit Game?"; List<string> MBButtons = new List<string>(); MBButtons.Add("Yes"); MBButtons.Add("No"); Guide.BeginShowMessageBox("Game Over", msg, MBButtons, 0, MessageBoxIcon.Alert, GetMBResult, null); break; default: this.Exit(); break; } } base.Update(gameTime); }
void GetMBResult(IAsyncResult r)
{
int? b = Guide.EndShowMessageBox(r);
if (b == 0)
{
CCDirector.sharedDirector().replaceScene(ChooseScreen.Current);
}
}
Complete.