示例#1
0
        /// <summary>
        /// Update stuff here
        /// </summary>
        /// <param name="gameTime"></param>
        protected override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            var ds = GetService <DebugStrings>();

            ds.Add(Color.Orange, "FPS {0}", gameTime.Fps);
            ds.Add("F1   - show developer console");
            ds.Add("F2   - toggle vsync");
            ds.Add("F5   - build content and reload textures");
            ds.Add("F12  - make screenshot");
            ds.Add("ESC  - exit");
            ds.Add("");

            if (IsActive)
            {
                ds.Add(Color.LightGreen, "Active");
            }
            else
            {
                ds.Add(Color.Red, "Not active");
            }

            ds.Add(Color.Orange, "");

            ds.Add(Color.Orange, "Keyboard");

            foreach (Keys key in (Keys[])Enum.GetValues(typeof(Keys)))
            {
                if (InputDevice.IsKeyDown(key))
                {
                    ds.Add(" - {0}", key.ToString());
                }
            }

            ds.Add("");
            ds.Add(Color.Orange, "Mouse");

            ds.Add(" - position (absolute): {0} {1}", InputDevice.GlobalMouseOffset.X, InputDevice.GlobalMouseOffset.Y);
            ds.Add(" - position (relative): {0} {1}", InputDevice.RelativeMouseOffset.X, InputDevice.RelativeMouseOffset.Y);
            ds.Add(" - total scroll value : {0}", scrollValue);

            ds.Add("");
            ds.Add(Color.Orange, "Gamepad");

            for (int playerIndex = 0; playerIndex <= 3; playerIndex++)
            {
                var gp = InputDevice.GetGamepad(playerIndex);

                if (gp.IsConnected)
                {
                    ds.Add(Color.LightGreen, "Gamepad #{0} is connected", playerIndex);

                    ds.Add(" - Left stick    : {0} {1}", gp.LeftStick.X, gp.LeftStick.Y);
                    ds.Add(" - Right stick   : {0} {1}", gp.RightStick.X, gp.RightStick.Y);
                    ds.Add(" - Left trigger  : {0} (left motor)", gp.LeftTrigger);
                    ds.Add(" - Right trigger : {0} (right motor)", gp.RightTrigger);

                    gp.SetVibration(gp.LeftTrigger, gp.RightTrigger);

                    if (gp.IsKeyPressed(GamepadButtons.X))
                    {
                        ds.Add(Color.Blue, "[X]");
                    }
                    if (gp.IsKeyPressed(GamepadButtons.Y))
                    {
                        ds.Add(Color.Yellow, "[Y]");
                    }
                    if (gp.IsKeyPressed(GamepadButtons.A))
                    {
                        ds.Add(Color.Green, "[A]");
                    }
                    if (gp.IsKeyPressed(GamepadButtons.B))
                    {
                        ds.Add(Color.Red, "[B]");
                    }

                    if (gp.IsKeyPressed(GamepadButtons.LeftShoulder))
                    {
                        ds.Add("[LS]");
                    }
                    if (gp.IsKeyPressed(GamepadButtons.RightShoulder))
                    {
                        ds.Add("[RS]");
                    }
                    if (gp.IsKeyPressed(GamepadButtons.LeftThumb))
                    {
                        ds.Add("[LT]");
                    }
                    if (gp.IsKeyPressed(GamepadButtons.RightThumb))
                    {
                        ds.Add("[RT]");
                    }

                    if (gp.IsKeyPressed(GamepadButtons.Back))
                    {
                        ds.Add("[Back]");
                    }
                    if (gp.IsKeyPressed(GamepadButtons.Start))
                    {
                        ds.Add("[Start]");
                    }

                    if (gp.IsKeyPressed(GamepadButtons.DPadLeft))
                    {
                        ds.Add("[Left]");
                    }
                    if (gp.IsKeyPressed(GamepadButtons.DPadRight))
                    {
                        ds.Add("[Right]");
                    }
                    if (gp.IsKeyPressed(GamepadButtons.DPadDown))
                    {
                        ds.Add("[Down]");
                    }
                    if (gp.IsKeyPressed(GamepadButtons.DPadUp))
                    {
                        ds.Add("[Up]");
                    }
                }
                else
                {
                    ds.Add(Color.Red, "Gamepad #{0} is diconnected", playerIndex);
                }
            }
        }