GetJoystickX
From Spheriki
Returns the normalized X coordinate of the given joystick, from -1 (full left) to 1 (full right).
Contents |
[edit]
Usage
number GetJoystickX(joy);
- joy Number, non-negative. Index of joystick to check X coordinate of.
[edit]
Examples
if (GetNumJoysticks() > 0)
{
var scr_w = GetScreenWidth();
var scr_h = GetScreenHeight();
var white = CreateColor(255, 255, 255);
while (!AreKeysLeft())
{
var x = (GetJoystickX(0) + 1) * 0.5 * scr_w;
Rectangle(x - 4, scr_h * 0.5 - 4, 8, 8, white);
FlipScreen();
}
}
else
Abort("No joysticks detected.");
The above example will allow the player to move a small square on the screen left and right, using the first joystick detected. Pressing a key will cause the demo to end.
[edit]
Notes
- Use the GetNumJoysticks() function to find the valid range of the argument
joy.
- The equivalent function for the Y axis is GetJoystickY().
- Many players will not have access to a joystick, so joystick input should be provided as an alternative to keyboard or mouse input, rather than a substitute.
[edit]
See also
- Abort()
- AreKeysLeft()
- CreateColor()
- FlipScreen()
- GetScreenHeight()
- GetScreenWidth()
- Rectangle()

