-
-
Save videlais/9d8ccc2f02baa502bc86 to your computer and use it in GitHub Desktop.
Gamepad6
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 the amount of movement from the deadzone (-1 to 1) | |
* @param {number} pad The Gamepad to check | |
* @param {string} axisId The axis and dimension to check | |
* @returns {number} The amount of movement, if any | |
*/ | |
self.moved = function(pad, axisId) { | |
if (self.gamepads[pad]) { | |
if (axisId === "LEFT_X") { | |
if (self.gamepads[pad].axes[0] < -self.LEFT_AXIS_THRESHOLD || | |
self.gamepads[pad].axes[0] > self.LEFT_AXIS_THRESHOLD) { | |
return self.gamepads[pad].axes[0]; | |
} | |
} else if (axisId === "LEFT_Y") { | |
if (self.gamepads[pad].axes[1] < -self.LEFT_AXIS_THRESHOLD || | |
self.gamepads[pad].axes[1] > self.LEFT_AXIS_THRESHOLD) { | |
return self.gamepads[pad].axes[1]; | |
} | |
} else if (axisId === "RIGHT_X") { | |
if (self.gamepads[pad].axes[2] < -self.RIGHT_AXIS_THRESHOLD || | |
self.gamepads[pad].axes[2] > self.RIGHT_AXIS_THRESHOLD) { | |
return self.gamepads[pad].axes[2]; | |
} | |
} else if (axisId === "RIGHT_Y") { | |
if (self.gamepads[pad].axes[3] < -self.RIGHT_AXIS_THRESHOLD || | |
self.gamepads[pad].axes[3] > self.RIGHT_AXIS_THRESHOLD) { | |
return self.gamepads[pad].axes[3]; | |
} | |
} | |
} else { | |
return 0; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment