Free whole-number pixel scaling for Godot 4. Your pixel art stays crisp at any window size: one canvas pixel is always k x k screen pixels, with k a whole number, and the spare room becomes extra canvas instead of black bars.
Show full description...
A 640x360 game in a 1366x768 window usually gets one of two things: pixels that are 2 or 3 screen pixels wide (the "viewport" stretch), or black bars on every side (the "integer" mode). With CozyPixelViewport the same window gets k 2 and a 683x384 canvas: square pixels and a full window.
What it does
- One node, CozyPixelViewport. Put your UI's root Control under it; it sets the window's stretch values itself.
- The biggest whole scale that fits: x2 at 1280x720, x3 at 1920x1080, x4 at 1440p, x6 at 4K. The Steam Deck's 1280x800 gets x2 and a 640x400 canvas.
- Your Node2D world and Camera2D get the same whole scale.
- Settings: the design canvas (640x360 by default; 960x540 or 320x180 work too), a minimum canvas that must always fit, and a "UI size" step for your options menu.
- Retina-aware on macOS (k counted in the panel's own pixels).
- A layout_changed(k, canvas) signal.
- A small demo drawn in code, and 26 headless tests.
How to use it
- Copy addons/cozy_pixel_viewport/ into your project.
- Set the default texture filter to Nearest.
- Add a CozyPixelViewport node and put your UI's root Control under it.
Open demo/demo.tscn to watch it at different window sizes.
Tested with Godot 4.7.2 (GL Compatibility and Forward+).
Want the full UI kit?
CozyPixelViewport is the scaling node of the Cozy Pixel UI Kit, given away on its own. The kit adds saved display settings with a ready Settings screen (full screen, which screen, UI size), a theme built in code from one palette, 23 pixel-perfect controls, two crisp pixel fonts and a pixel-grid check for your tests: https://brikigames.itch.io/cozy-pixel-ui-kit
Limitations
- Tested only with Godot 4.7.2 on macOS (a Retina screen). Windows and Linux are not tested by us yet.
- One per game: it sets the main window's stretch.
- It saves nothing: keep the UI size with your own settings.
- Text is only crisp with a pixel font set up without smoothing (the demo shows one).
License
MIT: use it in anything, free or commercial, change it, share it; keep the copyright notice. The demo's font is under the SIL Open Font License.
Made with AI
Made with AI assistance: the code and docs were written with AI coding assistants, then tested (26 automated tests, plus real-window checks at 7 window sizes) and reviewed by us. No AI-generated images: the demo's pictures are drawn by code and its font is an open-licensed font.
Links
Questions: leave a comment below. Made by Briki Games, the small studio behind an upcoming cozy cafe game: https://brikigames.itch.io