This is a CSS-related issue. On the web, the game canvas is set to have the same size as your game's resolution. Instead, you want the canvas to fill the entire screen. This can easily be fixed by adding the following code to your game's main CSS file:
CSS:
#gameCanvas, #GameCanvas, #gameVideo, #GameVideo {
width: 100% !important;
height: 100% !important;
}
The
#gameCanvas
and
#gameVideo
are for MZ, and
#GameCanvas
and
#GameVideo
are for MV. The
!important
part is required because the canvas has dimensions specified in the inline style element (inline style has the highest priority in CSS, and
!important
has an even higher priority).
In MZ, you can add the above code into the
/css/game.css
file.
For MV, it's a bit more complex, since MV doesn't have a main CSS file. You can either hijack the
/fonts/gamefont.css
file (easiest), or if you want a cleaner solution, you can create your own
/css/game.css
file, but then you'll also need to add the following HTML tag to the
/index.html
file:
HTML:
<link rel="stylesheet" type="text/css" href="css/game.css">
Alternatively, you can inject the CSS using a plugin. You'll need a plugin anyway, if you want the best-possible solution. The reason is because your game will be stretched (no letterboxing) once you change the canvas' (and video player's) dimensions. To fix this, you'll need a plugin.
Using a plugin, the easiest way to solve this problem would be to do the following:
- Retrieve
window.innerWidth
and window.innerHeight
- Retrieve the game canvas' dimensions and compute its aspect ratio.
- Using the aspect ratio, determine the factor by which to multiply the canvas' width and height, such that both width and height are equal to or smaller than the window's innerWidth or innerHeight.
- Modify the canvas' (and video's) style accordingly (the video's dimensions are equal to the canvas', so there's no need to perform the calculations for both).
- (optional) Add an event listener to the window's resize event, so that when the player resizes their browser window, the canvas (and video) adapt to it:
JavaScript:
window.addEventListener('resize', function(event) { /* do stuff here */ });