From 48afb52ef1efdc8bdd6bd577be18a02a955de07f Mon Sep 17 00:00:00 2001 From: Sam El-Husseini Date: Fri, 4 Nov 2016 15:39:57 -0700 Subject: [PATCH] Fix for accelerometer simulator not working in firefox. Fixes Microsoft/pxt/#679 --- sim/visuals/microbit.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sim/visuals/microbit.ts b/sim/visuals/microbit.ts index d315fc12..0fe237c1 100644 --- a/sim/visuals/microbit.ts +++ b/sim/visuals/microbit.ts @@ -712,8 +712,9 @@ namespace pxsim.visuals { tiltDecayer = 0; } - let ax = (ev.clientX - this.element.clientWidth / 2) / (this.element.clientWidth / 3); - let ay = (ev.clientY - this.element.clientHeight / 2) / (this.element.clientHeight / 3); + let bbox = this.element.getBoundingClientRect(); + let ax = (ev.clientX - bbox.width / 2) / ( bbox.width / 3); + let ay = (ev.clientY - bbox.height / 2) / (bbox.height / 3); let x = - Math.max(- 1023, Math.min(1023, Math.floor(ax * 1023))); let y = Math.max(- 1023, Math.min(1023, Math.floor(ay * 1023)));