GetJoystickX

From Spheriki

Jump to: navigation, search

Returns the normalized X coordinate of the given joystick, from -1 (full left) to 1 (full right).


Contents

Usage

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


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.


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