# holoplay-gamepad

> A library for getting events from the Looking Glass buttons.

Latest version **1.0.1** (published 2019-02-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install holoplay-gamepad
pnpm add holoplay-gamepad
yarn add holoplay-gamepad
bun add holoplay-gamepad
```

## Health

**Score 5/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: insecure dependencies; abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2019-02-19 |
| First published | 2019-02-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 8.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Brian R. Jackson |
| Maintainers | jaxzin |

## Links

- npm: https://www.npmjs.com/package/holoplay-gamepad
- Repository: https://github.com/jaxzin/holoplay-gamepad
- npm.io page: https://npm.io/package/holoplay-gamepad

## Dependencies (1)

- [uupaa.gamepad.js](https://npm.io/package/uupaa.gamepad.js.md) github:jaxzin/GamePad.js#add-holoplay

## Recent versions

- 1.0.1 (latest) — 2019-02-19

## README

holoplay-gamepad
--------------------
A JavaScript library for listening to button press events from a [Looking Glass display](https://lookingglassfactory.com).

![The Looking Glass](https://i.ytimg.com/vi/htFotQi_-jY/maxresdefault.jpg)

# Usage

### Setting up your event listener
```javascript
var gamepad = new HoloPlayGamePad();
gamepad.on(eventName, callback);
```

### Setting up the game loop
```javascript
//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 pressed
  * `buttonPressed` - Triggered on each tim
  * `buttonUp`
  
### Listening to individual buttons
Each button also has their own callback event.
#### SQUARE
* `squareDown`
* `squarePressed`
* `squareUp`
#### LEFT
* `leftDown`
* `leftPressed`
* `leftUp`
#### RIGHT
* `rightDown`
* `rightPressed`
* `rightUp`
#### CIRCLE
* `circleDown`
* `circlePressed`
* `circleUp`

## Example

```html
<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:
```bash
git clone https://github.com/jaxzin/holoplay-gamepad.git
yarn install
grunt install
start/open index.html
```

---
_Source: https://npm.io/package/holoplay-gamepad · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
