Giter Club home page Giter Club logo

gamepadjs's Introduction

Gamepad API

Allows you to use gamepads in javascript.

Screen shot 1

Quick start

<script src=".../gamepad.js" type="text/javascript"></script>
var pad = Gamepads.get(0);

In the game loop, you have to put the following command.

It will update the state of all the connected gamepads.

Gamepads.update();

Properties

All the buttons/joysticks states are accessible like this:

Get a button state (replace X by a number). Return a value in the range [0..1]

pad.BUTTON_X;

Get a joystick state (replace X by a number). Return a value in the range [-1..1]

pad.AXE_X;

If the gamepad is known, you can access it with some user friendly names:

pad.A;
pad.B;
pad.X;
pad.Y;
pad.LEFT_SHOULDER_0;
pad.RIGHT_SHOULDER_0;
pad.LEFT_SHOULDER_1;
pad.RIGHT_SHOULDER_1;
pad.SELECT;
pad.START;
pad.LEFT_STICK_BUTTON;
pad.LEFT_STICK_BUTTON;
pad.UP;
pad.DOWN;
pad.LEFT;
pad.RIGHT;
pad.LEFT_STICK_X;
pad.LEFT_STICK_Y;
pad.RIGHT_STICK_X;
pad.RIGHT_STICK_Y;

Events

connected

pad.on('connected', function(evt) { console.log(evt); });
// {"index":0,"timestamp":1338874409909,"type":"connected"}

disconnected

pad.on('disconnected', function(evt) { console.log(evt); });
// {"timestamp":1338874409909,"type":"disconnected"}

axismove

pad.on('axismove', function(evt) { console.log(evt); });
// {"button":"RIGHT_STICK_X","timestamp":1338874409909,
// "type":"axismove","value":0.003921627998352051}

buttondown

pad.on('buttondown', function(evt) { console.log(evt); });
// {"button":"A","timestamp":1338873574415,"type":"buttondown"}

buttonup

pad.on('buttonup', function(evt) { console.log(evt); });
// {"button":"A","timestamp":1338873574415,"type":"buttonup"}

Author

Alain Gilbert (@alain_gilbert)

gamepadjs's People

Contributors

alaingilbert avatar

Watchers

Rob Gilson avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.