-
-
Save videlais/85e6fa9ccbc768026ddc to your computer and use it in GitHub Desktop.
Gamepad5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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