IsJoystickButtonPressed

From Spheriki

Jump to: navigation, search

Detects whether a particular button of the given joystick is pressed or not.


Contents

Usage

boolean IsJoystickButtonPressed(joy, button);
  • joy Number, non-negative. Index of the joystick to check the button of.
  • button Number, non-negative. Index of the button to check.


Examples

if (GetNumJoysticks() > 0)
{
  var scr_w = GetScreenWidth();
  var scr_h = GetScreenHeight();
  var white = CreateColor(255, 255, 255);
  var button_count = GetNumJoystickButtons(0);
  var bar_width = scr_w / button_count;
  
  while (!AreKeysLeft())
  {
    for (var i = 0; i < button_count; ++i)
      if (IsJoystickButtonPressed(0, i))
        Rectangle(bar_width * i, 0, bar_width, scr_h, white);
    FlipScreen();
  }
}
else
  Abort("No joysticks detected.");

The above example will allow the player to press buttons on their joystick, and see vertical bars appear on the screen. Pressing a keyboard key will end the demo.


Notes

  • This function will return true if the button is indeed pressed, or false if it is not.
  • 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