How to control the back key in cocos2d-xna game to achieve Objective jump

Source: Internet
Author: User

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.

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.