new tma
This commit is contained in:
26
src/input/TouchInput.ts
Normal file
26
src/input/TouchInput.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import Phaser from "phaser";
|
||||
|
||||
export class TouchInput {
|
||||
dx = 0;
|
||||
dy = 0;
|
||||
|
||||
constructor(scene: Phaser.Scene) {
|
||||
let start: Phaser.Math.Vector2 | null = null;
|
||||
|
||||
scene.input.on("pointerdown", (pointer: Phaser.Input.Pointer) => {
|
||||
start = new Phaser.Math.Vector2(pointer.x, pointer.y);
|
||||
});
|
||||
|
||||
scene.input.on("pointermove", (pointer: Phaser.Input.Pointer) => {
|
||||
if (!start) return;
|
||||
this.dx = Phaser.Math.Clamp((pointer.x - start.x) / 50, -1, 1);
|
||||
this.dy = Phaser.Math.Clamp((pointer.y - start.y) / 50, -1, 1);
|
||||
});
|
||||
|
||||
scene.input.on("pointerup", () => {
|
||||
start = null;
|
||||
this.dx = 0;
|
||||
this.dy = 0;
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user