• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Input.GamePadState类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

 public void update(GamePadState gamePad, GameTime time)
 {
     if (! Menu.isActive())
     {
         if (time.TotalGameTime.Milliseconds % 50 == 0)
         {
             if (gamePad.ThumbSticks.Left.X > 0 && position.X < maxPosition.X)
                 position.X += cursorWidth;
             else if (gamePad.ThumbSticks.Left.X < 0 && position.X > 0)
                 position.X -= cursorWidth;
             if (gamePad.ThumbSticks.Left.Y < 0 && position.Y < maxPosition.Y)
                 position.Y += cursorHeight;
             else if (gamePad.ThumbSticks.Left.Y > 0 && position.Y > 0)
                 position.Y -= cursorHeight;
         }
         if (time.TotalGameTime.Milliseconds % 200 == 0)
         {
             if (gamePad.DPad.Right == ButtonState.Pressed && position.X < maxPosition.X)
                 position.X += cursorWidth;
             else if (gamePad.DPad.Left == ButtonState.Pressed && position.X > 0)
                 position.X -= cursorWidth;
             if (gamePad.DPad.Down == ButtonState.Pressed && position.Y < maxPosition.Y)
                 position.Y += cursorHeight;
             else if (gamePad.DPad.Up == ButtonState.Pressed && position.Y > 0)
                 position.Y -= cursorHeight;
         }
     }
 }
开发者ID:mueschm,项目名称:Tower-Defense,代码行数:28,代码来源:Controller.cs


示例15: AmbientToggle

        protected void AmbientToggle(KeyboardState currentKeyboardState, GamePadState currentGamePadState)
        {
            // toggle Ambient - Night/Day effect
            if (previousKeyboardState.IsKeyDown(Keys.E) &&
                currentKeyboardState.IsKeyUp(Keys.E) ||
                previousGamePadState.IsButtonDown(Buttons.RightShoulder) &&
                currentGamePadState.IsButtonUp(Buttons.RightShoulder))
            {
                ambient = !ambient;

                currentMusic.Stop();
                currentMusic.Dispose();

                // Ambient true sets to day time effect, false sets to night time effect
                if(ambient)
                {
                    skyColor = Color.DeepSkyBlue;
                    effect.Parameters["material"].StructureMembers["ambient"].SetValue(new Vector4(0.65f, 0.65f, 0.6f, 1.0f));
                    currentMusic = musicDay.CreateInstance();

                }
                else
                {
                    skyColor = Color.DarkSlateGray;
                    effect.Parameters["material"].StructureMembers["ambient"].SetValue(new Vector4(0.1f, 0.1f, 0.15f, 1.0f));
                    currentMusic = musicNight.CreateInstance();
                }
                enemy.Apply3DAudio(listener, enemy.Position, currentMusic);
                currentMusic.Play();

            }
        }
开发者ID:jsquare89,项目名称:MazeGame,代码行数:32,代码来源:MazeGame.cs


示例16: Update

        public void Update(Vector2 pos, MouseState mouse, GamePadState gps, GameTime gameTime)
        {
            //check user Drag Drop Events
            if (mouse.LeftButton == ButtonState.Pressed || gps.Buttons.A == ButtonState.Pressed)
            {
                //CHECK BUTTONS
                int clickedID = getClickedID(new Vector2(pos.X, pos.Y));
                if (clickedID >= 0)
                {
                    if (clickedID == 1)
                    {
                        main.stateManager.loadNextScreen(2, 0, gameTime);
                    }
                    if (clickedID == 2)
                    {
                        main.stateManager.loadNextScreen(4, 0, gameTime);
                    }
                    if (clickedID == 3)
                    {
                        main.lastState = 1;
                        main.stateManager.loadNextScreen(5, 0, gameTime);
                    }

                    Console.WriteLine("BUTTON PRESSED: clickedID: "+clickedID);
                    //APACURRO BOTONES
                }

            }
        }
开发者ID:grantana,项目名称:dancingParticles,代码行数:29,代码来源:Menu.cs


示例17: UpdateJump

        public void UpdateJump(KeyboardState aCurrentKeyboardState, GamePadState aCurrentGamePadState)
        {
            if ((CurrentState == State.Walking || CurrentState == State.Still) && (aCurrentKeyboardState.IsKeyDown(Keys.Up) == true || aCurrentGamePadState.DPad.Up == ButtonState.Pressed || aCurrentGamePadState.Buttons.A == ButtonState.Pressed))
            {
                Jump();
            }

            if (CurrentState == State.Jumping)
            {

                if (StartPosition.Y - Position.Y > 80)  //At peak of jump...
                {
                    Dir.Y = MOVE_DOWN;
                    MoveSpeed.Y = 3.0f;
                }

                Position.Y = (Dir.Y == MOVE_DOWN) ? Position.Y + MoveSpeed.Y : Position.Y - MoveSpeed.Y; //Change Y position

                //END JUMP LOGIC
                if (Position.Y > StartPosition.Y)
                {
                    Position.Y = StartPosition.Y;
                    CurrentState = State.Still;
                    Source = new Rectangle(0, 0, 28, Source.Height);
                    Dir.Y = 0;
                    MoveSpeed.X = 6.0f;
                    MoveSpeed.Y = 3.5f;
                }
            }
        }
开发者ID:JordanForeman,项目名称:JumperMan,代码行数:30,代码来源:Player.cs


示例18: Update

 /// <summary>
 /// Handles input, performs physics, and animates the player sprite.
 /// </summary>
 /// <remarks>
 /// We pass in all of the input states so that our game is only polling the hardware
 /// once per frame. We also pass the game's orientation because when using the accelerometer,
 /// we need to reverse our motion when the orientation is in the LandscapeRight orientation.
 /// </remarks>
 public void Update(
     GameTime gameTime,
     KeyboardState keyboardState,
     GamePadState gamePadState)
 {
     base.Update(gameTime);
 }
开发者ID:faintdeception,项目名称:FreedomFarmer,代码行数:15,代码来源:VisualGameObject.cs


示例19: Input

 static Input()
 {
     oldGamePadStates = new GamePadState[MaxInputs];
     newGamePadStates = new GamePadState[MaxInputs];
     //oldKeyboardState = new KeyboardState[MaxInputs];
     //newKeyboardState = new KeyboardState[MaxInputs];
 }
开发者ID:noogai03sprojects,项目名称:Testbed,代码行数:7,代码来源:Input.cs


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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Input.KeyboardState类代码示例发布时间:2022-05-26
下一篇:
C# Graphics.Viewport类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap