コード例 #1
0
        private static void AssertButtons(IEnumerable <Buttons> pressedButtons, GamePadState state)
        {
            Buttons joinedButtons = 0;

            foreach (var button in pressedButtons)
            {
                joinedButtons |= button;
            }

#if !XNA
            var gamePadButtons = state.Buttons;
            Assert.AreEqual(joinedButtons, gamePadButtons._buttons);
#endif

            // all buttons except for thumbstick position buttons and triggers (they're not controlled via buttons here)
            var allButtons = Enum.GetValues(typeof(Buttons)).OfType <Buttons>()
                             .Where(b => !Regex.IsMatch(Enum.GetName(typeof(Buttons), b), "(Thumbstick|Trigger)"));

            foreach (var button in allButtons)
            {
                if (pressedButtons.Contains(button))
                {
                    Assert.IsTrue(state.IsButtonDown(button));
                    Assert.IsFalse(state.IsButtonUp(button));
                }
                else
                {
                    Assert.IsTrue(state.IsButtonUp(button));
                    Assert.IsFalse(state.IsButtonDown(button));
                }
            }
        }
コード例 #2
0
ファイル: GamepadController.cs プロジェクト: Grutn/TDT4240-X2
        private void UpdateTimer(Keys key, Buttons button, float directionX, float directionY, float elapsedTime, ButtonDown downAction, ButtonUp upAction, ButtonPressed pressAction, ref float downTimer, ref float upTimer)
        {
            if (IsKeyDown(key) || currentGamePadState.IsButtonDown(button))
            {
                if (downAction != null && downTimer == 0)
                {
                    downAction.Invoke(directionX, directionY, upTimer, PlayerIndex);
                }

                downTimer += elapsedTime;
                upTimer    = 0;
            }
            else if (IsKeyUp(key) || currentGamePadState.IsButtonUp(button))
            {
                //Check if it was a press of key
                if (this.oldKeyboardState.IsKeyDown(key) || oldGamePadState.IsButtonDown(button))
                {
                    if (pressAction != null)
                    {
                        pressAction.Invoke(PlayerIndex);
                    }

                    if (upAction != null)
                    {
                        upAction.Invoke(downTimer, PlayerIndex);
                    }
                }
                upTimer  += elapsedTime;
                downTimer = 0;
            }
        }
コード例 #3
0
        public void Update()
        {
            gamePadState = GamePad.GetState(PlayerIndex.One);
            bool foundInput = false;

            if (gamePadState.IsButtonDown(Buttons.Start) && !startPressed)
            {
                startPressed = true;
                new StartButtonCommand().Execute();
            }
            else if (gamePadState.IsButtonUp(Buttons.Start) && startPressed)
            {
                startPressed = false;
            }

            if (playableObject.IsEnteringPipe || playableObject.IsExitingPipe)
            {
                new MarioNoInputCommand(playableObject).Execute();
            }
            else
            {
                if (gamePadState.IsButtonDown(Buttons.A) && !jumpPressed)
                {
                    jumpPressed = true;
                    new MarioJumpCommand(playableObject).Execute();
                    foundInput = true;
                }
                else if (gamePadState.IsButtonDown(Buttons.A))
                {
                    foundInput = true;
                }
                else if (gamePadState.IsButtonUp(Buttons.A) && jumpPressed)
                {
                    jumpPressed = false;
                }

                if (gamePadState.IsButtonDown(Buttons.B))
                {
                    playableObject.MaxHorizontalVelocity = GameValues.MarioRunningSpeed;
                    new MarioRunCommand(playableObject).Execute();
                }
                else
                {
                    playableObject.MaxHorizontalVelocity = GameValues.MarioWalkingSpeed;
                }

                foreach (KeyValuePair <Buttons, ICommand> item in buttonMap)
                {
                    if (gamePadState.IsButtonDown(item.Key))
                    {
                        item.Value.Execute();
                        foundInput = true;
                    }
                }
                if (!foundInput)
                {
                    new MarioNoInputCommand(playableObject).Execute();
                }
            }
        }
コード例 #4
0
 public bool isAnyFirstPress(Buttons b_)
 {
     return((gamePadCurrent1.IsButtonDown(b_) && gamePadPrevious1.IsButtonUp(b_)) ||
            (gamePadCurrent2.IsButtonDown(b_) && gamePadPrevious2.IsButtonUp(b_)) ||
            (gamePadCurrent3.IsButtonDown(b_) && gamePadPrevious3.IsButtonUp(b_)) ||
            (gamePadCurrent4.IsButtonDown(b_) && gamePadPrevious4.IsButtonUp(b_)));
 }
コード例 #5
0
        /// <summary>
        /// アップデートのタイミングにフレームワークから呼び出されます
        /// </summary>
        /// <param name="gameTime">ゲームタイム</param>
        protected override void Update(GameTime gameTime)
        {
            // インプットマネージャーのアップデート
            InputManager.Update();

            // 終了ボタンのチェック
            if (InputManager.IsJustKeyDown(Keys.Escape) || InputManager.IsJustButtonDown(PlayerIndex.One, Buttons.Back))
            {
                Exit();
            }

            // 入力を取得する
            UpdateInput(gameTime);

            mainComponent.cameraComponent.camera.Target = mainComponent.boneComponent.position;
            Console.WriteLine("position = " + mainComponent.boneComponent.position);

            // アニメーションの更新
            UpdateAnimation(gameTime, true, worldMatrix);

            oldGamePad = gamePad;
            gamePad    = GamePad.GetState(PlayerIndex.One);

            //デバッグ用(ボタンひとつでゴール)
            if (gamePad.IsButtonDown(Buttons.Start) && oldGamePad.IsButtonUp(Buttons.Start) && flg == true)
            {
                flg = false;
            }
            else if (gamePad.IsButtonDown(Buttons.Start) && oldGamePad.IsButtonUp(Buttons.Start) && flg == false)
            {
                flg = true;
            }

            base.Update(gameTime);
        }
コード例 #6
0
 public bool WasButtonReleased(Buttons button)
 {
     if (!IsConnected)
     {
         return(false);
     }
     return(lastGamePadState.IsButtonDown(button) && currentGamePadState.IsButtonUp(button));
 }
コード例 #7
0
 public bool ButtonPressed(Buttons button)
 {
     if (buttonState.IsButtonDown(button) && prevButtonState.IsButtonUp(button))
     {
         return(true);
     }
     return(false);
 }
コード例 #8
0
 public bool ButtonReleased(Buttons button)
 {
     if (padState.IsButtonUp(button) && prevPadState.IsButtonDown(button))
     {
         return(true);
     }
     return(false);
 }
コード例 #9
0
 /// <summary>
 /// Check if game pad A button pressed.
 /// </summary>
 /// <returns></returns>
 public bool GamePadAPressed()
 {
     if (lastPadState.IsButtonUp(Buttons.A) && currentPadState.IsButtonDown(Buttons.A))
     {
         return(true);
     }
     return(false);
 }
コード例 #10
0
        public bool FirstSkillReleased()
        {
            if (currentGamePadState.IsButtonUp(Buttons.RightShoulder) && previousGamePadState.IsButtonDown(Buttons.RightShoulder))
            {
                return(true);
            }

            return(false);
        }
コード例 #11
0
ファイル: PauseScreen.cs プロジェクト: fraxouille/DirtyTricks
        // Update & Draw
        public void Update(MouseState mouse, KeyboardState keyboard, GamePadState gamePadState)
        {
            if (keyboard.IsKeyUp(Keys.Escape) && gamePadState.Buttons.Start == ButtonState.Released)
            {
                exitPauseAllowed = true;
            }

            if ((keyboard.IsKeyDown(Keys.Escape) || gamePadState.Buttons.Start == ButtonState.Pressed) && exitPauseAllowed)
            {
                _selection       = 0;
                exitPauseAllowed = false;
                Game1.gameState  = GameState.Game;
            }

            for (int i = 0; i < _btnNumber; i++)
            {
                _buttons[i].Update(mouse, keyboard);
            }

            if (keyboard.IsKeyDown(Keys.Down) || gamePadState.IsButtonDown(Buttons.DPadDown))
            {
                DownButton();
            }
            if (keyboard.IsKeyUp(Keys.Down) && gamePadState.IsButtonUp(Buttons.DPadDown))
            {
                _currentDownState = false;
            }

            if (keyboard.IsKeyDown(Keys.Up) || gamePadState.IsButtonDown(Buttons.DPadUp))
            {
                UpButton();
            }
            if (keyboard.IsKeyUp(Keys.Up) && gamePadState.IsButtonUp(Buttons.DPadUp))
            {
                _currentUpState = false;
            }

            if ((keyboard.IsKeyDown(Keys.Enter) || gamePadState.Buttons.Start == ButtonState.Pressed || gamePadState.Buttons.A == ButtonState.Pressed) && exitPauseAllowed)
            {
                switch (_selection)
                {
                case 0:
                {
                    _selection       = 0;
                    exitPauseAllowed = false;
                    Game1.gameState  = GameState.Game;
                    break;
                }

                case 1:
                {
                    exitGame = true;
                    break;
                }
                }
            }
        }
コード例 #12
0
ファイル: Controls.cs プロジェクト: taichatha/Zombie-Run
 public bool onPress(Keys key, Buttons button)
 {
     if ((gp.IsButtonDown(button) && gpo.IsButtonUp(button)))
     {
         Console.WriteLine(button);
     }
     return((kb.IsKeyDown(key) && kbo.IsKeyUp(key)) ||
            (gp.IsButtonDown(button) && gpo.IsButtonUp(button)));
 }
コード例 #13
0
        public override void Update(GameTime gameTime)
        {
            if (Input.WasPressed(0, Buttons.Back, Keys.Escape))
            {
                GameManager.PopState();
            }

            if (Input.KeyboardState.WasKeyPressed(Keys.Up) ||
                (currentGamePadState.IsButtonDown(Buttons.DPadUp) &&
                 previousGamePadState.IsButtonUp(Buttons.DPadUp)) ||
                (currentGamePadState.ThumbSticks.Left.Y > 0 &&
                 previousGamePadState.ThumbSticks.Left.Y <= 0))
            {
                selected--;
            }
            if (Input.KeyboardState.WasKeyPressed(Keys.Down) ||
                (currentGamePadState.IsButtonDown(Buttons.DPadDown) &&
                 previousGamePadState.IsButtonUp(Buttons.DPadDown)) ||
                (currentGamePadState.ThumbSticks.Left.Y < 0 &&
                 previousGamePadState.ThumbSticks.Left.Y >= 0))
            {
                selected++;
            }
            if (selected < 0)
            {
                selected = 1;
            }
            if (selected == 2)
            {
                selected = 0;
            }

            if ((Input.WasPressed(0, Buttons.Start, Keys.Enter)) ||
                (Input.WasPressed(0, Buttons.A, Keys.Space)))
            {
                switch (selected)
                {
                case 0:     //Display Crosshairs
                {
                    OurGame.DisplayCrosshair = !OurGame.DisplayCrosshair;
                    break;
                }

                case 1:     //Display Radar
                {
                    OurGame.DisplayRadar = !OurGame.DisplayRadar;
                    break;
                }
                }
            }

            previousGamePadState = currentGamePadState;
            currentGamePadState  = Input.GamePads[0];

            base.Update(gameTime);
        }
コード例 #14
0
ファイル: InputHandler.cs プロジェクト: bramkelder/Orbis
 /// <summary>
 /// Checks if multiple given buttons are currently held down.
 /// </summary>
 /// <param name="buttons">An array of buttons to check.</param>
 /// <returns>Returns true if all buttons are held down.</returns>
 public bool IsGamePadHold(Buttons[] buttons)
 {
     foreach (Buttons button in buttons)
     {
         if (gState.IsButtonUp(button))
         {
             return(false);
         }
     }
     return(true);
 }
コード例 #15
0
 /// <summary>
 /// Returns if specific controller button is being released
 /// </summary>
 /// <param name="button">The button we want to check</param>
 /// <returns></returns>
 public bool controllerIsReleased(params Buttons[] buttons)
 {
     foreach (Buttons button in buttons)
     {
         if (newControllerState.IsButtonUp(button) && oldControllerState.IsButtonDown(button))
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #16
0
 /// <summary>
 /// Returns true if the button was released this frame.
 /// </summary>
 /// <param name="button">The button</param>
 /// <returns>True or false</returns>
 public bool IsButtonReleased(Button button)
 {
     if (currentPadState.IsConnected)
     {
         var buttons = buttonsToPad[button];
         return(currentPadState.IsButtonUp(buttons) && previousPadState.IsButtonDown(buttons));
     }
     else
     {
         var keys = buttonsToKeys[button];
         return(IsKeyReleased(keys.Item1) || IsKeyReleased(keys.Item2));
     }
 }
コード例 #17
0
        public override void Update(GameTime gameTime)
        {
            newKeyState     = Keyboard.GetState();
            newGamePadState = GamePad.GetState(PlayerIndex.One);

            if (newKeyState.IsKeyDown(Keys.W) && oldKeyState.IsKeyUp(Keys.W) ||
                newKeyState.IsKeyDown(Keys.Up) && oldKeyState.IsKeyUp(Keys.Up) ||
                newGamePadState.IsButtonDown(Buttons.DPadUp) && oldGamePadState.IsButtonUp(Buttons.DPadUp) ||
                newGamePadState.ThumbSticks.Left.Y > 0.5f && oldGamePadState.ThumbSticks.Left.Y < 0.5)
            {
                if (currentSelectedOption != 0)
                {
                    currentSelectedOption--;
                }
            }

            if (newKeyState.IsKeyDown(Keys.S) && oldKeyState.IsKeyUp(Keys.S) ||
                newKeyState.IsKeyDown(Keys.Down) && oldKeyState.IsKeyUp(Keys.Down) ||
                newGamePadState.IsButtonDown(Buttons.DPadDown) && oldGamePadState.IsButtonUp(Buttons.DPadDown) ||
                newGamePadState.ThumbSticks.Left.Y < -0.5f && oldGamePadState.ThumbSticks.Left.Y > -0.5)
            {
                if (currentSelectedOption != options.Count - 1)
                {
                    currentSelectedOption++;
                }
            }

            if (newKeyState.IsKeyDown(Keys.Space) && oldKeyState.IsKeyUp(Keys.Space) ||
                newKeyState.IsKeyDown(Keys.Enter) && oldKeyState.IsKeyUp(Keys.Enter) ||
                newGamePadState.IsButtonDown(Buttons.A) && oldGamePadState.IsButtonUp(Buttons.A))
            {
                switch (currentSelectedOption)
                {
                case 0:
                    game.Push(new GameStatePhase2());     //GameStatePhase1 GameStatePhase2
                    break;

                case 1:
                    game.Push(new OptionsState());
                    break;

                case 2:
                    quit = true;
                    break;
                }
            }

            oldKeyState     = newKeyState;
            oldGamePadState = newGamePadState;
        }
コード例 #18
0
 public void Update(GamePadState lastGamePadState, GamePadState currentGamePadState)
 {
     IsDown     = currentGamePadState.IsButtonDown(ButtonCode);
     OnPressed  = lastGamePadState.IsButtonUp(ButtonCode) && IsDown;
     IsUp       = currentGamePadState.IsButtonUp(ButtonCode);
     OnReleased = lastGamePadState.IsButtonDown(ButtonCode) && IsUp;
 }
コード例 #19
0
        public override bool IsPressed(Buttons button)
        {
            if (curr.IsButtonDown(button) && prev.IsButtonUp(button))
            {
                return(true);
            }

            if (button == Buttons.A)
            {
                if (curr_mouse.LeftButton == ButtonState.Pressed && prev_mouse.LeftButton == ButtonState.Released)
                {
                    return(true);
                }
            }

            if (button == Buttons.A || button == Buttons.B)
            {
                if (curr_keyboard.IsKeyDown(Keys.Space) && prev_keyboard.IsKeyUp(Keys.Space))
                {
                    return(true);
                }
            }

            Keys key = button_map[button];

            return(curr_keyboard.IsKeyDown(key) && prev_keyboard.IsKeyUp(key));
        }
コード例 #20
0
ファイル: InputManager.cs プロジェクト: pens/hs
 public static bool ButtonUp(Buttons button, bool justReleased)
 {
     if (newPad.IsButtonUp(button))
     {
         if (justReleased)
         {
             if (oldPad.IsButtonUp(button))
             {
                 return(false);
             }
             else
             {
                 return(true);
             }
         }
         else
         {
             return(true);
         }
     }
     else
     {
         return(false);
     }
 }
コード例 #21
0
        /// <summary>
        /// Comprueba si el boton o tecla asociada a una accion no esta pulsado.
        /// </summary>
        /// <param name="action">Nombre de la accion.</param>
        /// <returns>Devuelve verdadero si no se esta presionando la tecla o boton.</returns>
        public bool Release(string action)
        {
            switch (this.SelectedDevice)
            {
#if WINDOWS
            case InputType.KeyboardMouse:
                bool ret = false;
                if (this.Actions[action].Key != null)
                {
                    ret = keybState.IsKeyUp(this.Actions[action].Key.Value);
                }
                if (this.Actions[action].MouseButton != null)
                {
                    switch (this.Actions[action].MouseButton)
                    {
                    case MouseButtons.LeftButton: ret = mouseState.LeftButton == ButtonState.Released; break;

                    case MouseButtons.RightButton: ret = mouseState.RightButton == ButtonState.Released; break;

                    case MouseButtons.MiddleButton: ret = mouseState.MiddleButton == ButtonState.Released; break;

                    default: ret = false; break;
                    }
                }
                return(ret);
#endif
            case InputType.GamePad: return(gamepadState.IsButtonUp(this.Actions[action].Button.Value));

            default: return(false);
            }
        }
コード例 #22
0
        private void CheckAllButtons()
        {
            // PacketNumber only and always changes if there is a difference between GamePadStates.
            // ...At least, that's the theory. It doesn't seem to be implemented. Disabled for now.
            //if (_lastPacketNumber == _currentState.PacketNumber)
            //    return;
            foreach (Buttons button in Enum.GetValues(typeof(Buttons)))
            {
                if (_excludedButtons.Contains(button))
                {
                    break;
                }
                if (_currentState.IsButtonDown(button) && _previousState.IsButtonUp(button))
                {
                    RaiseButtonDown(button);
                }
                if (_currentState.IsButtonUp(button) && _previousState.IsButtonDown(button))
                {
                    RaiseButtonUp(button);
                }
            }

            // Checks triggers as buttons and floats
            CheckTriggers(s => s.Triggers.Left, Buttons.LeftTrigger);
            CheckTriggers(s => s.Triggers.Right, Buttons.RightTrigger);

            // Checks thumbsticks as vector2s
            CheckThumbSticks(s => s.ThumbSticks.Right, Buttons.RightStick);
            CheckThumbSticks(s => s.ThumbSticks.Left, Buttons.LeftStick);
        }
コード例 #23
0
        public void Update()
        {
            if (_currentCommands == _gameCommands && Id == -1)
            {
                Active = false;
            }
            if (GamePad.GetState(_controllerNum).IsConnected)
            {
                Active = true;
            }
            if (!Active && _currentCommands == _gameCommands)
            {
                return;
            }
            GamePadState state = GamePad.GetState(_controllerNum);

            foreach (KeyValuePair <Buttons, ICommandController> pair in _currentCommands)
            {
                if (state.IsButtonDown(pair.Key) && _oldState.IsButtonUp(pair.Key))
                {
                    pair.Value.BeginExecute(Id);
                }
                else if (state.IsButtonDown(pair.Key) && _oldState.IsButtonDown(pair.Key))
                {
                    pair.Value.Execute(Id);
                }
                else if (state.IsButtonUp(pair.Key) && _oldState.IsButtonDown(pair.Key))
                {
                    pair.Value.EndExecute(Id);
                }
            }
            _oldState = state;
        }
コード例 #24
0
ファイル: Game1.cs プロジェクト: TrevorNewell/Four-Frogs
        private void updateGUI(GameTime gameTime)
        {
            if ((currentGamePadState.IsButtonDown(Buttons.A) && (!isKeyPressed)))
            {
                isKeyPressed = true;
                if (index < 1)
                {
                    index++;
                    currentGUI = GUIs[index];
                }
                else
                {
                    startGame();
                }
            }

            if ((currentGamePadState.IsButtonUp(Buttons.A) && (isKeyPressed)))
            {
                isKeyPressed = false;
            }

            if (player.health <= 0f)
            {
                currentGUI = failScreen;
                healthBar.setOffset(-100, 13);
                healthBarBorders.setOffset(-100, 10);
            }

            if (player.isColBall(ball))
            {
                currentGUI = winScreen;
                healthBar.setOffset(-100, 13);
                healthBarBorders.setOffset(-100, 10);
            }
        }
コード例 #25
0
 /// <summary>
 /// Checks if the specified button is pressed on either keyboard or gamepad.
 /// </summary>
 bool IsPressed(Keys key, Buttons button)
 {
     return((currentKeyboardState.IsKeyDown(key) &&
             previousKeyboardState.IsKeyUp(key)) ||
            (currentGamePadState.IsButtonDown(button) &&
             previousGamePadState.IsButtonUp(button)));
 }
コード例 #26
0
        public bool IsInputUp(Inputs input)
        {
            if (inputType == InputType.Keyboard)
            {
                return(keyboard.IsKeyUp(inputToKeys[input]));
            }
            else if (inputType == InputType.Gamepad)
            {
                return(gamepad.IsButtonUp(inputToButtons[input]));
            }
            else if (inputType == InputType.Mouse)
            {
                switch (inputToMouse[input])
                {
                case MouseButton.Left:
                    return(mouse.LeftButton == ButtonState.Released);

                case MouseButton.Right:
                    return(mouse.RightButton == ButtonState.Released);

                case MouseButton.Middle:
                    return(mouse.MiddleButton == ButtonState.Released);
                }
            }
            return(false);
        }
コード例 #27
0
        public void Update(double totalMilliseconds, KeyboardState kstate, MouseState mstate, GamePadState gpstate)
        {
            if (escapeReset && (kstate.IsKeyDown(Keys.P) || gpstate.IsButtonDown(Buttons.Back)))
            {
                if (State == MenueState.Pause)
                {
                    State = MenueState.Running;
                }
                else
                {
                    State = MenueState.Pause;
                }

                escapeReset = false;
            }

            if (kstate.IsKeyUp(Keys.P) && gpstate.IsButtonUp(Buttons.Back))
            {
                escapeReset = true;
            }

            switch (State)
            {
            case MenueState.MainMenu:
                Menus[0].Update(mstate, kstate);
                break;

            case MenueState.Settings:
                Menus[1].Update(mstate, kstate);
                break;
            }
        }
コード例 #28
0
ファイル: GamePadInputBinding.cs プロジェクト: Rixium/Mayday
        public void Update()
        {
            var state = GamePad.GetState(_gamePadIndex);

            if (state.IsButtonDown(_gamePadButton) && _lastState.IsButtonUp(_gamePadButton) || AxisPressed(state, _gamePadAxis) && AxisReleased(_lastState, _gamePadAxis))
            {
                foreach (var action in OnPressed)
                {
                    action?.Invoke();
                }
            }
            else if (state.IsButtonUp(_gamePadButton) && _lastState.IsButtonDown(_gamePadButton) || AxisPressed(_lastState, _gamePadAxis) && AxisReleased(state, _gamePadAxis))
            {
                foreach (var action in OnReleased)
                {
                    action?.Invoke();
                }
            }
            else if (state.IsButtonDown(_gamePadButton) && _lastState.IsButtonDown(_gamePadButton) || AxisPressed(_lastState, _gamePadAxis) && AxisPressed(state, _gamePadAxis))
            {
                foreach (var action in OnHeld)
                {
                    action?.Invoke();
                }
            }

            _lastState = state;
        }
コード例 #29
0
ファイル: Game1.cs プロジェクト: northsteel/bnoerj
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            var keyboardState = Keyboard.GetState();
            var gamePadState  = GamePad.GetState(PlayerIndex.One);

            // Allows the game to exit
            if (keyboardState.IsKeyDown(Keys.Escape) == true ||
                GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                Exit();
            }

            if ((keyboardState.IsKeyDown(Keys.F12) == true &&
                 lastKeyboardState.IsKeyUp(Keys.F12) == true) ||
                (gamePadState.IsButtonDown(Buttons.Start) == true &&
                 lastGamePadState.IsButtonUp(Buttons.Start) == true))
            {
                colorAnalyzer.ControllingPlayer = PlayerIndex.One;
                colorAnalyzer.Visible           = !colorAnalyzer.Visible;
            }

            lastKeyboardState = keyboardState;
            lastGamePadState  = gamePadState;

            base.Update(gameTime);
        }
コード例 #30
0
        /// <summary>
        /// Handles input for quitting the game and toggling the safe area overlay.
        /// </summary>
        private void HandleInput()
        {
            previousKeyboardState = currentKeyboardState;
            previousGamePadState  = currentGamePadState;

            currentKeyboardState = Keyboard.GetState();
            currentGamePadState  = GamePad.GetState(PlayerIndex.One);

            // Check for exit.
            if (currentKeyboardState.IsKeyDown(Keys.Escape) ||
                currentGamePadState.IsButtonDown(Buttons.Back))
            {
                Exit();
            }

            // Check for showing or hiding the safe area overlay.
            if (safeAreaOverlay != null)
            {
                if ((currentKeyboardState.IsKeyDown(Keys.A) &&
                     previousKeyboardState.IsKeyUp(Keys.A)) ||
                    (currentGamePadState.IsButtonDown(Buttons.A) &&
                     previousGamePadState.IsButtonUp(Buttons.A)))
                {
                    safeAreaOverlay.Visible = !safeAreaOverlay.Visible;
                }
            }
        }