joystick_direction()
(Game Maker 6.1, 7)
joystick_direction - check the direction of joystick or gamepad.
Description
keycode joystick_direction ( joynum )
- keycode - keycode of direction, as a number
- joynum - number of joystick, as a number (either 1 or 2)
joystick_direction() checks the current direction of a joystick or gamepad and translates it into a virtual keycode relating to the numpad. Game Maker only supports two joysticks and which one you want to check has to be provided as its argument as either a 1 (for joystick 1) or 2, (for joystick 2).
The directions and the corresponding keycode constants are :
- no direction - numpad5
- right - numpad6
- up/right - numpad9
- up - numpad8
- up/left - numpad7
- left - numpad4
- left/down - numpad1
- down - numpad2
Examples
Example of Use
direction_held = joystick_direction(1);
In this example, the value of direction_held will be the direction held on joystick 1. If left were held on joystick 1, it will return the same numeric value as held in the keycode constant numpad4.
Checking for Input
If you want to check the direction of a joystick for use in games, you can check it against one of the keycode constants in an if statement :
if(joystick_direction(1) == numpad6)
{
//do something
}
In this code, if the direction held on joystick 1 is right, the code //do something will be executed.