• cocos2dxna 游戏中如何控制后退键实现目的性跳转


    在实际情况中,我们有时候需要根据不同的游戏场景来决定wp的后退“场景”。

    所以,我们可以先建一个常量类,里面放上一个常量,用来标记不同页面的代表值,

    例如:

    class GameMain
        {
            public static int CurrentScreen;
        }

    然后再在不同场景的类的构造函数给之赋值

    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());
            }
        }

    最后在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);
                }
            }

    完成。

  • 相关阅读:
    剑指offer(链表)
    设计模式
    谷歌Colab使用(深度学习)
    Consul与python API注册与注销
    【日志收集】之Loki
    【消息队列】之 RabbitMQ安装
    【消息队列】之NSQ安装
    Docker基础
    Python3 , Mysql5.7 , Smb 安装
    SkyWalking部署
  • 原文地址:https://www.cnblogs.com/dieaz5/p/2915631.html
Copyright © 2020-2023  润新知