当前位置: 首页>>代码示例>>C#>>正文


C# GamePadState.IsButtonDown方法代码示例

本文整理汇总了C#中Microsoft.Xna.Framework.Input.GamePadState.IsButtonDown方法的典型用法代码示例。如果您正苦于以下问题:C# GamePadState.IsButtonDown方法的具体用法?C# GamePadState.IsButtonDown怎么用?C# GamePadState.IsButtonDown使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Xna.Framework.Input.GamePadState的用法示例。


在下文中一共展示了GamePadState.IsButtonDown方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Update

        public void Update(GamePadState pad)
        {
            if (pad.IsButtonDown(Buttons.LeftThumbstickDown) && !oldPad.IsButtonDown(Buttons.LeftThumbstickDown))
            {
                if (current < 3)
                {
                    current++;
                }
            }
            if (pad.IsButtonDown(Buttons.LeftThumbstickUp) && !oldPad.IsButtonDown(Buttons.LeftThumbstickUp))
            {
                if (current > 1)
                {
                    current--;
                }
            }
            if (pad.IsButtonDown(Buttons.A) && oldPad.IsButtonUp(Buttons.A))
            {
                if (current == 1)
                {
                    FirstGame.start = true;
                }
                else if (current == 3)
                {
                    FirstGame.exit = true;
                }
            }

            oldPad = pad;
        }
开发者ID:Benbow,项目名称:ImagineCup2013,代码行数:30,代码来源:AccueilGUI.cs

示例2: AttackAdd

        // Adds an attack when the attack button is pressed accompanied by sound and animation
        public static void AttackAdd(ContentManager Content, Player ninja, List<PlayerAttack> ninjaAttacks, 
            KeyboardState presentKey, KeyboardState pastKey,
            GamePadState pressentButton, GamePadState pastButton)
        {
            if (presentKey.IsKeyDown(Keys.Space) && pastKey.IsKeyUp(Keys.Space)
                || pressentButton.IsButtonDown(Buttons.A) && pastButton.IsButtonUp(Buttons.A))
            {
                // if the attack button is pressed a new attack will be added to the list
                ninjaAttacks.Add(new PlayerAttack(Content.Load<Texture2D>("Images\\Attack"),
                    new Vector2(ninja.PositionX + (int)(ninja.Texture.Width * 0.8),
                    ninja.PositionY + (int)(ninja.Texture.Height / 2.25))));

                // A sound effect will be played each time we press the attack button
                ninja.PlaySound();

            }

            // The animation texture of the character will change with each attack
            if (presentKey.IsKeyDown(Keys.Space) || pressentButton.IsButtonDown(Buttons.A))
            {
                ninja.Texture = Content.Load<Texture2D>("Images\\NinjaFrame1-2");
            }
            else
            {
                ninja.Texture = Content.Load<Texture2D>("Images\\NinjaFrame1-1");
            }
        }
开发者ID:nader-dab,项目名称:JustANinjaGame,代码行数:28,代码来源:PlayerLogic.cs

示例3: Update

        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();
                }
            }
        }
开发者ID:BoltThrower,项目名称:Super-Mario-World-1-1,代码行数:60,代码来源:GamePadController.cs

示例4: updateSingleplayer

        public static void updateSingleplayer()
        {
            prevGamepad = currGamepad;
            currGamepad = GamePad.GetState(PlayerIndex.One);

            Vector2 moveVec = new Vector2(0, 0);

            if (currGamepad.IsButtonDown(Buttons.DPadUp)) moveVec += new Vector2(0, -speed);
            if (currGamepad.IsButtonDown(Buttons.DPadLeft)) moveVec += new Vector2(-speed, 0);
            if (currGamepad.IsButtonDown(Buttons.DPadDown)) moveVec += new Vector2(0, speed);
            if (currGamepad.IsButtonDown(Buttons.DPadRight)) moveVec += new Vector2(speed, 0);

            if (isClicked(Buttons.A) && !isJumping) isJumping = true;

            if (isJumping && !limitReached)
            {
                moveVec += new Vector2(0, -speed);
                test += speed;
                if (test == limit)
                    limitReached = true;
            }
            else if (limitReached)
            {
                moveVec -= new Vector2(0, -speed);
                test -= speed;
                if (test == 0)
                {
                    limitReached = false;
                    isJumping = false;
                }
            }
            Camera2D.movePosition(moveVec);
        }
开发者ID:KleinerMensch,项目名称:CR4VE,代码行数:33,代码来源:GamepadControls.cs

示例5: ProcessController

        public void ProcessController()
        {
            keyState = Keyboard.GetState();
            padState = GamePad.GetState(Microsoft.Xna.Framework.PlayerIndex.One);
            Actor hero = (Actor)game.Hero;

            /*
             * GamePad inputs
             */

            //Moving
            if (padState.IsButtonDown(Buttons.LeftThumbstickLeft) || keyState.IsKeyDown(Keys.Left))
            {
                hero.Pos.X -= 1.5f;
                hero.NextPosture(ActorDirection.Left);
            }
            if (padState.IsButtonDown(Buttons.LeftThumbstickRight) || keyState.IsKeyDown(Keys.Right))
            {
                hero.Pos.X += 1.5f;
                hero.NextPosture(ActorDirection.Right);
            }

            //Jump
            if (padState.IsButtonDown(Buttons.LeftThumbstickUp))
            {

            }

            if (padState.IsButtonDown(Buttons.LeftThumbstickDown))
            {

            }
        }
开发者ID:slay-mithos,项目名称:XNA-tests,代码行数:33,代码来源:KeyboardController.cs

示例6: FireCannons

 public static void FireCannons(GamePadState gs, GamePadState previousGamePadState, Player player, GameTime gameTime)
 {
     if (gs.IsButtonDown(actionKeys[Action.FireLeftCannon]))
     {
         player.FireLeftCannons(gameTime);
     }
     if (gs.IsButtonDown(actionKeys[Action.FireRightCannon]))
     {
         player.FireRightCannons(gameTime);
     }
 }
开发者ID:rpwjanzen,项目名称:2HourGame,代码行数:11,代码来源:ShipControlBehaviours.cs

示例7: FromInput

        /// <summary>
        /// Gets the current direction from a game pad and keyboard.
        /// </summary>
        public static Buttons FromInput(GamePadState gamePad, KeyboardState keyboard)
        {
            Buttons direction = None;

            // Get vertical direction.
            if (gamePad.IsButtonDown(Buttons.DPadUp) ||
                gamePad.IsButtonDown(Buttons.LeftThumbstickUp) ||
                keyboard.IsKeyDown(Keys.Up))
            {
                direction |= Up;
            }
            else if (gamePad.IsButtonDown(Buttons.DPadDown) ||
                gamePad.IsButtonDown(Buttons.LeftThumbstickDown) ||
                keyboard.IsKeyDown(Keys.Down))
            {
                direction |= Down;
            }

            // Comebine with horizontal direction.
            if (gamePad.IsButtonDown(Buttons.DPadLeft) ||
                gamePad.IsButtonDown(Buttons.LeftThumbstickLeft) ||
                keyboard.IsKeyDown(Keys.Left))
            {
                direction |= Left;
            }
            else if (gamePad.IsButtonDown(Buttons.DPadRight) ||
                gamePad.IsButtonDown(Buttons.LeftThumbstickRight) ||
                keyboard.IsKeyDown(Keys.Right))
            {
                direction |= Right;
            }

            return direction;
        }
开发者ID:Hamsand,项目名称:Swf2XNA,代码行数:37,代码来源:Direction.cs

示例8: GetState

        /// <summary>
        /// Generates a GamePadState based on the touch input provided (as applied to the on screen controls) and the gamepad state
        /// </summary>
        public GamePadState GetState(TouchCollection touchState, GamePadState gpState)
        {
            //Work out what buttons are pressed based on the touchState
            Buttons buttonsPressed = 0;

            foreach (TouchLocation touch in touchState)
            {
                if (touch.State == TouchLocationState.Moved || touch.State == TouchLocationState.Pressed)
                {
                    //Scale the touch position to be in _baseScreenSize coordinates
                    Vector2 pos = touch.Position;
                    Vector2.Transform(ref pos, ref globalTransformation, out pos);

                    if (pos.X < 128)
                        buttonsPressed |= Buttons.DPadLeft;
                    else if (pos.X < 256)
                        buttonsPressed |= Buttons.DPadRight;
                    else if (pos.X >= baseScreenSize.X - 128)
                        buttonsPressed |= Buttons.A;
                }
            }

            //Combine the buttons of the real gamepad
            GamePadButtons gpButtons = gpState.Buttons;
            buttonsPressed |= (gpButtons.A == ButtonState.Pressed ? Buttons.A : 0);
            buttonsPressed |= (gpButtons.B == ButtonState.Pressed ? Buttons.B : 0);
            buttonsPressed |= (gpButtons.X == ButtonState.Pressed ? Buttons.X : 0);
            buttonsPressed |= (gpButtons.Y == ButtonState.Pressed ? Buttons.Y : 0);

            buttonsPressed |= (gpButtons.Start == ButtonState.Pressed ? Buttons.Start : 0);
            buttonsPressed |= (gpButtons.Back == ButtonState.Pressed ? Buttons.Back : 0);

            buttonsPressed |= gpState.IsButtonDown(Buttons.DPadDown) ? Buttons.DPadDown : 0;
            buttonsPressed |= gpState.IsButtonDown(Buttons.DPadLeft) ? Buttons.DPadLeft : 0;
            buttonsPressed |= gpState.IsButtonDown(Buttons.DPadRight) ? Buttons.DPadRight : 0;
            buttonsPressed |= gpState.IsButtonDown(Buttons.DPadUp) ? Buttons.DPadUp : 0;

            buttonsPressed |= (gpButtons.BigButton == ButtonState.Pressed ? Buttons.BigButton : 0);
            buttonsPressed |= (gpButtons.LeftShoulder == ButtonState.Pressed ? Buttons.LeftShoulder : 0);
            buttonsPressed |= (gpButtons.RightShoulder == ButtonState.Pressed ? Buttons.RightShoulder : 0);

            buttonsPressed |= (gpButtons.LeftStick == ButtonState.Pressed ? Buttons.LeftStick : 0);
            buttonsPressed |= (gpButtons.RightStick == ButtonState.Pressed ? Buttons.RightStick : 0);

            var buttons = new GamePadButtons(buttonsPressed);

            return new GamePadState(gpState.ThumbSticks, gpState.Triggers, buttons, gpState.DPad);
        }
开发者ID:infinitespace-studios,项目名称:penumbra,代码行数:51,代码来源:VirtualGamePad.cs

示例9: Update

        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
                Exit();

            _keyState = Keyboard.GetState();
            _padState = GamePad.GetState(PlayerIndex.One);

            //Let the Scene Manager do it's thing

            if ((_prevKeyState.IsKeyDown(Keys.P) && !_keyState.IsKeyDown(Keys.P)) || (_prevPadState.IsButtonDown(Buttons.Y) && !_padState.IsButtonDown(Buttons.Y)))
            {
                // The 'P' key has just been released
                // This will only fire ONCE when the 'P' key is released
                if (_pauseOn)
                    _pauseOn = false;
                else
                    _pauseOn = true;
            }

            if(!_pauseOn)
                _manager.NextScene().Update(gameTime);

            //Console.WriteLine();
            _prevKeyState = _keyState;
            _prevPadState = _padState;

            base.Update(gameTime);
        }
开发者ID:Terracorrupt,项目名称:3rdYearProject,代码行数:29,代码来源:Game1.cs

示例10: CheckInput

        /// <summary>
        /// Call this method when input is received to have the console react to the user's commands.
        /// </summary>
        /// <param name="kbs">The current keyboard state.</param>
        /// <returns>The Command that corresponds to the user's input.</returns>
        public void CheckInput(GamePadState gs)
        {
            if (_menuActive)
            {
                if (gs.IsButtonDown(Buttons.Y) && _oldPad.IsButtonUp(Buttons.Y))
                    _menuActive = false;
            }
            else
            {
                // Should we bring the menu up?
                if (gs.IsButtonDown(Buttons.Y) && _oldPad.IsButtonUp(Buttons.Y))
                    _menuActive = true;
            }

            _oldPad = gs;
        }
开发者ID:GitKei,项目名称:COMP7615Asgn4,代码行数:21,代码来源:Menu.cs

示例11: Update

 public override void Update( TimeSpan gameTime, KeyboardState keyState, MouseState mouseState, GamePadState padState )
 {
     if ( keyState.IsKeyDown( Keys.Space ) || padState.IsButtonDown( Buttons.X ) || keyState.IsKeyDown( Keys.X ) )
     {
         ReferMenu( null );
     }
 }
开发者ID:nitzanbueno,项目名称:TanksDropTwo,代码行数:7,代码来源:PauseMenu.cs

示例12: handleController

        private List<Command> handleController()
        {
            List<Command> commands = new List<Command>();
            padState = GamePad.GetState(Microsoft.Xna.Framework.PlayerIndex.One);
            
            Vector2 move = new Vector2();
            move.X = 0;
            move.Y = 0;
            if (padState.ThumbSticks.Left.Length() > .7f)
            {
                move.X = padState.ThumbSticks.Left.X * .7f;
                move.Y = -padState.ThumbSticks.Left.Y * .7f;   
            }
            commands.Add(new MoveCommand(move));


            Vector2 gazeDir = new Vector2();
            gazeDir.X = padState.ThumbSticks.Right.X;
            gazeDir.Y = -padState.ThumbSticks.Right.Y;
            commands.Add(new GazeCommand(gazeDir));

            if (padState.IsButtonDown(Buttons.RightShoulder))
                commands.Add(new PunchCommand());
            return commands;
        }
开发者ID:mitjmcc,项目名称:DreamStateMachine,代码行数:25,代码来源:InputHandler.cs

示例13: InputsPlayer

        public void InputsPlayer(GameTime gameTime, bool move, bool jump, Player player)
        {
            // Save previous keyboard/gamepad states
            previousKeyboardState = currentKeyboardState;
            previousGamepadState = currentGamepadState;

            // Read current keyboard/gamepad
            currentKeyboardState = Keyboard.GetState();
            currentGamepadState = GamePad.GetState(PlayerIndex.One);

            if (move && player.CanMove)
            {
                if (currentKeyboardState.IsKeyDown(Keys.Left) || currentGamepadState.ThumbSticks.Left.X < 0)
                    player.Move(-1f);
                else if (currentKeyboardState.IsKeyDown(Keys.Right) || currentGamepadState.ThumbSticks.Left.X > 0)
                    player.Move(1f);
                else
                    player.Move(0f);
            }

            if (player.CanJump && jump)
            {
                if (currentGamepadState.IsButtonDown(Buttons.A) && previousGamepadState.IsButtonUp(Buttons.A))
                    player.Jump();
                else if (currentKeyboardState.IsKeyDown(Keys.Z) && previousKeyboardState.IsKeyUp(Keys.Z))
                    player.Jump();
            }

            if (player.IsOverDoor)
            {
                if (currentGamepadState.ThumbSticks.Left.Y < 0
                    && previousGamepadState.ThumbSticks.Left.Y < 0
                    && player.Velocity.X == 0
                    )
                    player.EnterDoor();
                else if (currentKeyboardState.IsKeyDown(Keys.Up)
                    && previousKeyboardState.IsKeyUp(Keys.Up)
                    && player.Velocity.X == 0
                    )
                    player.EnterDoor();
            }

            if (currentGamepadState.IsButtonDown(Buttons.B) && previousGamepadState.IsButtonUp(Buttons.B))
                player.Attack(gameTime);
            else if (currentKeyboardState.IsKeyDown(Keys.X) && previousKeyboardState.IsKeyUp(Keys.X))
                player.Attack(gameTime);
        }
开发者ID:colincapurso,项目名称:Game-Engine-XNA,代码行数:47,代码来源:Input.cs

示例14: PickupGold

 public static void PickupGold(GamePadState gs, GamePadState previousGamePadState, Player player, GameTime gameTime)
 {
     var pickupGoldButton = actionKeys[Action.PickupGold];
     if (gs.IsButtonDown(pickupGoldButton) && previousGamePadState.IsButtonUp(pickupGoldButton))
     {
         player.AttemptPickupGold();
     }
 }
开发者ID:rpwjanzen,项目名称:2HourGame,代码行数:8,代码来源:ShipControlBehaviours.cs

示例15: Update

        public void Update()
        {
            motion = Vector2.Zero;

            keyboardState = Keyboard.GetState();
            gamePadState = GamePad.GetState(PlayerIndex.One);

            if (keyboardState.IsKeyDown(Keys.Left) || gamePadState.IsButtonDown(Buttons.LeftThumbstickLeft))
                motion.X = -1;

            if (keyboardState.IsKeyDown(Keys.Right) || gamePadState.IsButtonDown(Buttons.LeftThumbstickRight))
                motion.X = 1;

            motion.X *= paddleSpeed;
            position += motion;
            checkInBounds();
        }
开发者ID:rene-ye,项目名称:A4Breakout,代码行数:17,代码来源:Bar.cs


注:本文中的Microsoft.Xna.Framework.Input.GamePadState.IsButtonDown方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。