じ☆ve冰风 发表于 2026-7-26 08:28:55

Fit to Browser Window

Fit to Browser Window
v1.00

Description

Designed for browser deployed games, this automatically fits the game screen to the width and height of the client's browser window.

Instructions

Plug and play, though it is up to you to create appropriately sized maps and graphics, and to understand how and why this script should or should not be used.

The creator can specify a maximum size and minimum size for their game; the game will not go beyond these boundaries. Leave blank or 0 and the game will just fill the available space.

When testing this plugin please note that the size of the game's title screen and first map are for a small screen, so you won't initially notice that the plugin is working! As I said it is up to you to tailor your game to the plugin.

Credits

Credit to YanFly for a few lines from the resolution changing script. I have just plugged my own variables into these lines.

Notes

I am not used to releasing my plugins publicly so I apologise if I have broken any unwritten rules in my plugin; I've tried to keep to the standards set in the plugins I've seen.

I want to do a new version eventually which will resize the game when the client resizes their browser window, but I am not sure if this is possible. Currently the player will have to reload the game if they change their window size.

The plugin has no benefit whatsoever to a standalone release.

Plugin

                Code:       
//=============================================================================
// FitToBrowser.js
//=============================================================================
/*:
* @plugindesc Fit to Browser v1.00
* @author Afar Build 2 / Credit to YanFly for a couple of lines from ScreenResolution.js
*
* @param Minimum Width
* @desc Makes the game not go below this size. 0 = doesn't matter.
* Default: 640
* @default 640
*
* @param Minimum Height
* @desc Makes the game not go below this size.0 = doesn't matter.                     
* Default: 480
* @default 480
*
* @param Maximum Width
* @desc Makes the game not go above this size. 0 = doesn't matter.
* Default: 1024
* @default 1024
*
* @param Maximum Height
* @desc Makes the game not go above this size. 0 = doesn't matter.                     
* Default: 768
* @default 768
*/

var AmyPond = AmyPond || {};
AmyPond.resolution = AmyPond.resolution || {};

AmyPond.parameters = PluginManager.parameters('FitToBrowser');
AmyPond.minWidth = Number(AmyPond.parameters['Minimum Width'] || 0);
AmyPond.minHeight = Number(AmyPond.parameters['Minimum Height'] || 0);
AmyPond.maxWidth = Number(AmyPond.parameters['Maximum Width'] || 0);
AmyPond.maxHeight = Number(AmyPond.parameters['Maximum Height'] || 0);

AmyPond.resize = function() {

    AmyPond.w = window.innerWidth
    || document.documentElement.clientWidth
    || document.body.clientWidth;

    AmyPond.h = window.innerHeight
    || document.documentElement.clientHeight
    || document.body.clientHeight;

    if (AmyPond.minWidth != 0) {
      if (AmyPond.w < AmyPond.minWidth) {
            AmyPond.w = AmyPond.minWidth;
      }
    }
    if (AmyPond.maxWidth != 0) {
      if (AmyPond.w > AmyPond.maxWidth) {
            AmyPond.w = AmyPond.maxWidth;
      }
    }
    if (AmyPond.minHeight != 0) {
      if (AmyPond.h < AmyPond.minHeight) {
            AmyPond.h = AmyPond.minHeight;
      }
    }
    if (AmyPond.maxHeight != 0) {
      if (AmyPond.h > AmyPond.maxHeight) {
            AmyPond.h = AmyPond.maxHeight;
      }
    }

    SceneManager._screenWidth = AmyPond.w;
    SceneManager._screenHeight = AmyPond.h;
    SceneManager._boxWidth = AmyPond.w;
    SceneManager._boxHeight = AmyPond.h;

   window.resizeBy(AmyPond.w, AmyPond.h);
};

AmyPond.resize();

//=============================================================================
// End of File
//=============================================================================




本贴来自国际rpgmaker官方论坛作者:Ellie Jane处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/fit-to-browser-window.75199/
页: [1]
查看完整版本: Fit to Browser Window