项目作者: sawa-zen

项目描述 :
GamePad for canvas game.
高级语言: JavaScript
项目地址: git://github.com/sawa-zen/zenpad.js.git
创建时间: 2016-06-11T03:40:42Z
项目社区:https://github.com/sawa-zen/zenpad.js

开源协议:

下载


Zenpad.js — GamePad for canvas game.

wercker status
MIT License

The aim of the project is to create an easy to use gamepad library for <canvas>.

Demo

Usage

Prepare DOM for Zenpad.js.

  1. <div id="myZenpad"></div>

Install from script

  1. <script src="zenpad.js"></script>
  2. <script>
  3. var zenpad = new Zenpad('myZenpad');
  4. // ... see below
  5. </script>

Install from require

  1. var Zenpad = require('zenpad.js');
  2. var zenpad = new Zenpad('myZenpad');
  3. // ... see below

General

  1. zenpad.on('touchstartA', function() {
  2. console.info('touchstartA');
  3. });
  4. zenpad.on('moveStick', function(event) {
  5. console.info('moveStick', event.x);
  6. });

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.