Search code examples
javascriptandroidgame-developmentjoystickmobile-browser

How to code a joystick controller for mobile browsers like in android games?


I am looking for a way to code a joystick controller for mobile browsers.

Like this one :

enter image description here

I have a browser-based game and it works somewhat okay when you have a keyboard.

However, for mobile, I need an improvement.

So I would like to code this such that when a user moves right with their fingers I want it to emulate as clicked d. So basically emulating a,s,d,w and if possible w+d (top+right) and other combinations.

So how can I achieve this? I have no idea where to begin with.


Solution

  • Maybe you could use this small library instead of coding your own joystick https://github.com/cptx032/virtual-joystick