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

Background does not redraw properly on resized canvases #45

Closed
elldritch opened this issue Aug 17, 2012 · 6 comments
Closed

Background does not redraw properly on resized canvases #45

elldritch opened this issue Aug 17, 2012 · 6 comments

Comments

@elldritch
Copy link

If I resize my canvas after initializing the Core module, and then call redraw() on either the Core module or the Draw module, the background doesn't redraw to fill the canvas. Calling reset() on the Core module doesn't work either, nor does using the set() method on the Background module. If I were to guess, I think it's due to the drawing function not checking for canvas size changes after the initialization.

@koggdal
Copy link
Owner

koggdal commented Aug 17, 2012

Can you provide a test case? Because when I tested this now, it works as it should.

@koggdal
Copy link
Owner

koggdal commented Aug 17, 2012

Are you resizing using the properties in oCanvas (core.width, core.height), or via some other way in the DOM? You need to resize via the properties in oCanvas, since there is no way of detecting when an element has been resized, except for polling all the time, which isn't really a good solution.

@elldritch
Copy link
Author

Oh I see. I was using a window resize event listener, and I was just resizing the canvas element instead of the oCanvas properties. Thanks!

@koggdal
Copy link
Owner

koggdal commented Aug 17, 2012

And just to be more clear about these properties: They do not only resize, but also redraw, so you don't have to make an extra call to redraw :)

@josh-oiknine
Copy link

I know this issue is closed but I wanted to know if there was a way to overload the default redrawing?

My issue is when I resize the browser window I want to resize the canvas to fill the innerWidth and innerHeight. This causes the redraw() to be called multiple times.

@koggdal
Copy link
Owner

koggdal commented Nov 18, 2014

I'd say that it would be expected and the best experience if it was redrawn on every resize, since you would otherwise see empty areas in the canvas before the redraw kicks in. Is the problem that you don't throttle the resize handler (the resize event can be triggered multiple times per frame)? Or is one redraw per frame too much? In that case, maybe you could try to throttle the resize handler to every 100 ms (or what time you feel is good for your project)?

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

No branches or pull requests

3 participants