The GamePadState class is part of the Microsoft.Xna.Framework.Input namespace in the XNA Framework. It provides access to the state of a gamepad controller, including information about which buttons and thumbsticks are being pressed.
Example 1: Checking if a button is pressed
// Get the current state of the gamepad GamePadState state = GamePad.GetState(PlayerIndex.One);
// Check if the A button is pressed if (state.Buttons.A == ButtonState.Pressed) { // Do something }
Example 2: Getting the position of the left thumbstick
// Get the current state of the gamepad GamePadState state = GamePad.GetState(PlayerIndex.One);
// Get the position of the left thumbstick Vector2 leftThumbstick = state.ThumbSticks.Left;
// Check if the thumbstick is pushed to the left or right if (leftThumbstick.X < 0) { // Pushed left } else if (leftThumbstick.X > 0) { // Pushed right }
This class is part of the XNA Framework, which is a package library for developing games in C#. It was originally developed by Microsoft for the Xbox 360 and PC platforms, but is now maintained by the community as an open source project.
C# (CSharp) Microsoft.Xna.Framework.Input GamePadState - 44 examples found. These are the top rated real world C# (CSharp) examples of Microsoft.Xna.Framework.Input.GamePadState extracted from open source projects. You can rate examples to help us improve the quality of examples.