Skip to content

Commit 80d1df4

Browse files
committed
ScaleManager.setMinMax(minWidth, minHeight, maxWidth, maxHeight) is a handy function to allow you to set all the min/max dimensions in one call.
1 parent 2f1f680 commit 80d1df4

4 files changed

Lines changed: 60 additions & 30 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ Version 2.1.0 - "Cairhien" - -in development-
102102
* Support for CocoonJS.App's 'onSuspended' and 'onActivated' events, making it so that the timers and sounds are stopped/started and muted/unmuted when the user swaps an app from the background to the fore or the reverse (thanks @videlais #1152)
103103
* Canvas.removeFromDOM(canvas) will remove a canvas element from the DOM.
104104
* Game.destroy now removes the games canvas element from the DOM.
105+
* ScaleManager.setMinMax(minWidth, minHeight, maxWidth, maxHeight) is a handy function to allow you to set all the min/max dimensions in one call.
105106

106107
### Updates
107108

resources/Project Templates/Basic/Boot.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,7 @@ BasicGame.Boot = function (game) {
66

77
BasicGame.Boot.prototype = {
88

9-
preload: function () {
10-
11-
// Here we load the assets required for our preloader (in this case a background and a loading bar)
12-
this.load.image('preloaderBackground', 'images/preloader_background.jpg');
13-
this.load.image('preloaderBar', 'images/preloadr_bar.png');
14-
15-
},
16-
17-
create: function () {
9+
init: function () {
1810

1911
// Unless you specifically know your game needs to support multi-touch I would recommend setting this to 1
2012
this.input.maxPointers = 1;
@@ -32,15 +24,25 @@ BasicGame.Boot.prototype = {
3224
// Same goes for mobile settings.
3325
// In this case we're saying "scale the game, no lower than 480x260 and no higher than 1024x768"
3426
this.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;
35-
this.scale.minWidth = 480;
36-
this.scale.minHeight = 260;
37-
this.scale.maxWidth = 1024;
38-
this.scale.maxHeight = 768;
27+
this.scale.setMinMax(480, 260, 1024, 768);
3928
this.scale.forceLandscape = true;
4029
this.scale.pageAlignHorizontally = true;
4130
this.scale.setScreenSize(true);
31+
this.scale.refresh();
4232
}
4333

34+
},
35+
36+
preload: function () {
37+
38+
// Here we load the assets required for our preloader (in this case a background and a loading bar)
39+
this.load.image('preloaderBackground', 'images/preloader_background.jpg');
40+
this.load.image('preloaderBar', 'images/preloadr_bar.png');
41+
42+
},
43+
44+
create: function () {
45+
4446
// By this point the preloader assets have loaded to the cache, we've set the game settings
4547
// So now let's start the real preloader going
4648
this.state.start('Preloader');

resources/Project Templates/Full Screen Mobile/src/Boot.js

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,46 +16,46 @@ BasicGame.Boot = function (game) {
1616

1717
BasicGame.Boot.prototype = {
1818

19-
preload: function () {
20-
21-
// Here we load the assets required for our preloader (in this case a background and a loading bar)
22-
this.load.image('preloaderBackground', 'images/preloader_background.jpg');
23-
this.load.image('preloaderBar', 'images/preloadr_bar.png');
24-
25-
},
26-
27-
create: function () {
19+
init: function () {
2820

2921
this.input.maxPointers = 1;
3022
this.stage.disableVisibilityChange = true;
3123

3224
if (this.game.device.desktop)
3325
{
3426
this.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;
35-
this.scale.minWidth = 480;
36-
this.scale.minHeight = 260;
37-
this.scale.maxWidth = 1024;
38-
this.scale.maxHeight = 768;
27+
this.scale.setMinMax(480, 260, 1024, 768);
3928
this.scale.pageAlignHorizontally = true;
4029
this.scale.pageAlignVertically = true;
4130
this.scale.setScreenSize(true);
31+
this.scale.refresh();
4232
}
4333
else
4434
{
4535
this.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;
46-
this.scale.minWidth = 480;
47-
this.scale.minHeight = 260;
48-
this.scale.maxWidth = 1024;
49-
this.scale.maxHeight = 768;
36+
this.scale.setMinMax(480, 260, 1024, 768);
5037
this.scale.pageAlignHorizontally = true;
5138
this.scale.pageAlignVertically = true;
5239
this.scale.forceOrientation(true, false);
5340
this.scale.setResizeCallback(this.gameResized, this);
5441
this.scale.enterIncorrectOrientation.add(this.enterIncorrectOrientation, this);
5542
this.scale.leaveIncorrectOrientation.add(this.leaveIncorrectOrientation, this);
5643
this.scale.setScreenSize(true);
44+
this.scale.refresh();
5745
}
5846

47+
},
48+
49+
preload: function () {
50+
51+
// Here we load the assets required for our preloader (in this case a background and a loading bar)
52+
this.load.image('preloaderBackground', 'images/preloader_background.jpg');
53+
this.load.image('preloaderBar', 'images/preloadr_bar.png');
54+
55+
},
56+
57+
create: function () {
58+
5959
this.state.start('Preloader');
6060

6161
},
@@ -64,6 +64,7 @@ BasicGame.Boot.prototype = {
6464

6565
// This could be handy if you need to do any extra processing if the game resizes.
6666
// A resize could happen if for example swapping orientation on a device or resizing the browser window.
67+
// Note that this callback is only really useful if you use a ScaleMode of RESIZE and place it inside your main game state.
6768

6869
},
6970

src/core/ScaleManager.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,32 @@ Phaser.ScaleManager.prototype = {
447447

448448
},
449449

450+
/**
451+
* Set the ScaleManager min and max dimensions in one single callback.
452+
*
453+
* @method setMinMax
454+
* @param {number} minWidth - The minimum width the game is allowed to scale down to.
455+
* @param {number} minHeight - The minimum height the game is allowed to scale down to.
456+
* @param {number} maxWidth - The maximum width the game is allowed to scale up to.
457+
* @param {number} maxHeight - The maximum height the game is allowed to scale up to.
458+
*/
459+
setMinMax: function (minWidth, minHeight, maxWidth, maxHeight) {
460+
461+
this.minWidth = minWidth;
462+
this.minHeight = minHeight;
463+
464+
if (typeof maxWidth !== 'undefined')
465+
{
466+
this.maxWidth = maxWidth;
467+
}
468+
469+
if (typeof maxHeight !== 'undefined')
470+
{
471+
this.maxHeight = maxHeight;
472+
}
473+
474+
},
475+
450476
/**
451477
* The ScaleManager.preUpdate is called automatically by the core Game loop.
452478
*

0 commit comments

Comments
 (0)