GamePadState
The GamePadState structure for the GamePad class has the follow
-
ing members:
The Buttons member is a structure that contains members for each
of the controls on a gamepad — A, B, Back, LeftShoulder, LeftStick,
RightShoulder, RightStick, Start, X, and Y. Each of these members
is a ButtonState enum value that has two possibilities, Pressed and
Released.
The DPad member is another structure set up exactly the same;
it has four ButtonState type members in a structure for each of the
four directions in the D-pad.
The IsConnected member is self-explanatory. If for some reason
the gamepad were disconnected, you wouldn’t want to try to cap
-
ture data and you would probably even want to pause the game and
display a message asking the player to reconnect the controller.
PacketNumber is an integer value that you can use to determine
if the state of the device has changed, rather than checking the con
-
trols themselves. So you could do something like:
Listing 4-2
if (GamePad.GetState(PlayerIndex.One).
PacketNumber != _curPacketNum)
{
//check controls
//save the new packet number
_curPacketNum = GamePad.GetState(PlayerIndex.One).
PacketNumber;
}
Input 115
Figure 4-2

Get Essential XNA Game Studio 2.0 Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.