Game Development Reference
In-Depth Information
Note
You can detect when the user presses the thumbstick buttons the same way
you do normal buttons on the gamepad, you just need to figure out which index
represents each thumbstick button. This is not normally a problem since most
games let the user bind game actions to whichever buttons or axes they want. In
other words, you should generally never hardcode the controls in your game as
they might not be correct or desirable for some players.
We've really only scratched the surface of using joysticks with DirectInput. Spend
some time exploring the various properties of the Joystick object that we stored
in our m_Joystick1 member variable. You'll see that it has a lot of other properties
we didn't use here. The X and Y properties, for example, will usually tell you what the
left joystick is doing. The RotationX and RotationY properties will usually tell you
the position of the right analog stick. A joystick has two axis as you can see. If the
joystick is not moved at all, it is centered, so its position reading will be in the center
of the ranges of both axis. If you push the joystick all the way to the right, it will be at
its maximum value on its horizontal axis. If you push it up all the way, it will be at the
minimum value for its vertical axis.
Note
You might expect the joystick's position to be (0,0) if you push it all the way up
and left, but it isn't. This is because most joysticks have a circular range of move-
ment and therefore the joystick will never be at the absolute upper-left corner of
the movement range defined by its pair of axes.
The Z property will usually give you the value for the axis that represents the trigger
buttons for gamepad style devices in most cases. If neither trigger is pressed, the
value is in the middle of the range. If the left trigger is completely pressed, the Z
property will have the maximum value for the axis, and of course if the right trigger
is completely pressed, then Z will have the minimum value for the range of this ax-
is. The range can vary and you can also modify stuff like this by messing with the
Properties property of the Joystick object (remember that you have to release
Search WWH ::




Custom Search