Add joystick & click to move on disable controls

This commit is contained in:
Alexis Faizeau 2022-05-06 15:29:20 +02:00 committed by David Négrier
parent fc7a7aa54d
commit c96c6a357c
2 changed files with 11 additions and 2 deletions

View File

@ -25,6 +25,11 @@ export class GameSceneUserInputHandler implements UserInputHandlerInterface {
if ((!pointer.wasTouch && pointer.leftButtonReleased()) || pointer.getDuration() > 250) {
return;
}
if (!this.gameScene.userInputManager.isControlsEnable()) {
return;
}
for (const object of gameObjects) {
if (object instanceof Player || object instanceof RemotePlayer) {
return;

View File

@ -176,7 +176,6 @@ export class UserInputManager {
this.scene.input.keyboard.removeAllListeners();
}
//todo: should we also disable the joystick?
disableControls() {
this.scene.input.keyboard.removeAllKeys();
this.isInputDisabled = true;
@ -186,6 +185,11 @@ export class UserInputManager {
this.initKeyBoardEvent();
this.isInputDisabled = false;
}
isControlsEnable() {
return !this.isInputDisabled;
}
getEventListForGameTick(): ActiveEventList {
const eventsMap = new ActiveEventList();
if (this.isInputDisabled) {
@ -266,7 +270,7 @@ export class UserInputManager {
this.scene.input.on(
Phaser.Input.Events.POINTER_DOWN,
(pointer: Phaser.Input.Pointer, gameObjects: Phaser.GameObjects.GameObject[]) => {
if (!pointer.wasTouch) {
if (!pointer.wasTouch || this.isInputDisabled) {
return;
}
this.userInputHandler.handlePointerDownEvent(pointer, gameObjects);