niklashigi / contro

:video_game: Game controls done right.
https://npm.im/contro
MIT License
53 stars 7 forks source link

Incorrect documentation on stick #6

Closed quinton-ashley closed 6 years ago

quinton-ashley commented 6 years ago

https://github.com/shroudedcode/contro/blob/fd07ebca71906848740ebd5c1dae11b39d921282/docs/components/gamepad.md

The docs says buttons and sticks can be queried gamepad.button('A').query()
gamepad.stick('left').query()

but sticks can't, the stick function returns the vector object gamepad.stick('left')

quinton-ashley commented 6 years ago

Thanks!

quinton-ashley commented 6 years ago

Wait it's not on npm yet. Could you publish the update on npm or are you working on other changes too?

Also just wanted to say Contro is awesome and the best gamepad web api wrapper library by far! I'm using Contro with bottlenose. I like that it can actually handle controllers that are already connected unlike html5-gamepad.

niklashigi commented 6 years ago

I just merged the pull request (couldn't do that yesterday because I forgot a documentation change and had to head off) and a new version was released. Please note that although I published it as a minor version change (v1.2.2), it actually contains a breaking change since you have to call .query() now.

Also, thanks a lot! If you have any ideas on how to improve this library, let me know. I really want Contro to be a single solution to all of the JavaScript game developer's input handling needs.

quinton-ashley commented 6 years ago

Awesome! I think it'd be helpful to have methods, like trigger, but for press ended and press held too. This could be done by storing button press state changes and then making comparisons to the result of query(). I made an example from your demo on code pen.

Speaking of triggers, query() on analog triggers should return analog values (like sticks do) and a trigger that returns a boolean value for a full press down on controllers like the Xbox One that have analog triggers.

Also in the example I just wanted to show how easy it was to re-map the Xbox One controller button layout to the button layout of the Nintendo Switch and other Nintendo systems if anyone's interested.

https://codepen.io/qashto/pen/XxJBEK

niklashigi commented 6 years ago

I think it'd be helpful to have methods, like trigger, but for press ended and press held too

I understand why press ended would be useful, but what's the use case for press held? If I understand correctly, the only difference between press held and the default control would be that on the first "tick" press held returns false. I'm not sure where one would need that kind of behavior.

query() on analog triggers should return analog values (like sticks do) and a trigger that returns a boolean value for a full press down

Feel free to implement this and open a pull request (if you wait until tomorrow, that would even count towards your Hacktoberfest PRs). I don't really have the time to implement new features for Contro at the moment because of school and more urgent projects. I would, however, be willing to answer any of your questions.

quinton-ashley commented 6 years ago

Maybe the game implements one action when a button has shortly pressed and another when it's held for a while. Press held could return the amount of time the button has been held instead of true/false. I can't PR rn since I'm busy working on bottlenose but maybe in a month or so I will.