GithubHelp home page GithubHelp logo

luser / gamepadtest Goto Github PK

View Code? Open in Web Editor NEW
251.0 14.0 101.0 10 KB

Gamepad API Test

Home Page: https://luser.github.io/gamepadtest/

License: Creative Commons Zero v1.0 Universal

JavaScript 70.56% HTML 29.44%

gamepadtest's Introduction

This is a simple demo of using the Gamepad API in JavaScript. It attempts to account for differences in implementations of the unfinished spec, as well as Chrome's prefixed implementation.

Gamepad API Test

Written in 2013 by Ted Mielczarek [email protected]

To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this software to the public domain worldwide. This software is distributed without any warranty.

You should have received a copy of the CC0 Public Domain Dedication along with this software. If not, see http://creativecommons.org/publicdomain/zero/1.0/.

gamepadtest's People

Contributors

arimeq avatar luser avatar nondebug avatar toji avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gamepadtest's Issues

Inconsistent formatting

Code has inconsistent formatting, for example you use spacer in for loops or don't
line 93 for (var i=0; i<controller.axes.length; i++) {
line 104 for (var i = 0; i < gamepads.length; i++) {

Confusing css class name changes in javascript

If I understood it correctly, the code overrides the className with every loop iteration.
b.className = "button"; is used to remove the "pressed" class.

To make it more clear, you could use the add and remove methods of classList property.
instead use buttonElement.classList.remove('pressed');
also utilize buttonElement.classList.add('pressed'); when it's needed.

Chrome sniffing is completely unnecessary

There's no need at all for separate Chrome/Firefox code paths here. Just check navigator.getGamepads() instead of storing Event.gamepad, and the same code works exactly the same way for both.

Broken in Chrome Canary

Chrome added support for gamepadconnected/gamepaddisconnected events, but something is not working right, as nothing shows up. This is in Chrome Canary 36.0.1964.2. Not sure if this is a bug in my code or in Chrome. Works fine in 34.0.1847.131 on the same machine.

@toji, @sgraham, any thoughts?

Display axis bar including digital value.

Thank you awesome example program.
I have changed axis bar too convinient.

To display Axis bar including digital number value, add CSS.

.axis::before {
min-height: 14px;
content: attr(num);
color: red;
vertical-align: text-top;
font-size: x-small;
font-weight: bold;
margin-left: 3px;
}

And rewrite part of addgamepad function for "num" attribute,

var b = $("<div class='buttons'>");
for (var i=0; i<gamepad.buttons.length; i++) {
var e = $("<span class='button'>"+i+"</span>");
b.append(e);
}
d.append(b);
var a = $("<div class='axes'>");
for (i=0; i<gamepad.axes.length; i++) {
e = $("<progress class='axis'>",{"max":"2","value":"1","num":"ax"+i});
a.append(e);
}
d.append(a);
document.body.appendChild(d[0]);
rAF(updateStatus);

And updatestatus function too,
var a = axes[i];
a.setAttribute("max", "2");
a.setAttribute("num", "ax"+i+ ": " + controller.axes[i].toFixed(4));
a.setAttribute("value", controller.axes[i] + 1);

Thank you.

Vibration

It would be nice to have a button that vibrates the controller.

before contributing

Hi, first thanks for this awesome demo!

Would you accept a pull request with the following commits ? :

  • Replace <progress> with <meter>
  • Rename variables that uses single letter with more descriptive names
  • performance optimizations

Also another question: Is window.addEventListener("gamepadconnected", connecthandler); window.addEventListener("gamepaddisconnected", disconnecthandler); useless considering scangamepads(); is called all the time in the requestAnimationFrame ? Or am I missing something ?

Xbox one controller

I am using an xbox one controller, but it's showing that I'm using Xbox 360 controller.
screenshot

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.