put the virtual joystick into the userInputManager and restricted it to touchscreens

This commit is contained in:
kharhamel 2021-04-16 18:49:04 +02:00
parent d7a74baa9d
commit 56287a2958
5 changed files with 54 additions and 40 deletions

View file

@ -408,26 +408,10 @@ export class GameScene extends ResizableScene implements CenterListener {
//initialise list of other player
this.MapPlayers = this.physics.add.group({immovable: true});
this.virtualJoystick = new VirtualJoystick(this, {
x: this.game.renderer.width / 2,
y: this.game.renderer.height / 2,
radius: 20,
base: this.add.circle(0, 0, 20),
thumb: this.add.circle(0, 0, 10),
enable: true,
dir: "8dir",
});
this.virtualJoystick.visible = true;
//create input to move
mediaManager.setUserInputManager(this.userInputManager);
this.userInputManager = new UserInputManager(this, this.virtualJoystick);
// Listener event to reposition virtual joystick
// whatever place you click in game area
this.input.on('pointerdown', (pointer: { x: number; y: number; }) => {
this.virtualJoystick.x = pointer.x;
this.virtualJoystick.y = pointer.y;
});
this.userInputManager = new UserInputManager(this);
if (localUserStore.getFullscreen()) {
document.querySelector('body')?.requestFullscreen();