Andrzej Mazur — @end3r — Enclave Games
Hungarian Web Conference — Budapest, Hungary — November 8th 2014
W3C Working Draft
Editors
Version 21+ (prefixes)
Right now: 38
Version 29+ (Australis - April 29th 2014)
Version 24+ (prefixes⁄config)
Right now: 33
Version 24+
Right now: 25
No support
Shipped in IE Developer Channel
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;