Changing resolution in game (Solved)

Status
Not open for further replies.

orcomarcio

Veteran
Veteran
Joined
Nov 26, 2015
Messages
104
Reaction score
20
First Language
Italian
Hey there,
I need to make the game change resolution during fights (to be precise I need 960x540 during exploration and 1920x1080 in combat).
Initially i solved the problem re-initializing the Graphics class each time i needed to change resolution, but apparently that creates a lot of garbage and after a few iterations it starts to slow down, break and the console gives this message "WARNING: Too many active WebGL contexts. Oldest context will be lost".
I tried another way by basically calling this function
Code:
SceneManager.changeGraphicResolution = function(width, height) {
    this._screenWidth  = width;
    this._screenHeight = height;
    Graphics._width    = width;
    Graphics._height   = height;
    var resizeWidth = this._screenWidth - window.innerWidth;
    var resizeHeight = this._screenHeight - window.innerHeight;
    window.resizeBy(resizeWidth, resizeHeight);
};
The problem with this method is that if res scales up it increases the window size too and if done in full screen it scales the contents and i see only the top left corner. I tried some workarounds but are very scuffed, like switching full screen mode 2 times in the span of 2 cycles, which kinda solves the problem. Anyway this whole solution can work but I feel like there must be an easier and cleaner way.

TL;DR I need to change resolution on command in-game, keeping the same window size if windowed mode and not giving problems if done while in full screen.

Does anyone know how to either clear the garbage before re-initializing graphics or change resolution in real time?
 

orcomarcio

Veteran
Veteran
Joined
Nov 26, 2015
Messages
104
Reaction score
20
First Language
Italian
I solved it, when the scene changes and i need to change resolution i call this fucntion

Code:
SceneManager.changeGraphicResolution = function(width, height) {
    this._screenWidth  = width;
    this._screenHeight = height;
    Graphics._width    = width;
    Graphics._height   = height;
};
This makes the games think the resolution changed and it's needed for stuff like camera position, windows width and such, but it doesn't really change the resolution. For that you need to change Graphics.width to a random value and change it back to the desired resolution the next cycle. this refreshes it and makes it work. It's not the most elegant solution (and gives a frame or two of glitched images while scaling, it is not that evident unless you pay close attention) but it works. Here is how I implemented it inside the SceneManager.changeScene function.

Code:
SceneManager.changeScene = function() {
    //added lines
    if (this._rescale > 1) { //scale to 1920
        Graphics.width    = 960; //this could probably be any value
        this._rescale--;
    } else if (this._rescale > 0) {
        Graphics.width    = 1920;
        this._rescale--;
    }
    if (this._rescale < -1) { //scale to 920
        Graphics.width    = 1920; //this could probably be any value
        this._rescale++;
    } else if (this._rescale < 0) {
        Graphics.width    = 960;
        this._rescale++;
    }
    //added lines end
    if (this.isSceneChanging() && !this.isCurrentSceneBusy()) {
        if (this._scene) {
            this._scene.terminate();
            this._previousClass = this._scene.constructor;
        }
        this._scene = this._nextScene;
        if (this._scene) {
            //added lines
            if (this._scene instanceof Scene_Battle) {
                SceneManager.changeGraphicResolution(1920, 1080);
                this._rescale = 2;
            } else {
                SceneManager.changeGraphicResolution(960, 540);
                this._rescale = -2;
            }
            //added lines end
            this._scene.create();
            this._nextScene = null;
            this._sceneStarted = false;
            this.onSceneCreate();
        }
        if (this._exiting) {
            this.terminate();
        }
    }
};
 
Last edited:

slimmmeiske2

Little Red Riding Hood
Global Mod
Joined
Sep 6, 2012
Messages
6,752
Reaction score
4,602
First Language
Dutch
Primarily Uses
RMXP

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

 
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

JDgoldvox wrote on Mr. Detective's profile.
hey, could u help me with a problem? basically, How do I delete a character from a map after a cut scene is over? I am really new with RPG maker MV. Please help!
The most rewarding part of making custom body character parts is absolutely not making the masks work. Somebody please put me out of my misery.
Any commercial devs here ever mess with Gamejolt? Been contemplating making my games available there but don't know if it's worth the effort or not.
Social distancing taught me of how much of not a loner I am. Dammit, I miss seeing my friends...
Happy 4th of July all. Anybody have plans? Mine here is staying home away from the virus. Still a nice 3 day weekend.

Forum statistics

Threads
99,263
Messages
963,617
Members
130,856
Latest member
superfluffy
Top