Skip to content

Commit 9e001be

Browse files
try fixing mobile touch
1 parent 5bf97f6 commit 9e001be

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

js10/cubes/scripts/isometricCanvas.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,10 @@ export default class IsometricCanvas {
7575
}
7676

7777
_handleClick(e) {
78-
const mouseX = e.clientX - this.canvas.getBoundingClientRect().left;
79-
const mouseY = e.clientY - this.canvas.getBoundingClientRect().top;
80-
78+
const rect = this.canvas.getBoundingClientRect();
79+
const mouseX = e.clientX - rect.left;
80+
const mouseY = e.clientY - rect.top;
81+
8182
// Check objects in reverse
8283
for (let i = this.objects.length - 1; i >= 0; i--) {
8384
const object = this.objects[i];
@@ -88,12 +89,12 @@ export default class IsometricCanvas {
8889
return;
8990
}
9091
}
91-
92-
// Call ground click if nothing matched
92+
9393
if (this.onGroundClick) {
9494
this.onGroundClick();
9595
}
9696
}
97+
9798

9899
// Ray casting algorithm
99100
_isPointInPolygon(mouseX, mouseY, polygon) {
@@ -209,8 +210,17 @@ export default class IsometricCanvas {
209210

210211
_handleTouchEnd(e) {
211212
this.isDragging = false;
213+
214+
if (e.changedTouches.length === 1) {
215+
const touch = e.changedTouches[0];
216+
const rect = this.canvas.getBoundingClientRect();
217+
const x = touch.clientX - rect.left;
218+
const y = touch.clientY - rect.top;
219+
220+
this._handleClick({ clientX: touch.clientX, clientY: touch.clientY });
221+
}
212222
}
213-
223+
214224
_startPinchZoom(e) {
215225
const [t1, t2] = e.touches;
216226
this._initialPinchDistance = Math.hypot(

0 commit comments

Comments
 (0)