Joystick Basics


The concept of a joystick is straightforward, although you might be surprised by how loosely a joystick is defined in terms of Windows programming. In Windows, a joystick is a physical input device that allows variable movement along different axes with multiple pushbuttons. That's the geeky description of a joystick. What it means is that a joystick is an input device that can move in several different directions. Notice that I said several directions, not just two. Although a traditional joystick is thought of in terms of two axes (X and Y), a joystick in Windows can actually go up to six axes. Fortunately, we aren't going to worry about more than two joystick axes in this hour , which helps simplify things considerably.

graphics/book.gif

The six possible joystick axes supported by Windows can be arranged in many different ways. A traditional joystick has two axes that correspond to moving the joystick handle side to side (one axis) and forward and back (another axis). A third axis of movement can be added by allowing the joystick handle to be pushed and pulled vertically. A fourth axis can be the twisting of the joystick handle. The fifth and sixth axes apply to more advanced input devices, and are typically used for keeping track of moving the entire joystick in space, like an input glove.


Because a traditional joystick has only two axes of motion, you can think of the joystick in much the same way as you think of the mouse. Although a mouse can be moved in any direction, its movement is limited to a single plane. In other words, you can always resolve mouse movement into an XY value. Joysticks are similar in this manner because you can identify their movement according to how far the handle is being pushed along each axis. If side to side movement is along the x axis and forward and back movement is along the y axis, a joystick can be tracked in a manner similar to the mouse by using an XY value.

Also similar to the mouse are the buttons on a joystick. Just as mice are capable of supporting multiple buttons (typically three), joysticks are also capable of having several buttons. In fact, joysticks are much more flexible than mice in terms of how many buttons they can have; joysticks in Windows are allowed to have up to 32 buttons . I personally wouldn't want to try and figure out how to use a joystick with that many buttons, but the option is there if someone wants to make a joystick for super humans . A more realistic number for joystick buttons is six, which is still a lot to keep track of for the average game player. Similar to mouse button presses and keyboard key presses, handling joystick button presses is relatively straightforward, as you learn a little later in the hour.



Sams Teach Yourself Game Programming in 24 Hours
Sams Teach Yourself Game Programming in 24 Hours
ISBN: 067232461X
EAN: 2147483647
Year: 2002
Pages: 271

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net