Game Development Reference
In-Depth Information
auto btnState = state.Gamepad.wButtons;
if (btnState & XINPUT_GAMEPAD_DPAD_UP)
{
_sidePressed = -1;
}
else if (btnState &
XINPUT_GAMEPAD_DPAD_DOWN)
{
_sidePressed = 1;
}
else
{
float thumbY = state.Gamepad.sThumbLY;
float magnitude = abs(thumbY);
if (magnitude >
XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE)
{
if (thumbY > 0)
_sidePressed = -1;
else
_sidePressed = 1;
}
else
{
_sidePressed = 0;
}
}
}
}
}
Multiple controllers
Upto four controllers can be connected to one machine, as indicated by the
XUSER_MAX_COUNT constant provided by XInput. We can work with all of the con-
trollers by looping through all of them and retrieving their state using the XIn-
putGetState() method. This method takes the integer index of the controller we
Search WWH ::




Custom Search