Skip to content

Commit b978a2b

Browse files
committed
Introduced a separate stage.fullScreenScaleMode property that is used to decide scaling when fullscreen.
1 parent c5c7547 commit b978a2b

3 files changed

Lines changed: 46 additions & 11 deletions

File tree

examples/display/fullscreen.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ function create() {
1313

1414
game.stage.backgroundColor = '#e3ed49';
1515

16+
// Stretch to fill
17+
// game.stage.fullScreenScaleMode = Phaser.StageScaleMode.EXACT_FIT;
18+
// Keep original size
19+
// game.stage.fullScreenScaleMode = Phaser.StageScaleMode.NO_SCALE;
20+
// Maintain aspect ratio
21+
game.stage.fullScreenScaleMode = Phaser.StageScaleMode.NO_SCALE;
22+
1623
game.input.onDown.add(gofull, this);
1724

1825
}

src/core/Stage.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ Phaser.Stage = function (game, width, height) {
5252
*/
5353
this.scaleMode = Phaser.StageScaleMode.NO_SCALE;
5454

55+
/*
56+
* @property {number} fullScreenScaleMode - Scale mode to be used in fullScreen
57+
*/
58+
this.fullScreenScaleMode = Phaser.StageScaleMode.NO_SCALE;
59+
5560
/**
5661
* @property {Phaser.StageScaleMode} scale - The scale of the current running game.
5762
*/

src/system/StageScaleMode.js

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -310,16 +310,25 @@ Phaser.StageScaleMode.prototype = {
310310

311311
if (this.isFullScreen)
312312
{
313-
this.game.stage.canvas.style['width'] = '100%';
314-
this.game.stage.canvas.style['height'] = '100%';
313+
if (this.game.stage.fullScreenScaleMode === Phaser.StageScaleMode.EXACT_FIT)
314+
{
315+
this.game.stage.canvas.style['width'] = '100%';
316+
this.game.stage.canvas.style['height'] = '100%';
315317

316-
this.setMaximum();
318+
this.setMaximum();
317319

318-
this.game.input.scale.setTo(this.game.width / this.width, this.game.height / this.height);
320+
this.game.input.scale.setTo(this.game.width / this.width, this.game.height / this.height);
321+
322+
this.aspectRatio = this.width / this.height;
323+
this.scaleFactor.x = this.game.width / this.width;
324+
this.scaleFactor.y = this.game.height / this.height;
325+
}
326+
else if (this.game.stage.fullScreenScaleMode === Phaser.StageScaleMode.SHOW_ALL)
327+
{
328+
this.game.stage.scale.setShowAll();
329+
this.game.stage.scale.refresh();
330+
}
319331

320-
this.aspectRatio = this.width / this.height;
321-
this.scaleFactor.x = this.game.width / this.width;
322-
this.scaleFactor.y = this.game.height / this.height;
323332
}
324333
else
325334
{
@@ -560,13 +569,27 @@ Phaser.StageScaleMode.prototype = {
560569
{
561570
this.setMaximum();
562571
}
563-
else if (this.game.stage.scaleMode == Phaser.StageScaleMode.EXACT_FIT)
572+
else if (!this.isFullScreen)
564573
{
565-
this.setExactFit();
574+
if (this.game.stage.scaleMode == Phaser.StageScaleMode.EXACT_FIT)
575+
{
576+
this.setExactFit();
577+
}
578+
else if (this.game.stage.scaleMode == Phaser.StageScaleMode.SHOW_ALL)
579+
{
580+
this.setShowAll();
581+
}
566582
}
567-
else if (this.game.stage.scaleMode == Phaser.StageScaleMode.SHOW_ALL)
583+
else
568584
{
569-
this.setShowAll();
585+
if (this.game.stage.fullScreenScaleMode == Phaser.StageScaleMode.EXACT_FIT)
586+
{
587+
this.setExactFit();
588+
}
589+
else if (this.game.stage.fullScreenScaleMode == Phaser.StageScaleMode.SHOW_ALL)
590+
{
591+
this.setShowAll();
592+
}
570593
}
571594

572595
this.setSize();

0 commit comments

Comments
 (0)