I have a bluetooth controller in which I've tested all the numbers of the buttons with this Gamepad tester: http://html5gamepad.com/, so I'm pretty sure the values of the buttons are correct. However, nothing seems to fire, the Gamepad is shown to be "connected", just the button events not working. Below is the code:
function gameLoop() {
if (navigator.webkitGetGamepads) {
var wgp = navigator.webkitGetGamepads()[0];
if (wgp.buttons[12] == 1 || wgp.buttons[4] == 1) {
console.log('move');
}
};
gameLoop();
Where could I have wrong? I'm using Chrome so I have the webkit prefix. Could the Gamepad tester be showing me the wrong buttons? Thanks for your help.
Had similar issue. Inspecting the code at gamepad.js/all.js.cofee highlighted that we need to retrieve gamepads from
navigator
on every update cycle (they don't auto-update), make sure yourgameLoop()
is called repeatedly. For example inwindow.setInterval(gameLoop, 100)
orwindow.requestAnimationFrame(gameLoop)
Reference: