Game Development Reference
In-Depth Information
Chapter 2. Responding to Player Inputs
Games by their very nature are interactive. They can respond to user input, unlike
movies which play out exactly the same every time. So, you need a way to detect and
respond to the user's input via mouse, keyboard, or gamepad. How can we accom-
plish this in our game? There are two options we can use for this: DirectInput and
XInput .
In this chapter, we will cover the following topics:
• DirectInput versus XInput
• Mouse and keyboard input
• Using joysticks with DirectInput
• Using joysticks with XInput
DirectInput versus XInput
So, which of these two options should we use? The answer is possibly both. Why
both, you ask? The reason is that we need to use DirectInput to support older
input devices that don't support the new features of XInput. An input device is any
device that the user uses to provide input to the game, such as a mouse, keyboard,
gamepad, and steering wheel.
We could just use DirectInput, but this approach has some limitations. DirectInput can
handle XInput devices, but the left and right trigger buttons on a gamepad will be
treated as a single button. One trigger is treated as the positive direction and the oth-
er as the negative direction. So, the two triggers are treated together as a single axis.
DirectInput also does not support XInput vibration effects, and you cannot query for
headset devices. On the flip side, we could just use XInput but then people with older
DirectInput devices would not be able to play our game with them.
To support these features of newer input devices, we will need to use XInput along
with DirectInput. This allows people with XInput devices to take advantage of their
new features, while at the same time allowing users with older DirectInput devices to
still be able to play our game with them. The players will undoubtedly appreciate this.
So, what is the true difference between DirectInput and XInput? XInput is geared spe-
cifically towards Xbox 360 controllers and specialized Xbox 360 controllers, such as
Search WWH ::




Custom Search