do not call joystick logic if not on mobile
This commit is contained in:
parent
62b00f852d
commit
bf6b9a7c83
@ -54,7 +54,7 @@ export class UserInputManager {
|
|||||||
private scene: Phaser.Scene;
|
private scene: Phaser.Scene;
|
||||||
private isInputDisabled: boolean;
|
private isInputDisabled: boolean;
|
||||||
|
|
||||||
private joystick!: MobileJoystick;
|
private joystick?: MobileJoystick;
|
||||||
private joystickEvents = new ActiveEventList();
|
private joystickEvents = new ActiveEventList();
|
||||||
private joystickForceThreshold = 60;
|
private joystickForceThreshold = 60;
|
||||||
private joystickForceAccuX = 0;
|
private joystickForceAccuX = 0;
|
||||||
@ -81,9 +81,9 @@ export class UserInputManager {
|
|||||||
initVirtualJoystick() {
|
initVirtualJoystick() {
|
||||||
this.joystick = new MobileJoystick(this.scene);
|
this.joystick = new MobileJoystick(this.scene);
|
||||||
this.joystick.on("update", () => {
|
this.joystick.on("update", () => {
|
||||||
this.joystickForceAccuX = this.joystick.forceX ? this.joystickForceAccuX : 0;
|
this.joystickForceAccuX = this.joystick?.forceX ? this.joystickForceAccuX : 0;
|
||||||
this.joystickForceAccuY = this.joystick.forceY ? this.joystickForceAccuY : 0;
|
this.joystickForceAccuY = this.joystick?.forceY ? this.joystickForceAccuY : 0;
|
||||||
const cursorKeys = this.joystick.createCursorKeys();
|
const cursorKeys = this.joystick?.createCursorKeys();
|
||||||
for (const name in cursorKeys) {
|
for (const name in cursorKeys) {
|
||||||
const key = cursorKeys[name as Direction];
|
const key = cursorKeys[name as Direction];
|
||||||
switch (name) {
|
switch (name) {
|
||||||
@ -192,7 +192,7 @@ export class UserInputManager {
|
|||||||
return eventsMap;
|
return eventsMap;
|
||||||
}
|
}
|
||||||
this.joystickEvents.forEach((value, key) => {
|
this.joystickEvents.forEach((value, key) => {
|
||||||
if (value) {
|
if (value && this.joystick) {
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case UserInputEvent.MoveUp:
|
case UserInputEvent.MoveUp:
|
||||||
case UserInputEvent.MoveDown:
|
case UserInputEvent.MoveDown:
|
||||||
@ -253,7 +253,7 @@ export class UserInputManager {
|
|||||||
this.scene.input.on(
|
this.scene.input.on(
|
||||||
Phaser.Input.Events.POINTER_UP,
|
Phaser.Input.Events.POINTER_UP,
|
||||||
(pointer: Phaser.Input.Pointer, gameObjects: Phaser.GameObjects.GameObject[]) => {
|
(pointer: Phaser.Input.Pointer, gameObjects: Phaser.GameObjects.GameObject[]) => {
|
||||||
this.joystick.hide();
|
this.joystick?.hide();
|
||||||
this.userInputHandler.handlePointerUpEvent(pointer, gameObjects);
|
this.userInputHandler.handlePointerUpEvent(pointer, gameObjects);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -267,9 +267,9 @@ export class UserInputManager {
|
|||||||
this.userInputHandler.handlePointerDownEvent(pointer, gameObjects);
|
this.userInputHandler.handlePointerDownEvent(pointer, gameObjects);
|
||||||
// Let's only display the joystick if there is one finger on the screen
|
// Let's only display the joystick if there is one finger on the screen
|
||||||
if ((pointer.event as TouchEvent).touches.length === 1) {
|
if ((pointer.event as TouchEvent).touches.length === 1) {
|
||||||
this.joystick.showAt(pointer.x, pointer.y);
|
this.joystick?.showAt(pointer.x, pointer.y);
|
||||||
} else {
|
} else {
|
||||||
this.joystick.hide();
|
this.joystick?.hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user