ScaleManager.setMinMax(minWidth, minHeight, maxWidth, maxHeight) is a handy function to allow you to set all the min/max dimensions in one call.

This commit is contained in:
photonstorm 2014-09-01 03:07:17 +01:00
parent 2f1f680d73
commit 80d1df4705
4 changed files with 73 additions and 43 deletions

View file

@ -102,6 +102,7 @@ Version 2.1.0 - "Cairhien" - -in development-
* 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)
* Canvas.removeFromDOM(canvas) will remove a canvas element from the DOM.
* Game.destroy now removes the games canvas element from the DOM.
* ScaleManager.setMinMax(minWidth, minHeight, maxWidth, maxHeight) is a handy function to allow you to set all the min/max dimensions in one call.
### Updates

View file

@ -6,15 +6,7 @@ BasicGame.Boot = function (game) {
BasicGame.Boot.prototype = {
preload: function () {
// Here we load the assets required for our preloader (in this case a background and a loading bar)
this.load.image('preloaderBackground', 'images/preloader_background.jpg');
this.load.image('preloaderBar', 'images/preloadr_bar.png');
},
create: function () {
init: function () {
// Unless you specifically know your game needs to support multi-touch I would recommend setting this to 1
this.input.maxPointers = 1;
@ -32,15 +24,25 @@ BasicGame.Boot.prototype = {
// Same goes for mobile settings.
// In this case we're saying "scale the game, no lower than 480x260 and no higher than 1024x768"
this.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;
this.scale.minWidth = 480;
this.scale.minHeight = 260;
this.scale.maxWidth = 1024;
this.scale.maxHeight = 768;
this.scale.setMinMax(480, 260, 1024, 768);
this.scale.forceLandscape = true;
this.scale.pageAlignHorizontally = true;
this.scale.setScreenSize(true);
this.scale.refresh();
}
},
preload: function () {
// Here we load the assets required for our preloader (in this case a background and a loading bar)
this.load.image('preloaderBackground', 'images/preloader_background.jpg');
this.load.image('preloaderBar', 'images/preloadr_bar.png');
},
create: function () {
// By this point the preloader assets have loaded to the cache, we've set the game settings
// So now let's start the real preloader going
this.state.start('Preloader');

View file

@ -16,6 +16,36 @@ BasicGame.Boot = function (game) {
BasicGame.Boot.prototype = {
init: function () {
this.input.maxPointers = 1;
this.stage.disableVisibilityChange = true;
if (this.game.device.desktop)
{
this.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;
this.scale.setMinMax(480, 260, 1024, 768);
this.scale.pageAlignHorizontally = true;
this.scale.pageAlignVertically = true;
this.scale.setScreenSize(true);
this.scale.refresh();
}
else
{
this.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;
this.scale.setMinMax(480, 260, 1024, 768);
this.scale.pageAlignHorizontally = true;
this.scale.pageAlignVertically = true;
this.scale.forceOrientation(true, false);
this.scale.setResizeCallback(this.gameResized, this);
this.scale.enterIncorrectOrientation.add(this.enterIncorrectOrientation, this);
this.scale.leaveIncorrectOrientation.add(this.leaveIncorrectOrientation, this);
this.scale.setScreenSize(true);
this.scale.refresh();
}
},
preload: function () {
// Here we load the assets required for our preloader (in this case a background and a loading bar)
@ -26,36 +56,6 @@ BasicGame.Boot.prototype = {
create: function () {
this.input.maxPointers = 1;
this.stage.disableVisibilityChange = true;
if (this.game.device.desktop)
{
this.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;
this.scale.minWidth = 480;
this.scale.minHeight = 260;
this.scale.maxWidth = 1024;
this.scale.maxHeight = 768;
this.scale.pageAlignHorizontally = true;
this.scale.pageAlignVertically = true;
this.scale.setScreenSize(true);
}
else
{
this.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;
this.scale.minWidth = 480;
this.scale.minHeight = 260;
this.scale.maxWidth = 1024;
this.scale.maxHeight = 768;
this.scale.pageAlignHorizontally = true;
this.scale.pageAlignVertically = true;
this.scale.forceOrientation(true, false);
this.scale.setResizeCallback(this.gameResized, this);
this.scale.enterIncorrectOrientation.add(this.enterIncorrectOrientation, this);
this.scale.leaveIncorrectOrientation.add(this.leaveIncorrectOrientation, this);
this.scale.setScreenSize(true);
}
this.state.start('Preloader');
},
@ -64,6 +64,7 @@ BasicGame.Boot.prototype = {
// This could be handy if you need to do any extra processing if the game resizes.
// A resize could happen if for example swapping orientation on a device or resizing the browser window.
// Note that this callback is only really useful if you use a ScaleMode of RESIZE and place it inside your main game state.
},

View file

@ -447,6 +447,32 @@ Phaser.ScaleManager.prototype = {
},
/**
* Set the ScaleManager min and max dimensions in one single callback.
*
* @method setMinMax
* @param {number} minWidth - The minimum width the game is allowed to scale down to.
* @param {number} minHeight - The minimum height the game is allowed to scale down to.
* @param {number} maxWidth - The maximum width the game is allowed to scale up to.
* @param {number} maxHeight - The maximum height the game is allowed to scale up to.
*/
setMinMax: function (minWidth, minHeight, maxWidth, maxHeight) {
this.minWidth = minWidth;
this.minHeight = minHeight;
if (typeof maxWidth !== 'undefined')
{
this.maxWidth = maxWidth;
}
if (typeof maxHeight !== 'undefined')
{
this.maxHeight = maxHeight;
}
},
/**
* The ScaleManager.preUpdate is called automatically by the core Game loop.
*