window size on browsers

Hello all,

I am experiencing difficulties on web deploiments for a game.
I use a 1200*576 resolution (25*12 tiles).
I would like the game to upscale automaticaly to fit the size of the screen of the user but I can't seem to manage.

I tried to use "changeWindowHeightTo" and "ChangeWindowWidthTo" but the window on my browser screen remains 1200*576.

do you have any solutions ?

Thanks !

Zardev

Edit : the above mentionned functions work well when I test the game in RMMV. But don't when the game is uploaded on a webpage.
If I understand correctly, you would want to use this:
JavaScript:
var gameCanvas = document.getElementById("GameCanvas");
gameCanvas["width"] = "100%";
gameCanvas["height"] = "100%";
This will cause the game canvas (where the game is rendered) to take the full width and height of the current browser window.

If you also want to change the window's size, that's going to be a lot more complex. Since many web developers abused their ability to resize windows, most browser manufacturers decided to disable resizing either completely or by default. Most browsers still allow resizing windows that you have created yourself (aka. "popups"), though.

If that's what you want, you'll need a page that opens your game in a new window:
JavaScript:
var gameWindow = window.open("https://www.example.com/my-game", "_blank", "width=" + screen.width + ", height=" + screen.height);
This will open your game (assuming your game's URL is "https://www.example.com/my-game") in a new window that has the same size as your current screen resolution.

You can then change the window's size later on using:
JavaScript:
gameWindow.resizeTo(600, 288);
which will resize the gameWindow we had opened before to 600x288 pixels. This is only possible from within the page that opened the gameWindow, and not from within the gameWindow itself.

Getting those windows to maximize, however, is even more complex... Needless to say that messing with windows is not something the browser manufacturers want to support.
Thanks for your answer !

The first solution is what I want exactly.
I tried your bit of code in a script in an event but it does not work.

Do I need to adapt some of it or does it goes somewhere in particular? In the index.html maybe ?

thx a lot

Zardev
Sorry, I made a mistake with my previous code:
JavaScript:
var gameCanvas = document.getElementById("GameCanvas");
gameCanvas.style["width"] = "100%";
gameCanvas.style["height"] = "100%";
I forgot the .style. I also realized that I didn't need the square brackets [] and could have simply used gameCanvas.style.width and gameCanvas.style.height instead.


As for your question, I just realized RPG Maker MV will reset the canvas' dimensions on multiple occasions, so it'd be better to put this code in a plugin instead:
JavaScript:
(function() {
  var Graphics__centerElement = Graphics._centerElement;
  Graphics._centerElement = function() {
    Graphics__centerElement.call(this);

    this._canvas.style.width = "100%";
    this._canvas.style.height = "100%";
  }
})();
Just copy paste the code into a .js file and put the file in the /js/plugins directory of your project.

Also, there are no Terms of Use for this specific plugin. Use it as you see fit.
I can't test it now, but I wondered if it would be more practical to turn on StrechMode at game startup.
The RPG_CORE doesn't check if it's active when the game works on browsers and maybe smartphones, so I put TRUE inside the function.
In this plugin I also disabled the Switch (F3 key).

Edit:
If it works, no credit is needed as it is just a simple modification of the existing one.
whoa, thanks guys, this is exactly what I was looking for and it works perfectly !
Hi everyone ! I had the same issue with a RMMZ game on web browser.

So I worked on a version of this "StrechMode_ON" for RPG Maker MZ. Finally, I simply changed the "rmmz_core.js" file for my web export.

Here it is :

maxdevige, please refrain from necro-posting in a thread. Necro-posting is posting in a thread that has not had posting activity in over 30 days. You can review our forum rules here. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/window-size-on-browsers.141180/