GetJoystickY

From Spheriki

Jump to: navigation, search

Returns the normalized Y coordinate of the given joystick, from -1 (full up) to 1 (full down).


Contents

Usage

number GetJoystickY(joy);
  • joy Number, non-negative. Index of joystick to check Y coordinate of.


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.


Notes

  • Use the GetNumJoysticks() function to find the valid range of the argument joy.
  • 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.


See also

Personal tools