The first command you should check is joystick_exists(1), which will tell you if a joystick is indeed plugged into the computer and registering. You can check joystick_exists(2) for two-player games. Using 0 for the argument is the same as using 1.
I see no use for checking the joystick name, since this seems to return a default Windows value. Some joystick software may change this, such as installing Logitech's drivers, but it's a pointless feature.
The next important joystick function to check is joystick_axes(1). This will tell you how many axes the joystick supports. GM can handle up to six axes. The old Commodore and Atari joysticks used one axis. Most modern joysticks have 4 axes. A DualShock2 has 4 and although the DualShock3 is advertised as a "SIX AXIS" controller, it only has 4 axes like its predecessor.
The axes are important when dealing with a controller. Looking at Logitech's Dual Action controller, we get the following information using GM's joystick functions.

The Dual Axis is a 4-axes controller with 12 buttons (more on that later). Notice the function joystick_has_pov(0). This is the reason a DualShock3 can be said to only have 4 axes. The fifth and sixth axes are treated as a POV button by GM. I am guessing this will always return TRUE, but if you find a joystick that returns FALSE, please let me know. Of course, much of this can be avoided by using simply joystick_direction(0), which compares the joystick's xpos and ypos to the keyboard's number pad, with numpad1=97 and numpad9=105. The resting value is 101, which is numpad5.
In this situation here, the analog button on my Dual Axis is off, so GM is reading all the joystick's functions as they exist by default. The left analog stick uses the first two axes, checked by joystick_xpos(0) and joystick_ypos(0). The right analog stick uses the third and fourth axes, checked by joystick_zpos(0) for the horizontal and joystick_rpos(0) (short for Z-axis rotation) for the vertical. In cases where a fifth and sixth axis do exist and are not treated as a POV button, GM uses joystick_upos(0) and joystick_vpos(0) respectively.
Like a DualShock2 controller, the Dual Axis has the two analog sticks and a directional pad. When the analog button is off, the directional pad is treated as a POV button, so its state is checked by the function joystick_pov(0). This function checks every 45 degrees, with 0 being up, 90 being right, 180 being down, and 270 being left. Bear in mind that this is contrary to how GM normally handles angles (0=right, 90=up, 180=left, 270=down). However, when the analog button is on, the directional pad and left analog stick are swapped. This means the directional pad will be checked by joystick_xpos(0)/joystick_ypos(0) and the left analog stick will be checked by joystick_pov(0).
The difficulty in using joystick support is actually in the GUI (graphic user interface). How do you show the player which function is mapped to which button when joysticks map buttons differently? That's for you to figure out. The Logitech Dual Action maps the Playstation as Square=1, Ex=2, Circle=3, Triangle=4. You can check your joystick's button mapping easily enough by running the Game Controllers control panel on Windows. Pushing down on an analog stick counts as a button press. Unfortunately, GM has no function to check if a joystick button is pressed or released.
Lastly, it is important to note when checking analog stick positions, analog sticks rarely reset to 0.00, so you should check analog stick position in multiples of 0.10 or 0.15. Any increment smaller than that could return a false positive. To find the angle of the analog stick, check use GM's trigonometric functions.
No comments:
Post a Comment