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) { if ((!pointer.wasTouch && pointer.leftButtonReleased()) || pointer.getDuration() > 250) {
return; return;
} }
if (!this.gameScene.userInputManager.isControlsEnable()) {
return;
}
for (const object of gameObjects) { for (const object of gameObjects) {
if (object instanceof Player || object instanceof RemotePlayer) { if (object instanceof Player || object instanceof RemotePlayer) {
return; return;

View File

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