HTML and CSS Reference
In-Depth Information
if(button == 1) { // button[1] is B or O
GAME.startNewGame();
}
}
else {
console.log("Button "+button+" was released.");
}
},
axisPressed: function(event) {
var axis = event.axis;
var value = event.value;
console.log("Axis: "+axis+", value: "+value+".");
}
};
/* Here are all the event listeners: */
window.addEventListener("gamepadconnected", function(e) {
gamepadAPI.gamepadConnected(e);
});
window.addEventListener("gamepaddisconnected", function(e) {
gamepadAPI.gamepadDisconnected(e);
});
window.addEventListener("gamepadbuttondown", function(e) {
gamepadAPI.buttonPressed(e, true);
});
window.addEventListener("gamepadbuttonup", function(e) {
gamepadAPI.buttonPressed(e, false);
});
window.addEventListener("gamepadaxismove", function(e){
gamepadAPI.axisPressed(e);
});
/* Let's create a GAME object for our game */
var GAME = {};
/* Here's the function that will start our game */
GAME.startNewGame = function(){
alert("New game started!");
}
</script>
</body>
</html>
That's it; you have created a fully working test case. Connecting the gamepad and pressing the buttons will print
the output in the browser's JavaScript console. You can now add this to your game or start implementing new game on
top of this.
Search WWH ::




Custom Search