Introduction
Add 2 new screen stetch modes. They can be toggled with F3.
Original(contain) strech: the game screen stretches to fit inside the window while keeping its aspect ratio.
Full stretch: the game screen stetches to fit both width and height.
Cover strech: the game screen stretches to cover the entire window, while keeping its aspect ratio. The contents outside the window will be clipped.
No stretch: turn off stretch mode.
Terms
You can use it in any project, credit is not required.
How to Use
Save the code as a js file and put it in plugins directory. There are no parameters for this plugin, just turn it on in the editor.
JavaScript:
//============================================================================= // ScreenStretch.js //============================================================================= /*: * @plugindesc Add new stetch modes. * @author utunnels * * @help Add 2 new screen stetch modes. They can be toggled with F3. Original(contain) strech: the game screen stretches to fit inside the window while keeping its aspect ratio. Full stretch: the game screen stetches to fit both width and height. Cover strech: the game screen stretches to cover the entire window, while keeping its aspect ratio. The contents outside the window will be clipped. No stretch: turn off stretch mode. */ Graphics._defaultStretchMode = function() { return (Utils.isNwjs() || Utils.isMobileDevice())?2:0; }; Graphics._switchStretchMode = function() { this._stretchEnabled++; if(this._stretchEnabled>3) this._stretchEnabled = 0; this._updateAllElements(); }; Graphics._updateRealScale = function() { if (this._stretchEnabled) { const h = this._stretchWidth() / this._width; const v = this._stretchHeight() / this._height; this._realScale = (this._stretchEnabled==3?Math.max:Math.min)(h, v); this._realScaleX = h; this._realScaleY = v; window.scrollTo(0, 0); } else { this._realScale = this._scale; this._realScaleX = this._scale; this._realScaleY = this._scale; } }; Graphics._stretchWidth = Graphics._stretchWidth||function() { if (Utils.isMobileDevice()) { return document.documentElement.clientWidth; } else { return window.innerWidth; } }; Graphics._stretchHeight = Graphics._stretchHeight||function() { if (Utils.isMobileDevice()) { return document.documentElement.clientHeight; } else { return window.innerHeight; } }; Graphics._centerElement = function(element) { var width = element.width * (this._stretchEnabled!=2?this._realScale:this._realScaleX); var height = element.height * (this._stretchEnabled!=2?this._realScale:this._realScaleY); element.style.position = 'absolute'; element.style.margin = 0; element.style.left = (window.innerWidth-width)/2 + 'px'; element.style.top = (window.innerHeight-height)/2 + 'px'; element.style.width = width + 'px'; element.style.height = height + 'px'; document.body.style.overflow = 'hidden'; }; Graphics.pageToCanvasX = function(x) { if (this._canvas) { var left = this._canvas.offsetLeft; var scalex = this._canvas.clientWidth/this._canvas.width; return Math.round((x - left) / scalex); } else { return 0; } }; Graphics.pageToCanvasY = function(y) { if (this._canvas) { var top = this._canvas.offsetTop; var scaley = this._canvas.clientHeight/this._canvas.height; return Math.round((y - top) / scaley); } else { return 0; } }; 复制代码
本贴来自国际rpgmaker官方论坛作者:utunnels处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:
https://forums.rpgmakerweb.com/threads/more-screen-stretch-modes-plugin.170575/