Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/sawa-zen/zenpad.js

GamePad for canvas game.
https://github.com/sawa-zen/zenpad.js

canvas gamedev gamepad npm-package webgl

Last synced: about 1 month ago
JSON representation

GamePad for canvas game.

Awesome Lists containing this project

README

        

# Zenpad.js — GamePad for canvas game.

![](zenpad_demo.gif)

[![wercker status](https://app.wercker.com/status/6764b7988a279822959e792434e70223/s/master "wercker status")](https://app.wercker.com/project/byKey/6764b7988a279822959e792434e70223)
[![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE)

The aim of the project is to create an easy to use gamepad library for ``.

### Demo

- [http://zendash.sawa-zen.com/](http://zendash.sawa-zen.com/)
- [http://zenpad.sawa-zen.com/demo/](http://zenpad.sawa-zen.com/demo/)

### Usage

Prepare DOM for Zenpad.js.

```html


```

#### Install from script

```html

var zenpad = new Zenpad('myZenpad');
// ... see below

```

#### Install from require

```javascript
var Zenpad = require('zenpad.js');
var zenpad = new Zenpad('myZenpad');
// ... see below
```

#### General

```javascript
zenpad.on('touchstartA', function() {
console.info('touchstartA');
});

zenpad.on('moveStick', function(event) {
console.info('moveStick', event.x);
});
```

### Method

- **on(eventName:String, handler:Function)**

Use to add events.

- **off(eventName:String, handler:Function)**

Use to remove events.

- **dispose()**

Use to dispose zenpad.

### Event

- **touchstartA**

Emit "touchstartA" event when push "A" button.

- **touchendA**

Emit "touchendA" event when pull "A" button.

- **clickA**

This is "touchendA" alias event.

- **touchstartB**

Emit "touchstartB" event when push "B" button.

- **touchendB**

Emit "touchendB" event when pull "B" button.

- **clickB**

This is "touchendB" alias event.

- **moveStick**

Emit "moveStick" event when move stick.

**Property**
- **x** : It is "x" position of stick.
- **y** : It is "y" position of stick.
- **angle** : It is the angle where the stick was knocked down.
- **length** : It is the distance between the stick and the center.

- **releaseStick**

Emit "releaseStick" event when stick is released.