Skip to content

Instantly share code, notes, and snippets.

@videlais
Created December 24, 2013 07:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save videlais/85e6fa9ccbc768026ddc to your computer and use it in GitHub Desktop.
Save videlais/85e6fa9ccbc768026ddc to your computer and use it in GitHub Desktop.
Gamepad5
/**
* Returns if a specific button on a certain gamepad was pressed
* @param {number} pad The Gamepad to check
* @param {string} buttonId The button to check
* @returns {boolean} If the button on the specific gamepad is currently pressed
*/
self.pressed = function(pad, buttonId) {
if (self.gamepads[pad] && BUTTONS[buttonId]) {
var buttonIndex = BUTTONS[buttonId];
if (buttonIndex === 4 || buttonIndex === 5) {
return self.gamepads[pad].buttons[buttonIndex] > self.SHOULDER0_BUTTON_THRESHOLD;
} else if (buttonIndex === 6 || buttonIndex === 7) {
return self.gamepads[pad].buttons[buttonIndex] > self.SHOULDER1_BUTTON_THRESHOLD;
} else {
return self.gamepads[pad].buttons[buttonIndex] > 0.5;
}
} else {
return false;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment