Skip to content

fix bounding box calculations for the accelerometer tilt effect#6828

Merged
riknoll merged 1 commit into
masterfrom
dev/riknoll/fix-tilt-bounds
May 13, 2026
Merged

fix bounding box calculations for the accelerometer tilt effect#6828
riknoll merged 1 commit into
masterfrom
dev/riknoll/fix-tilt-bounds

Conversation

@riknoll
Copy link
Copy Markdown
Member

@riknoll riknoll commented May 12, 2026

fixes #6103

this fixes the accelerometer tilt effect.

previously, all calculations for determining the mouse position within the board were based on getBoundingClientRect(). the problem with that approach is that the CSS transformation we apply to make the micro:bit look like it's tilting changes the bounds returned by that function (getBoundingClientRect() is calculated post CSS). as a result, we get some weird results for certain screen sizes and aspect ratios where the board moves itself out from underneath the mouse pointer when it tilts.

to fix this, this PR makes two changes:

  • the event listeners are now registered on the document rather than the SVG element
  • the bounding box calculations are now performed relative to the page bounds rather than the transforming bounding box

together, these two changes give us a constant bounding box instead of a moving target.

while i was here, i also switched the tilt decay function to use requestAnimationFrame instead of setInterval, so the decay is now much smoother than before (and a little quicker, but I think it looks nice).

@riknoll riknoll requested a review from a team May 12, 2026 22:38
@riknoll riknoll merged commit debb862 into master May 13, 2026
20 checks passed
@riknoll riknoll deleted the dev/riknoll/fix-tilt-bounds branch May 13, 2026 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Simulator tilt left stops working when a parts image shows

2 participants