Improving Input with Joysticks
(Page 1 of 7 )
When designing games, it's important to know how to interpret and respond to joystick input in your own games. Learn how to properly calibrate a joystick in Windows XP, how to add joystick support to the game engine, and more. (From
Beginning Game Programming, by Michael Morrison, 2005, Sams, ISBN: 0672326590.)
Note - Released in 1980 by Atari, Centipede is one of the first games to rely on a trackball for user input. Centipede was quite popular in its day and still has some devoted fans. Centipede owns the distinction of being the first video game created by a woman, Dona Bailey, which is no small feat considering how few women worked in the video game industry in its early days.
From its inception, the joystick has been used chiefly as an input device for game systems. Admittedly, its name alone limits its usage to the entertainment industry, as I doubt too many accountants would purchase a "joystick" for crunching numbers in a spreadsheet. At any rate, joysticks and game pads both play an important role in modern video games of all kinds, including computer games. For this reason, it's important for you to have an understanding of how to interpret and respond to joystick input in your own games. This chapter introduces you to joysticks and what makes them tick, along with providing you with the knowledge and source code to handle joystick input in games.
In this chapter, you'll learn
The basics of responding to joystick input in games
How to properly calibrate a joystick in Windows XP
How to add joystick support to the game engine
How to use the new and improved game engine to create interesting programs that respond to a joystick
Understanding 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 have up to six axes. Fortunately, we aren't going to worry about more than two joystick axes in this chapter, which helps simplify things considerably.
Note - 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 from 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 3D space, such as with 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 mouse devices are capable of supporting multiple buttons (typically three at most), joysticks are also capable of having several buttons. In fact, joysticks are much more flexible than mouse devices in terms of how many buttons they can have; joysticks in Windows are allowed to have up to 32 buttons. It would probably take super-human memory skills and hand/eye coordination to figure out how to use a joystick with that many buttons, but the option is there if someone wants to make a joystick for the truly gifted among us. 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 and keyboard key presses, handling joystick button presses is relatively straightforward, as you learn a little later in the chapter.
This chapter is from Beginning Game Programming, by Michael Morrison (Sams, ISBN: 0672326590). Check it out at your favorite bookstore today.
Buy this book now. |
Next: Calibrating Joysticks >>
More PC Gaming Articles
More By Sams Publishing
| Recommended by Dev Hardware |
|---|
|