Andrzej Mazur ‐ @end3r ‐ Enclave Games
Front-Trends — Warsaw, Poland — May 7-9th 2014
W3C Draft:
Editors:
Version 21+ (prefixes)
Version 29+ (Australis - April 29th 2014)
Version 24+ (prefixes⁄config)
GitHub Game Off II theme: Change
Privacy: interact first while the page is visible to get the event
window.addEventListener("gamepadconnected", function(e) {
console.log("Gamepad connected: "+e.gamepad.id);
});
window.addEventListener("gamepaddisconnected", function(e) {
console.log("Gamepad disconnected: "+e.gamepad.id);
});
id
- information about the controllerindex
- unique integer of the connected deviceconnected
- true if connectedmapping
- layout of the buttons, "standard"axes
- array of floating point values, state of each axisbuttons
- array of GamepadButton
objects, state of each button, pressed
and value
propertiesfunction addgamepad(gamepad) {
controllers[gamepad.index] = gamepad;
window.requestAnimationFrame(updateStatus);
}
function updateStatus() {
for(c in controllers) {
var controller = controllers[c];
for(var i=0; i<controller.buttons.length; i++) {
var buttonPressed = controller.buttons[i].pressed;
if(buttonPressed) {
console.log("Button id="+i+" was pressed");
} else {
console.log("Button id="+i+" was released");
}
}
}
}
Buttons: integer, 0 or 1.
Axes: float, -1 to 1.
Config.threshold = 0.5;