Skip to content

Commit 848912d

Browse files
committed
- touch input fix
1 parent 7db4d4a commit 848912d

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

src/scenes/game.scene.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@ export class Game extends Scene {
4242
if (!xIsLeft && yIsTop) {
4343
this._hero.heroState.set({ action: "SHOOTING" });
4444
}
45-
if (xIsLeft && !yIsTop) {
46-
this._hero.heroState.set({ action: "MOVING-LEFT" });
47-
}
48-
if (!xIsLeft && !yIsTop) {
49-
this._hero.heroState.set({ action: "MOVING-RIGHT" });
50-
}
5145
});
5246

5347
this._hero = new Hero(this);
@@ -69,11 +63,34 @@ export class Game extends Scene {
6963
}
7064
}
7165

66+
const pointer = this.input.activePointer;
67+
68+
if (pointer.isDown) {
69+
this.handlePointer(pointer);
70+
}
71+
7272
this._hero?.update(time, delta);
7373
this._currentLevel?.update();
7474
}
7575

7676
private createDebug(): void {
7777
this._toggleDebugKey = this._keyboard?.addKey(Phaser.Input.Keyboard.KeyCodes.D);
7878
}
79+
80+
private handlePointer(pointer: Phaser.Input.Pointer) {
81+
if (!this._hero) {
82+
return;
83+
}
84+
85+
const xIsLeft = pointer.x < this.cameras.main.width / 2;
86+
const yIsTop = pointer.y < this.cameras.main.height / 2;
87+
88+
if (xIsLeft && !yIsTop) {
89+
this._hero.heroState.set({ action: "MOVING-LEFT" });
90+
console.log("should move left");
91+
}
92+
if (!xIsLeft && !yIsTop) {
93+
this._hero.heroState.set({ action: "MOVING-RIGHT" });
94+
}
95+
}
7996
}

0 commit comments

Comments
 (0)