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

Scale canvas to window size example #25

Open
jakeklassen opened this issue May 25, 2023 · 3 comments
Open

Scale canvas to window size example #25

jakeklassen opened this issue May 25, 2023 · 3 comments

Comments

@jakeklassen
Copy link

I'm not sure this is the proper place to ask, but does anyone have an example of how to best scale a Skia Canvas to match the window size?

For example, say I am making a game with a canvas size 128x128 and a window sized at 512x512 (so 4x), is there an easy way to auto scale (stretch) the canvas to the window size? I don't want to actually create a 512x512 canvas and the draw all the native 128x128 sprite at a larger resolution.

I'm basically after something like the transform: scale(4) you'd get with CSS.

@nhrones
Copy link

nhrones commented Jul 10, 2023

Skia-canvas has the same API surface as html-canvas.
https://www.w3schools.com/tags/canvas_scale.asp

@hashrock
Copy link
Contributor

so I guess we might need dwm version of window.devicePixelRatio to achieve that?

@jakeklassen
Copy link
Author

@nhrones yeah that makes sense but I'm thinking more along the lines of:

canvas.style.transform = `scale(4)`;

Using the context API to scale a 128x128 canvas won't make the canvas fill the 512x512 window. Unless I am misunderstanding something. I'm thinking something along the lines of a window stretch mode that could be fill, etc. Not sure how to achieve that with this lib.

Hopefully that helps clear up my original question.

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