yoannmoinet / nipplejs

:video_game: A virtual joystick for touch capable interfaces.
https://yoannmoinet.github.io/nipplejs
MIT License
1.78k stars 185 forks source link

Option for Touch / mobile only - ignore desktop mouse events #173

Closed SmileyJames closed 2 years ago

SmileyJames commented 2 years ago

Is your feature request related to a problem? Please describe. For mobile touch devices nipple js is the perfect fit for controlling movement and view direction in my first-person game. But on desktop WASD and pointer lock mouse movement is more appropriate. Nipple.js is getting in the way for desktop users, and detecting if a device is mobile or desktop (to turn off nipple js) is difficult and discouraged by browser vendors.

Describe the solution you'd like I'd like an option to ignore MouseEvents and only respond to TouchEvents. Perhaps this is possible and I haven't spotted it?

Describe alternatives you've considered Detecting if desktop or mobile, to stop using nipple js on desktop. But generally this is not encouraged by browser vendors and leads to buggy behaviours.

Additional context Thanks for maintaining nipple js! I am very happy contribute for this feature

yoannmoinet commented 2 years ago

I don't think this needs to be done from within the library.

If you don't want the joystick on desktop, simply don't instantiate the lib when on desktop.

SmileyJames commented 2 years ago

But detecting if a browser is desktop or mobile is discouraged and difficult. However only responding to touch events not mouse events is simple. This article explains further the trouble with desktop detection: https://developer.mozilla.org/en-US/docs/Web/HTTP/Browser_detection_using_the_user_agent Also this article (sadly the https is broken but it's live if you accept the risk): https://www.stucox.com/blog/you-cant-detect-a-touchscreen/

yoannmoinet commented 2 years ago

This lib isn't aimed to detect wether the user is on desktop or mobile. So the logic for it will remain on your side.