Game Development Reference
In-Depth Information
else
return StillReleased
end
end
end
With this function, it is then possible to check the KeyState of any key. Later
in this chapter, we will discuss an event-based system that builds on this. But for
now, let's move on to analog devices.
Analog Input
Because analog devices have a wide range of values, it is common to have spuri-
ous input. Suppose a joystick has its x and y values represented by a signed 16-bit
integer. This means both the x and y values can range from -32,768 to +32,767.
If the joystick is placed down on a flat surface and the player doesn't touch it, in
theory both the x and y values should be zero, because the joystick is not being
touched. However, in practice the values will be around zero, but rarely precisely
zero.
Because of this, if the raw analog input was just applied directly to the movement
of a character, the character would never stay still. This means you could put down
your controller yet still have your character move onscreen. To resolve this prob-
lem, most games implement some sort of analog filtering , which is designed to
eliminate spurious input data. Figure 5.2 illustrates how this filtering might be
used to implement a dead zone , which is an area around the center of the joystick
input range that is ignored.
Search WWH ::




Custom Search