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


C# Input.GamePadState类代码示例

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


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

示例1: Update

 public override void Update(GameTime gameTime, GamePadState newGamePadState, GamePadState oldGamePadState, KeyboardState newKeyboardState, KeyboardState oldKeyboardState)
 {
     if ((newGamePadState.Buttons.A != oldGamePadState.Buttons.A && newGamePadState.Buttons.A == ButtonState.Pressed)
         || (newKeyboardState.IsKeyDown(Keys.Enter) && oldKeyboardState.IsKeyUp(Keys.Enter))) {
         Game.GameStartingScreen = GameStartingScreen.SetupScreen;
     }
 }
开发者ID:bstockus,项目名称:WarehouseZombieAttack,代码行数:7,代码来源:SplashScreen.cs

示例2: GetInput

        public static List<InputManager.ACTIONS> GetInput()
        {
            currentGamePadState = GamePad.GetState(PlayerIndex.One);
            List<InputManager.ACTIONS> actions = new List<InputManager.ACTIONS>();

            if (currentGamePadState.IsButtonUp(Buttons.A) && previousGamePadState.IsButtonDown(Buttons.A))
            {
                actions.Add(InputManager.ACTIONS.JUMP);
            }

            if (currentGamePadState.ThumbSticks.Left.X > 0 || currentGamePadState.DPad.Right == ButtonState.Pressed)
            {
                actions.Add(InputManager.ACTIONS.RIGHT);
            }
            else if (currentGamePadState.ThumbSticks.Left.X < 0 || currentGamePadState.DPad.Left == ButtonState.Pressed)
            {
                actions.Add(InputManager.ACTIONS.LEFT);
            }

            if (currentGamePadState.IsButtonUp(Buttons.Y) && previousGamePadState.IsButtonDown(Buttons.Y))
            {
                actions.Add(InputManager.ACTIONS.TOGGLE);
            }

            previousGamePadState = currentGamePadState;
            return actions;
        }
开发者ID:wico-,项目名称:Code,代码行数:27,代码来源:inGamePad.cs

示例3: Update

        public override void Update(GameTime gameTime, EventManager events)
        {
            base.Update(gameTime, events);

              #region GamePad

              // GamePad
              P1LastGamePadState = P1GamePadState;
              P1GamePadState = GamePad.GetState(PlayerIndex.One);

              bool left = P1GamePadState.ThumbSticks.Left.X < 0.0f;
              bool right = P1GamePadState.ThumbSticks.Left.X > 0.0f;
              bool jump = (P1GamePadState.Buttons.A == ButtonState.Pressed
            && P1LastGamePadState.Buttons.A == ButtonState.Released);
              bool action = (P1GamePadState.Buttons.B == ButtonState.Released
            && P1LastGamePadState.Buttons.B == ButtonState.Pressed);

              #endregion

              #region Keyboard

              bool keyJump = (keyboard.IsKeyDown(Keys.Up)
            && lastKeyboard.IsKeyUp(Keys.Up));
              bool keyDownLeft = keyboard.IsKeyDown(Keys.Left);
              bool keyDownRight = keyboard.IsKeyDown(Keys.Right);
              bool keyAction = keyboard.IsKeyUp(Keys.Space)
            && lastKeyboard.IsKeyDown(Keys.Space);

              #endregion

              if (action || keyAction) events.Notify(Event.Action, null);
        }
开发者ID:colincapurso,项目名称:LD25,代码行数:32,代码来源:Input.cs

示例4: InputHelper

        /// <summary>
        ///   Constructs a new input state.
        /// </summary>
        public InputHelper(ScreenManager manager)
        {
            _currentKeyboardState = new KeyboardState();
            _currentGamePadState = new GamePadState();
            _currentMouseState = new MouseState();
            _currentVirtualState = new GamePadState();

            _lastKeyboardState = new KeyboardState();
            _lastGamePadState = new GamePadState();
            _lastMouseState = new MouseState();
            _lastVirtualState = new GamePadState();

            _manager = manager;

            _cursorIsVisible = false;
            _cursorMoved = false;
#if WINDOWS_PHONE
            _cursorIsValid = false;
#else
            _cursorIsValid = true;
#endif
            _cursor = Vector2.Zero;

            _handleVirtualStick = true;
        }
开发者ID:kbo4sho,项目名称:SG.WP7,代码行数:28,代码来源:InputHelper.cs

示例5: Update

 /// <summary>
 /// Performs the logic to control the Player.
 /// </summary>
 /// <param name="pad">The state of the gamepad used to control this player.</param>
 public void Update(GamePadState pad)
 {
     if (pad.ThumbSticks.Left.X >= 0.5) pos.X += speed;
     if (pad.ThumbSticks.Left.X <= -0.5) pos.X -= speed;
     if (pad.ThumbSticks.Left.Y >= 0.5) pos.Y -= speed;
     if (pad.ThumbSticks.Left.Y <= -0.5) pos.Y += speed;
 }
开发者ID:elegantlytragic,项目名称:isaac,代码行数:11,代码来源:GamepadPlayer.cs

示例6: getAxis

 public float getAxis(GamePadState gamePadState, bool left, bool x)
 {
     if (x)
     {
         if (left)
         {
             return gamePadState.ThumbSticks.Left.X;
         }
         else
         {
             return gamePadState.ThumbSticks.Right.X;
         }
     }
     else
     {
         if (left)
         {
             return gamePadState.ThumbSticks.Left.Y;
         }
         else
         {
             return gamePadState.ThumbSticks.Right.Y;
         }
     }
 }
开发者ID:doanhtdpl,项目名称:karts,代码行数:25,代码来源:InputManager.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: GamePadController

        public virtual void GamePadController(GamePadState state)
        {
            if (state.DPad.Down == ButtonState.Pressed && !(_previousGamePadState.DPad.Down == ButtonState.Pressed))
            {
                _selectedIndex++;

                if (_selectedIndex == _levels.Length)
                    _selectedIndex--;
            }
            else if (state.DPad.Up == ButtonState.Pressed && !(_previousGamePadState.DPad.Up == ButtonState.Pressed))
            {
                _selectedIndex--;

                if (_selectedIndex < 0)
                    _selectedIndex++;
            }
            else if (state.Buttons.A == ButtonState.Pressed &&!(_previousGamePadState.Buttons.A ==ButtonState.Pressed))
            {
                var sample = _levels[_selectedIndex].CreateLevelFunction();
                sample.OnLoad();
                CurrentLevel = sample;
            }

            _previousGamePadState = state;
        }
开发者ID:RiltonF,项目名称:MonogameAsteroids,代码行数:25,代码来源:Game1.cs

示例9: Initialize

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            base.Initialize();
            previousGamePadState = GamePad.GetState(PlayerIndex.One);
        }
开发者ID:higgs11,项目名称:Controller,代码行数:13,代码来源:Game1.cs

示例10: Update

        //Methods
        //Update & Draw
        public void Update(MouseState mouse, KeyboardState keyboard, GamePadState gamePadState)
        {
            if (keyboard.IsKeyUp(Keys.Escape) && gamePadState.Buttons.Start == ButtonState.Released)
                pauseAllowed = true;

            if ((keyboard.IsKeyDown(Keys.Escape) || gamePadState.Buttons.Start == ButtonState.Pressed) && pauseAllowed)
            {

                pauseAllowed = false;
                Game1.gameState = GameState.Pause;
            }

            if (mouse.X > 800)
            {
                Map.Current.position.X++;
                player.position.X++;
            }

            if (mouse.X < 200)
            {
                Map.Current.position.X--;
                player.position.X--;
            }

            Map.Current.Update();
            player.Update(mouse, keyboard, gamePadState);
        }
开发者ID:fraxouille,项目名称:DirtyTricks,代码行数:29,代码来源:GameScreen.cs

示例11: InputManager

 //********************************************
 // Constructors
 //********************************************
 public InputManager(Main game)
 {
     z_game = game;
     z_prevKeyState = z_curKeyState = new KeyboardState();
     z_prevPadState = z_curPadState = new GamePadState();
     SetDefaultControls();
 }
开发者ID:acm-team,项目名称:SpaceCats,代码行数:10,代码来源:InputManager.cs

示例12: HandleInput

        /// <summary>
        /// Exit the screen after a tap or click
        /// </summary>
        /// <param name="input"></param>
        private void HandleInput(MouseState mouseState, GamePadState padState)
        {
            if (!isExit)
            {
#if WINDOWS_PHONE
                if (ScreenManager.input.Gestures.Count > 0 &&
                    ScreenManager.input.Gestures[0].GestureType == GestureType.Tap)
                {
                    isExit = true;
                }
#else

                PlayerIndex result;
                if (mouseState.LeftButton == ButtonState.Pressed)
                {
                    isExit = true;
                }
                else if (ScreenManager.input.IsNewButtonPress(Buttons.A, null, out result) ||
                    ScreenManager.input.IsNewButtonPress(Buttons.Start, null, out result))
                {
                    isExit = true;
                }
#endif

            }
        }
开发者ID:liwq-net,项目名称:SilverSprite,代码行数:30,代码来源:InstructionScreen.cs

示例13: CheckHorizontalMovementKeys

        //
        // Horizontal Movement
        protected void CheckHorizontalMovementKeys(KeyboardState ksKeys,
                                           GamePadState gsPad)
        {
            bool bResetTimer = false;

            player.Thrusting = false;
            if ((ksKeys.IsKeyDown(Keys.Right)) || (gsPad.ThumbSticks.Left.X > 0))
            {
                if (player.ScrollRate < iMaxHorizontalSpeed)
                {
                    player.ScrollRate += player.AccelerationRate;
                    if (player.ScrollRate > iMaxHorizontalSpeed)
                        player.ScrollRate = iMaxHorizontalSpeed;
                    bResetTimer = true;
                }
                player.Thrusting = true;
                player.Facing = 0;
            }

            if ((ksKeys.IsKeyDown(Keys.Left)) || (gsPad.ThumbSticks.Left.X < 0))
            {
                if (player.ScrollRate > -iMaxHorizontalSpeed)
                {
                    player.ScrollRate -= player.AccelerationRate;
                    if (player.ScrollRate < -iMaxHorizontalSpeed)
                        player.ScrollRate = -iMaxHorizontalSpeed;
                    bResetTimer = true;
                }
                player.Thrusting = true;
                player.Facing = 1;
            }

            if (bResetTimer)
                player.SpeedChangeCount = 0.0f;
        }
开发者ID:sp00fy,项目名称:secret-robot,代码行数:37,代码来源:Game1.cs

示例14: 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

示例15: Update

        public override void Update(float deltaTime)
        {
            if (id == World.gameId)
            {
                gamePad = GamePad.GetState(PlayerIndex.One);
                keyboard = Keyboard.GetState();

                if (gamePad.Buttons.Y == ButtonState.Pressed &&
                    oldGamePad.Buttons.Y == ButtonState.Released &&
                    World.inMenu == false ||
                    keyboard.IsKeyDown(Keys.Tab) &&
                    oldKeyboard.IsKeyUp(Keys.Tab) &&
                    World.inMenu == false)
                {
                    World.inMenu = true;
                    World.menuManager.SwitchMenu(World.menuManager.shop);
                }
                else if (keyboard.IsKeyDown(Keys.Tab) &&
                   oldKeyboard.IsKeyUp(Keys.Tab) &&
                   World.inMenu == true)
                {
                    World.menuManager.CurrentMenu.BackOut();
                }
            }
            oldGamePad = gamePad;
            oldKeyboard = keyboard;
            base.Update(deltaTime);
        }
开发者ID:DuncanKeller,项目名称:dunGeon,代码行数:28,代码来源:Capitalist.cs


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