Game Development Reference
In-Depth Information
a device before you can change its properties). This range can vary from one con-
troller to the next.
What about the Directional Pad though (often called a D-Pad for short)? How you
handle these depends on how the controller reports it. Some may report the D-Pad
as normal buttons, in which case it would be handled in the same way as normal
buttons. Other controllers report the D-Pad as a POV (point of view) controller. In
this case, you can access it using the GetPointOfViewControllers() method
of the JoystickState object. It returns an int array. The first index represents
the first POV controller on your game controller. The value of the first element of the
array will change depending on which direction you are pressing. For mine, the first
element has the value 0 when I press up, 9,000 when I press to the right, 18,000
when I press down, and 27,000 when I press to the left on the D-Pad.
Note
Much of this can vary depending on the type of game controller you are using
and how DirectInput sees it. So, you may have to play around with different
properties in the JoystickState object (remember we stored ours in the
m_Joy1StateCurrent member variable) to find what you need.
Feel free to experiment with the debug code we just added into the Update() meth-
od. Experimentation is a great way to learn new things. Sometimes, it's quicker than
reading lots of boring documentation too! We won't fully cover DirectInput here as
that could fill an entire topic by itself.
The downloadable code for this chapter contains a bunch of handy joystick handling
methods added to our UserInput class. They include
DI_LeftStickPosition() , DI_RightStickPosition , and
DI_TriggersAxis() , among others. DI is of course short for DirectInput. The
TriggersAxis() method gets the current value of the axis that represents the trig-
gers (discussed earlier). The joystick methods get the current position of the joy-
sticks. For mine, each axis has a range of 0 to 65535 , and each joystick has two
axes of course (horizontal and vertical). When the joystick is not pressed at all, its
position will be in the center of both its horizontal and vertical axes.
Search WWH ::




Custom Search