Table of Contents

Struct GamePadState

Namespace
Microsoft.Xna.Framework.Input
Assembly
MonoGame.Framework.dll

Represents specific information about the state of the controller, including the current state of buttons and sticks.

This is implemented as a partial struct to allow for individual platforms to offer additional data without separate state queries to GamePad.

public struct GamePadState
Inherited Members

Constructors

GamePadState(GamePadThumbSticks, GamePadTriggers, GamePadButtons, GamePadDPad)

Initializes a new instance of the GamePadState struct using the specified GamePadThumbSticks, GamePadTriggers, GamePadButtons, and GamePadDPad.

public GamePadState(GamePadThumbSticks thumbSticks, GamePadTriggers triggers, GamePadButtons buttons, GamePadDPad dPad)

Parameters

thumbSticks GamePadThumbSticks

Initial thumbstick state.

triggers GamePadTriggers

Initial trigger state.

buttons GamePadButtons

Initial button state.

dPad GamePadDPad

Initial directional pad state.

GamePadState(Vector2, Vector2, float, float, Buttons)

Initializes a new instance of the GamePadState struct using the specified stick, trigger, and button values.

public GamePadState(Vector2 leftThumbStick, Vector2 rightThumbStick, float leftTrigger, float rightTrigger, Buttons button)

Parameters

leftThumbStick Vector2

Left stick value. Each axis is clamped between −1.0 and 1.0.

rightThumbStick Vector2

Right stick value. Each axis is clamped between −1.0 and 1.0.

leftTrigger float

Left trigger value. This value is clamped between 0.0 and 1.0.

rightTrigger float

Right trigger value. This value is clamped between 0.0 and 1.0.

button Buttons

Button(s) to initialize as pressed.

GamePadState(Vector2, Vector2, float, float, Buttons[])

Initializes a new instance of the GamePadState struct using the specified stick, trigger, and button values.

public GamePadState(Vector2 leftThumbStick, Vector2 rightThumbStick, float leftTrigger, float rightTrigger, Buttons[] buttons)

Parameters

leftThumbStick Vector2

Left stick value. Each axis is clamped between −1.0 and 1.0.

rightThumbStick Vector2

Right stick value. Each axis is clamped between −1.0 and 1.0.

leftTrigger float

Left trigger value. This value is clamped between 0.0 and 1.0.

rightTrigger float

Right trigger value. This value is clamped between 0.0 and 1.0.

buttons Buttons[]

Array of Buttons to initialize as pressed.

Fields

Default

The default initialized gamepad state.

public static readonly GamePadState Default

Field Value

GamePadState

Properties

Buttons

Gets a structure that identifies what buttons on the controller are pressed.

public readonly GamePadButtons Buttons { get; }

Property Value

GamePadButtons

The buttons structure.

DPad

Gets a structure that identifies what directions of the directional pad on the controller are pressed.

public readonly GamePadDPad DPad { get; }

Property Value

GamePadDPad

The directional pad structure.

IsConnected

Gets a value indicating if the controller is connected.

public readonly bool IsConnected { get; }

Property Value

bool

true if it is connected; otherwise, false.

PacketNumber

Gets the packet number associated with this state.

public readonly int PacketNumber { get; }

Property Value

int

The packet number.

ThumbSticks

Gets a structure that indicates the position of the controller sticks (thumbsticks).

public readonly GamePadThumbSticks ThumbSticks { get; }

Property Value

GamePadThumbSticks

The thumbsticks position.

Triggers

Gets a structure that identifies the position of triggers on the controller.

public readonly GamePadTriggers Triggers { get; }

Property Value

GamePadTriggers

Positions of the triggers.

Methods

Equals(object)

Determines whether the specified object is equal to the current GamePadState.

public override bool Equals(object obj)

Parameters

obj object

The object to compare with the current GamePadState.

Returns

bool

true if the specified object is equal to the current GamePadState; otherwise, false.

GetHashCode()

Serves as a hash function for a GamePadState object.

public override int GetHashCode()

Returns

int

A hash code for this instance that is suitable for use in hashing algorithms and data structures such as a hash table.

IsButtonDown(Buttons)

Determines whether specified input device buttons are pressed in this GamePadState.

public bool IsButtonDown(Buttons button)

Parameters

button Buttons

Buttons to query. Specify a single button, or combine multiple buttons using a bitwise OR operation.

Returns

bool

true, if button was pressed, false otherwise.

IsButtonUp(Buttons)

Determines whether specified input device buttons are released (not pressed) in this GamePadState.

public bool IsButtonUp(Buttons button)

Parameters

button Buttons

Buttons to query. Specify a single button, or combine multiple buttons using a bitwise OR operation.

Returns

bool

true, if button was released (not pressed), false otherwise.

ToString()

Returns a string that represents the current GamePadState.

public override string ToString()

Returns

string

A string that represents the current GamePadState.

Operators

operator ==(GamePadState, GamePadState)

Determines whether a specified instance of GamePadState is equal to another specified GamePadState.

public static bool operator ==(GamePadState left, GamePadState right)

Parameters

left GamePadState

The first GamePadState to compare.

right GamePadState

The second GamePadState to compare.

Returns

bool

true if left and right are equal; otherwise, false.

operator !=(GamePadState, GamePadState)

Determines whether a specified instance of GamePadState is not equal to another specified GamePadState.

public static bool operator !=(GamePadState left, GamePadState right)

Parameters

left GamePadState

The first GamePadState to compare.

right GamePadState

The second GamePadState to compare.

Returns

bool

true if left and right are not equal; otherwise, false.