GamePad.GetState Method (PlayerIndex, GamePadDeadZone)

Gets the current state of a game pad controller, using a specified dead zone on analog stick positions.

Syntax

'Declaration
Public Shared Function GetState ( _
         playerIndex As PlayerIndex, _
         deadZoneMode As GamePadDeadZone _
) As GamePadState 
public static GamePadState GetState (
         PlayerIndex playerIndex,
         GamePadDeadZone deadZoneMode
)
public:
static GamePadState GetState(
         PlayerIndex playerIndex,
         GamePadDeadZone deadZoneMode
)

Parameters

  • playerIndex
    Type: PlayerIndex
    Player index for the controller you want to query.
  • deadZoneMode
    Type: GamePadDeadZone
    Enumerated value that specifies what dead zone type to use.

Return Value

Type: GamePadState
The current state of the controller.

Exceptions

Exception type Condition
InvalidOperationException An unknown error has occurred. Verify that the correct playerIndex is being requested.

Remarks

Bb197229.bp(en-us,XNAGameStudio.42).gifBest Practice
  • On the first menu presented by the game, consider asking the player to sign in by pressing A or Start. This enables the game to detect the correct controller in use for each player in the game.

  • When processing player input, you can examine SignedInGamer.GameDefaults to determine a player's preferences for how the Xbox 360 controller is used to send input to the game.

When you call GetState, check the returned structure's IsConnected property value. If the controller has been disconnected, this value will be false. When a controller is disconnected, values for its state will not be valid. Also, the controller will not receive any new vibration settings.

The deadZoneMode parameter specifies the type of dead-zone processing to apply to the analog sticks on the controller. By applying a dead zone, controller inputs will report values near the center and edges of their ranges more accurately. If you wish to do your own dead-zone processing, use GamePadDeadZone.None.

Requirements

Namespace: Microsoft.Xna.Framework.Input

Assembly: Microsoft.Xna.Framework (in microsoft.xna.framework.dll)

See Also

Concepts

Overview of User Input and Input Devices

Reference

SignedInGamer.PlayerIndex Property
SignedInGamer.GameDefaults
GamePad Class
GamePad Members
Microsoft.Xna.Framework.Input Namespace

Platforms

Windows Phone