Left, top, right and bottom movement controls in mobile?

I am doing a game on space ship battle, it works fine on the desktop with the keys of the keyboard. in case of mobile, I want it to be done on the touch of the canvas as of that pointer x and y the player should move left, right, top and bottom.

I would suggest detecting pointers in relation to the player.

For example

this.input.on(‘pointerdown’,this.movePlayer.bind(this));

 movePlayer(pointer) {
        if (pointer.x < this.player.x) {
            //move left 
            player.x--;
        }
    }
1 Like

i did it in same way but i am not satisfied with the scenario below
player.x = 10;
pointer.x = 30;
pointer.y = -30;

while moving the player it is not looking good. hope you got what i meant to say here.