Limit scaling to a multiple of the game's resolution?

Hi everyone,

is it possible to change the free scaling of the game window to multiples of the game's resolution?

Like, the player can still scale the window as they want, but the game inside will snap to the biggest possible resolution, that is a multiple of the smallest valid resolution and fits in the current window.

Thanks!
Code:
Graphics._updateRealScale = function() {
    if (this._stretchEnabled && this._width > 0 && this._height > 0) {
        const h = this._stretchWidth() / this._width;
        const v = this._stretchHeight() / this._height;
        this._realScale = Math.min(h, v);
        window.scrollTo(0, 0);
    } else {
        const h = this._stretchWidth() / (this._width);
        const v = this._stretchHeight() / (this._height);
        var pixelLockedScale = Math.min(h, v);
        pixelLockedScale = Math.floor(pixelLockedScale);
        this._realScale = Math.max(pixelLockedScale, 1);
        window.scrollTo(0, 0);
    }
};

Graphics._defaultStretchMode = function() {
    return false;
};

That should force the contents of the window to only resize in integer values.
Thank you! It works perfectly.
Just curious, what resolution does your game use?
The height of the default resolution(816x624) is more than half of 1080, so either you have a bigger than 1080p monitor or you are using a smaller resolution?
My main concern for this was to get rid of the blur, when you are somewhere inbetween the clean zoom steps. I'd rather have some black spacing than seeing people play in full screen with blur.

I'm using 1248x864 resolution, but my assets are scaled up by 3, so the "smallest" unit in my game is 3x3px. I modified the code, so "standard resolution /3 *1" and "/3 *2" are also allowed to scale, while the default is "/3 *3" of course. Also, it will allow "/3 *4" and upwards.

So, the next possible zoom will be 1664x1152 instead of 2496x1728 for example.
I see.
What if your character moves 4 pixels for example in game instead of multiple of 3? And various of menus elements and pictures, do you manage to align them?
I think so, but I'm still checking through everything. I had to disable the smallest resolution already (/3*1). The pixels were fine, but the font was barely readable.

Menus and HUD interfaces should be fine, as I do all of them on my own, and they are designed to match the pixelart style.

Basically I have a 16x16px style, that is upscaled to 48x48px. I'm not quite sure where a char might walk weird pixel amounts, but I'll have an eye on it. Worst case would be situational blur again, I guess.
I find your solution interesting.
I spent a whole day yesterday trying to snap everything to 3x3 pixel grids and still haven't finished, thre are just too many UI elements to check. :LZScheeze:
I tried 960x720 to simulate RM2k style(320x240*3). But my desktop resolution is 1920x1080, so it can only be scaled up to 4/3. Maybe 1152x624 is better, because it can be scaled up to 5/3.
I like that approach a lot. Even more, the more I spend time with the new locked scaling. The blur was really stressing me. Since I can work with 16x16, there are quite a few good looking zoom levels available.
Today I made the blackspace "pretty", so it's also nice to look at.

It's anthrazit instead of black and has a subtle noise on it.
Also a shadow, so the game is "floating" a little. (you might have to zoom in to see it)

1735441821836.png


When I started my project, I didn't gave the resolution much technical thought. I went to one of the important maps and made a gut decision, how much should be visible on one screen. And how long I want the player to walk from one side to another.
So, I'm kind of stuck with it now, it's not optimized with any state of the art monitors. But I did pay attention to the 3x3px "styleguide".
It is high noon here and I can only see a black background, it is too subtle to nitice.

By the way, it is also possible to align the sprites before rendering. But then you'll have to spend long time to fix menus. Zoom, text-align, etc, there are many things can break it. There may be things can't be divided by 3, for example, icons are 32x32.

(function(alias){
PIXI.Render.prototype.render=function(){
//do something to align the elements
// var displayObject = arguments[0];
// blahblah
alias.call(this,...arguments);
}
})(PIXI.Render.prototype.render)
var PX=3;
function roundPX(v){
return Math.round(v/PX)*PX;
}
functionfloorPX(v){
return Math.floor(v/PX)*PX;
}
function ceilPX(v){
return Math.ceil(v/PX)*PX;
}
It is high noon here and I can only see a black background, it is too subtle to nitice.
You may see it if you call it's name three times at midnight.

for example, icons are 32x32.
I don't use the default icons, as they don't follow the 3x3 px style. Text was the biggest issue, but only for the smallest resolution, which got deactivated.

Original thread: https://forums.rpgmakerweb.com/threads/limit-scaling-to-a-multiple-of-the-games-resolution.174216/