Game Development Reference
In-Depth Information
saying so in Visual Studio's Output pane. The second if statement does this for the
B button, and the last two if statements do the same for the X and Y buttons.
You may have noticed that we didn't have to acquire the XInput controller at the be-
ginning of the Update() method like we do with the mouse, keyboard, and joysticks
under DirectInput. Instead, we simply set up the XInput controller in our InitXIn-
put() method. You may also have noticed that we didn't need to add code in our
Dispose(bool) method to dispose of the XInput controller object either. It doesn't
even have a Dispose() method.
We are now ready to test our new code. You will need an XInput compatible control-
ler to test it. If you don't have one, this code will still run, but it just won't do anything
since there's no XInput controller for it to get input from.
If you have a controller that supports XInput, you may see dual output from this code
because both the DirectInput and the XInput test code will be outputting debug mes-
sages to Visual Studio's Output pane at the same time (if both are reading input
from the same controller), as shown in the following screenshot:
DirectInput and XInput both reading input from the same device
We have once again only really scratched the surface here. There is more to XInput
than what we've looked at. For example, you can get the state of the left and right
sticks by accessing the LeftThumbX and LeftThumbY properties for the left stick,
Search WWH ::




Custom Search