mirror of
https://github.com/photonstorm/phaser
synced 2024-11-25 14:10:42 +00:00
Merge pull request #6703 from rexrainbow/expand-scale-mode
Add EXPAND scale mode
This commit is contained in:
commit
d6d4fc9705
2 changed files with 60 additions and 2 deletions
|
@ -431,7 +431,7 @@ var ScaleManager = new Class({
|
||||||
|
|
||||||
this.fullscreen = game.device.fullscreen;
|
this.fullscreen = game.device.fullscreen;
|
||||||
|
|
||||||
if (this.scaleMode !== CONST.SCALE_MODE.RESIZE)
|
if ((this.scaleMode !== CONST.SCALE_MODE.RESIZE) && (this.scaleMode !== CONST.SCALE_MODE.EXPAND))
|
||||||
{
|
{
|
||||||
this.displaySize.setAspectMode(this.scaleMode);
|
this.displaySize.setAspectMode(this.scaleMode);
|
||||||
}
|
}
|
||||||
|
@ -1047,6 +1047,53 @@ var ScaleManager = new Class({
|
||||||
this.canvas.width = styleWidth;
|
this.canvas.width = styleWidth;
|
||||||
this.canvas.height = styleHeight;
|
this.canvas.height = styleHeight;
|
||||||
}
|
}
|
||||||
|
else if (this.scaleMode === CONST.SCALE_MODE.EXPAND)
|
||||||
|
{
|
||||||
|
// Resize to match parent, like RESIZE mode
|
||||||
|
|
||||||
|
// This will constrain using min/max
|
||||||
|
this.displaySize.setSize(this.parentSize.width, this.parentSize.height);
|
||||||
|
|
||||||
|
styleWidth = this.displaySize.width;
|
||||||
|
styleHeight = this.displaySize.height;
|
||||||
|
|
||||||
|
if (autoRound)
|
||||||
|
{
|
||||||
|
styleWidth = Math.floor(styleWidth);
|
||||||
|
styleHeight = Math.floor(styleHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
style.width = styleWidth + 'px';
|
||||||
|
style.height = styleHeight + 'px';
|
||||||
|
|
||||||
|
|
||||||
|
// Expand canvas size to fit game size's width or height
|
||||||
|
|
||||||
|
var scaleX = this.parentSize.width / this.gameSize.width;
|
||||||
|
|
||||||
|
var scaleY = this.parentSize.height / this.gameSize.height;
|
||||||
|
|
||||||
|
if (scaleX < scaleY)
|
||||||
|
{
|
||||||
|
this.baseSize.setSize(this.gameSize.width, this.parentSize.height / scaleX);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.baseSize.setSize(this.displaySize.width / scaleY, this.gameSize.height);
|
||||||
|
}
|
||||||
|
|
||||||
|
styleWidth = this.baseSize.width;
|
||||||
|
styleHeight = this.baseSize.height;
|
||||||
|
|
||||||
|
if (autoRound)
|
||||||
|
{
|
||||||
|
styleWidth = Math.floor(styleWidth);
|
||||||
|
styleHeight = Math.floor(styleHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.canvas.width = styleWidth;
|
||||||
|
this.canvas.height = styleHeight;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// All other scale modes
|
// All other scale modes
|
||||||
|
|
|
@ -87,6 +87,17 @@ module.exports = {
|
||||||
* @const
|
* @const
|
||||||
* @since 3.16.0
|
* @since 3.16.0
|
||||||
*/
|
*/
|
||||||
RESIZE: 5
|
RESIZE: 5,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Canvas's visible area is resized to fit all available _parent_ space like RESIZE mode,
|
||||||
|
* and scale canvas size to fit inside the visible area like FIT mode.
|
||||||
|
*
|
||||||
|
* @name Phaser.Scale.ScaleModes.EXPAND
|
||||||
|
* @type {number}
|
||||||
|
* @const
|
||||||
|
* @since 3.70.1
|
||||||
|
*/
|
||||||
|
EXPAND : 6
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue