IsJoystickButtonPressed
From Spheriki
Detects whether a particular button of the given joystick is pressed or not.
Contents |
[edit]
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.
[edit]
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.
[edit]
Notes
- This function will return
trueif the button is indeed pressed, orfalseif 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.
[edit]
See also
- Abort()
- AreKeysLeft()
- CreateColor()
- FlipScreen()
- GetScreenHeight()
- GetScreenWidth()
- Rectangle()

