Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Macroquad doesn't react to canvas element size changes #787

Open
InnocentusLime opened this issue Sep 3, 2024 · 0 comments · May be fixed by not-fl3/miniquad#479
Open

Macroquad doesn't react to canvas element size changes #787

InnocentusLime opened this issue Sep 3, 2024 · 0 comments · May be fixed by not-fl3/miniquad#479

Comments

@InnocentusLime
Copy link
Contributor

InnocentusLime commented Sep 3, 2024

What is going wrong?

In WASM builds of macroquad, when you resize a canvas with JS/CSS on the fly -- it doesn't actually react to that. It is apparent by the graphics rendered in the canvas getting stretched and the fact that width and height attributes of the canvas do not get updated.

This is a problem for

  • any macroquad app that doesn't have its canvas constantly as "fullscreen"
  • any macroquad app that may resize its canvas without having the window resized

Cause

This might be because, if we look at the miniquad source code (https://github.com/not-fl3/miniquad/blob/master/js/gl.js) the resize reoutine is only called when onresize event is fired, which according to MDN docs (https://developer.mozilla.org/en-US/docs/Web/API/Window/resize_event) fires off only when the window is resized. Not the canvas element.

Solution

not-fl3/miniquad#479 seems to have a valid fix as this issue seems to belong to miniquad and not unique to macroquad. The fix uses ResizeObserver API (https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver)

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 a pull request may close this issue.

1 participant