Coder Social home page Coder Social logo

shroudedcode / contro Goto Github PK

View Code? Open in Web Editor NEW
52.0 3.0 7.0 502 KB

:video_game: Game controls done right.

Home Page: https://npm.im/contro

License: MIT License

JavaScript 5.08% TypeScript 94.92%
game-development javascript-library controls keyboard mouse gamepad zero-dependency

contro's People

Contributors

shroudedcode 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

Watchers

 avatar  avatar  avatar

contro's Issues

Show labels based on gamepad model

While on an Xbox controller the action buttons are called A, B, C, and D, on a PlayStation controller the action buttons are symbols (circle, square, ...). Contro should detect that and display the appropriate label.

These mappings might help.

doesn't work on mobile

my device:
OnePlus 3
Android 8.0.0
Chrome browser

gamepad: XBox controller.

here's the code. It is alerting 'a' in desktop chrome but not on mobile. I verified my gamepad is connected using https://html5gamepad.com/

const { Mouse, Keyboard, Gamepad, or, and } = Contro;

const gamepad = new Gamepad();


const controls = {
    a: gamepad.button('a').trigger,
    b: gamepad.button('b').trigger,
    left: gamepad.button('left').trigger
}

function gameLoop() {
    // Query the controls and do something
    if (controls.a.query()) {
        console.log('a');
        alert('a')
    }
    if (controls.b.query()) {
        console.log('b');
    }
    if (controls.left.query()) {
        console.log('left')
        alert('left')
    }

    requestAnimationFrame(gameLoop)
}



requestAnimationFrame(gameLoop)

add listeners

for using contro without game loops it might come in handy

more?

Hey it's possible to add detection of more gamepads?

8bitdo Support

I've attempted to use the demo with my 8bitdo wireless controller. It doesn't appear to recognize the connection. The button labels don't change when connected, nor do they respond to input from the gamepad. I've tried this on bluetooth and USB using Windows 10, Chrome.

I hate to open an issue for something basic, but I do see input working with the controller using this: https://html5gamepad.com/

Looking at your code, it uses most of the same stuff.

Custom inputs?

Hi,

I really like this lib, nice work!

I propose an addition to the API/doc - a way to add custom inputs.

This is useful for when having the same game played on mobile.

Stick Error

Hello, whenever I do gamepad.stick("left").query() I get this error: Uncaught (in promise) TypeError: Cannot read property 'timestamp' of undefined

Why?

Supporting non-standard layouts, scoped keypresses, composing gamepads?

Hello, thanks for a great library and extensive tests! I have been using it to allow blind people to play video games with a gamepad.

I ran into a few limitations and after a failed attempt to add some of them to contro, I ended up writing some code that is similar to contro but has the following features:

  • uses the standard layout to explicitly to buttons and sticks
  • supports gamepads that do not use the standard layout
    • some browsers like Firefox do not provide a standard mapping
    • uses mapping files to support non-standard gamepads
  • allows checking if a specific button is available on the gamepad
  • allows composing buttons, sticks, and even gamepads to make it easier to write games
  • allows scoping the key presses so they only apply when the game is in focus (being played)
  • allows disposing of keyboard buttons when they are no longer needed

I was not sure if some of those were problems others have run into and if you would be interested in a Pull Request to contro with those changes. If you are interested, I can create one and add tests.

Also, here is the README for the code.

Again, thanks for such an elegant library!

refs #2

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.