Game Development Reference
In-Depth Information
GamePad input
Windows 8 provides native support for the Xbox 360 Controller. In most cases this
will be wired; however, a wireless dongle can be acquired to allow standard wireless
controllers to be used with a PC. A simple to use C API is provided that allows you
to work with multiple controllers, retrieve states, and set the vibration motors on the
controller so that physical feedback can be provided to the player, as required in the
game.
XInput, the API for the Xbox 360 Controller, is your best option for adding GamePad
support, and to get started with it we just need to include a single include file and link
a static library. Inside pch.h , we'll add the following lines of code:
#include <Xinput.h>
#pragma comment(lib, "Xinput.lib")
Now we can get started with the controller. The Xbox 360 Controller provides a num-
ber of buttons and triggers to enable a variety of gameplay scenarios. We're just work-
ing on a simple game so we don't need to worry about all of the options. In this case
we'll be supporting the vertical axis on the left thumbstick, and the up/down D-Pad
buttons. They are shown in the following table:
You can find a reference for all of the buttons on the GamePad at ht-
tp://msdn.microsoft.com/en-us/library/windows/apps/mi-
crosoft.directx_sdk.reference.xinput_gamepad
Button/Con-
trol
Description
Values
Left/right
thumbstick
Analog stick(s) providing x/y axis information
-32,768 -
32,767
Search WWH ::




Custom Search