From 180bd07783c499df45fc07f56613b6a66bd9e38e Mon Sep 17 00:00:00 2001 From: Joey Wunderlich Date: Mon, 8 Apr 2019 15:11:55 -0700 Subject: [PATCH] Fix NaN acceleration on mobile (#1984) --- sim/visuals/microbit.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sim/visuals/microbit.ts b/sim/visuals/microbit.ts index 4c1cd5ac..55a73fbc 100644 --- a/sim/visuals/microbit.ts +++ b/sim/visuals/microbit.ts @@ -909,8 +909,13 @@ path.sim-board { } const bbox = this.element.getBoundingClientRect(); - const ax = (ev.clientX - bbox.width / 2) / (bbox.width / 3); - const ay = (ev.clientY - bbox.height / 2) / (bbox.height / 3); + + // ev.clientX and ev.clientY are not defined on mobile iOS + const xPos = ev.clientX != null ? ev.clientX : ev.pageX; + const yPos = ev.clientY != null ? ev.clientY : ev.pageY; + + const ax = (xPos - bbox.width / 2) / (bbox.width / 3); + const ay = (yPos - bbox.height / 2) / (bbox.height / 3); const x = - Math.max(- 1023, Math.min(1023, Math.floor(ax * 1023))); const y = - Math.max(- 1023, Math.min(1023, Math.floor(ay * 1023)));