GetJoystickY
From Spheriki
Returns the normalized Y coordinate of the given joystick, from -1 (full up) to 1 (full down).
Contents |
[edit]
Usage
number GetJoystickY(joy);
- joy Number, non-negative. Index of joystick to check Y coordinate of.
[edit]
Examples
if (GetNumJoysticks() > 0)
{
var scr_w = GetScreenWidth();
var scr_h = GetScreenHeight();
var white = CreateColor(255, 255, 255);
while (!AreKeysLeft())
{
var y = (GetJoystickY(0) + 1) * 0.5 * scr_h;
Rectangle(scr_w * 0.5 - 4, y - 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 up and down, 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 X axis is GetJoystickX().
- 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()

