1.0.1 • Published 7 years ago
holoplay-gamepad v1.0.1
holoplay-gamepad
A JavaScript library for listening to button press events from a Looking Glass display.

Usage
Setting up your event listener
var gamepad = new HoloPlayGamePad();
gamepad.on(eventName, callback);Setting up the game loop
//Game loop
function WatchForInput(){
gamepad.tick();
// Setup a callback for the next animation tick.
requestAnimationFrame(WatchForInput);
}
WatchForInput()Events
Listening to all buttons
To listen to all the buttons, the callback is passed the name of the button
buttonDown- Triggered once when the button is pressedbuttonPressed- Triggered on each timbuttonUp
Listening to individual buttons
Each button also has their own callback event.
SQUARE
squareDownsquarePressedsquareUp
LEFT
leftDownleftPressedleftUp
RIGHT
rightDownrightPressedrightUp
CIRCLE
circleDowncirclePressedcircleUp
Example
<html>
<head>
<!-- Bring in the GamePad.js dependencies, use `grunt install` -->
<script src="dependencies/GamePad/WebModule.js"></script>
<script>WebModule.publish = true;</script>
<script src="dependencies/GamePad/GamePadDevice.js"></script>
<script src="dependencies/GamePad/GamePad.js"></script>
<script src="dependencies/GamePad/GamePadPlayer.js"></script>
<!-- Bring in the holoplay-gamepad classes -->
<script src="lib/EventEmitter.js"></script>
<script src="lib/HoloPlayGamePad.js"></script>
<script>
var gamepad = new HoloPlayGamePad();
gamepad.on('buttonDown', function(name) {
document.getElementById("holoButton").innerText = name;
});
gamepad.on('buttonUp', function(name) {
document.getElementById("holoButton").innerText = '';
});
//Game loop
function WatchForInput(){
gamepad.tick();
// Setup a callback for the next animation tick.
requestAnimationFrame(WatchForInput);
}
WatchForInput()
</script>
</head>
<body>
Pressing:<span id="holoButton"></span>
</body>
</html>Try the example yourself:
git clone https://github.com/jaxzin/holoplay-gamepad.git
yarn install
grunt install
start/open index.html1.0.1
7 years ago