2013-10-01 12:54:29 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2014-02-05 05:54:25 +00:00
|
|
|
* @copyright 2014 Photon Storm Ltd.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2014-02-25 14:46:48 +00:00
|
|
|
* The ScaleManager object is responsible for helping you manage the scaling, resizing and alignment of your game within the browser.
|
2013-10-01 12:54:29 +00:00
|
|
|
*
|
2014-03-23 07:59:28 +00:00
|
|
|
* @class Phaser.ScaleManager
|
2013-10-01 12:54:29 +00:00
|
|
|
* @constructor
|
|
|
|
* @param {Phaser.Game} game - A reference to the currently running game.
|
2014-09-01 07:19:43 +00:00
|
|
|
* @param {number|string} width - The width of the game.
|
|
|
|
* @param {number|string} height - The height of the game.
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2014-02-25 14:46:48 +00:00
|
|
|
Phaser.ScaleManager = function (game, width, height) {
|
2013-09-09 11:35:20 +00:00
|
|
|
|
|
|
|
/**
|
2013-11-04 20:43:59 +00:00
|
|
|
* @property {Phaser.Game} game - A reference to the currently running game.
|
2013-09-09 11:35:20 +00:00
|
|
|
*/
|
2013-11-04 20:43:59 +00:00
|
|
|
this.game = game;
|
2013-09-09 11:35:20 +00:00
|
|
|
|
2014-09-05 05:02:25 +00:00
|
|
|
/**
|
2014-09-09 11:48:21 +00:00
|
|
|
* @property {Phaser.FlexGrid} grid - EXPERIMENTAL: A responsive grid on which you can align game objects.
|
2014-09-05 05:02:25 +00:00
|
|
|
*/
|
|
|
|
this.grid = null;
|
|
|
|
|
2013-09-09 11:35:20 +00:00
|
|
|
/**
|
2014-09-01 07:19:43 +00:00
|
|
|
* @property {number} width - Width of the game after calculation.
|
2013-09-09 11:35:20 +00:00
|
|
|
*/
|
2014-08-31 00:57:50 +00:00
|
|
|
this.width = 0;
|
2013-09-09 11:35:20 +00:00
|
|
|
|
|
|
|
/**
|
2014-09-01 07:19:43 +00:00
|
|
|
* @property {number} height - Height of the game after calculation.
|
2013-11-04 20:43:59 +00:00
|
|
|
*/
|
2014-08-31 00:57:50 +00:00
|
|
|
this.height = 0;
|
2013-11-04 20:43:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {number} minWidth - Minimum width the canvas should be scaled to (in pixels).
|
2013-09-09 11:35:20 +00:00
|
|
|
*/
|
2013-11-04 20:43:59 +00:00
|
|
|
this.minWidth = null;
|
2013-09-09 11:35:20 +00:00
|
|
|
|
|
|
|
/**
|
2014-02-13 12:50:10 +00:00
|
|
|
* @property {number} maxWidth - Maximum width the canvas should be scaled to (in pixels). If null it will scale to whatever width the browser can handle.
|
2013-09-09 11:35:20 +00:00
|
|
|
*/
|
2013-11-04 20:43:59 +00:00
|
|
|
this.maxWidth = null;
|
2013-09-09 11:35:20 +00:00
|
|
|
|
|
|
|
/**
|
2013-11-04 20:43:59 +00:00
|
|
|
* @property {number} minHeight - Minimum height the canvas should be scaled to (in pixels).
|
2013-09-09 11:35:20 +00:00
|
|
|
*/
|
2013-11-04 20:43:59 +00:00
|
|
|
this.minHeight = null;
|
2013-09-09 11:35:20 +00:00
|
|
|
|
|
|
|
/**
|
2014-02-13 12:50:10 +00:00
|
|
|
* @property {number} maxHeight - Maximum height the canvas should be scaled to (in pixels). If null it will scale to whatever height the browser can handle.
|
2013-09-09 11:35:20 +00:00
|
|
|
*/
|
2013-11-04 20:43:59 +00:00
|
|
|
this.maxHeight = null;
|
2013-09-09 11:35:20 +00:00
|
|
|
|
2014-08-31 11:17:07 +00:00
|
|
|
/**
|
|
|
|
* @property {Phaser.Point} offset - Holds the offset coordinates of the Game.canvas from the top-left of the browser window (used by Input and other classes)
|
|
|
|
*/
|
|
|
|
this.offset = new Phaser.Point();
|
|
|
|
|
2013-09-09 11:35:20 +00:00
|
|
|
/**
|
2014-09-01 00:02:41 +00:00
|
|
|
* @property {boolean} forceLandscape - Set to `true` if the game should only run in a landscape orientation.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @default
|
2013-09-09 11:35:20 +00:00
|
|
|
*/
|
2013-11-04 20:43:59 +00:00
|
|
|
this.forceLandscape = false;
|
2013-09-09 11:35:20 +00:00
|
|
|
|
|
|
|
/**
|
2014-09-01 00:02:41 +00:00
|
|
|
* @property {boolean} forcePortrait - Set to `true` if the game should only run in a portrait orientation.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @default
|
2013-09-09 11:35:20 +00:00
|
|
|
*/
|
2013-11-25 04:40:04 +00:00
|
|
|
this.forcePortrait = false;
|
2013-09-09 11:35:20 +00:00
|
|
|
|
|
|
|
/**
|
2014-09-01 00:02:41 +00:00
|
|
|
* @property {boolean} incorrectOrientation - If `forceLandscape` or `forcePortrait` are true and the browser doesn't match that orientation this is set to `true`.
|
2013-10-01 12:54:29 +00:00
|
|
|
* @default
|
2013-09-09 11:35:20 +00:00
|
|
|
*/
|
2013-11-04 20:43:59 +00:00
|
|
|
this.incorrectOrientation = false;
|
2013-09-09 11:35:20 +00:00
|
|
|
|
|
|
|
/**
|
2013-11-04 20:43:59 +00:00
|
|
|
* @property {boolean} pageAlignHorizontally - If you wish to align your game in the middle of the page then you can set this value to true.
|
2014-09-01 00:02:41 +00:00
|
|
|
* It will place a re-calculated margin-left pixel value onto the canvas element which is updated on orientation/resizing events.
|
2013-11-04 20:43:59 +00:00
|
|
|
* It doesn't care about any other DOM element that may be on the page, it literally just sets the margin.
|
|
|
|
* @default
|
2013-09-09 11:35:20 +00:00
|
|
|
*/
|
2013-11-04 20:43:59 +00:00
|
|
|
this.pageAlignHorizontally = false;
|
2013-09-09 11:35:20 +00:00
|
|
|
|
|
|
|
/**
|
2013-11-04 20:43:59 +00:00
|
|
|
* @property {boolean} pageAlignVertically - If you wish to align your game in the middle of the page then you can set this value to true.
|
2014-09-01 00:02:41 +00:00
|
|
|
* It will place a re-calculated margin-left pixel value onto the canvas element which is updated on orientation/resizing events.
|
2013-11-04 20:43:59 +00:00
|
|
|
* It doesn't care about any other DOM element that may be on the page, it literally just sets the margin.
|
|
|
|
* @default
|
2013-11-01 02:07:21 +00:00
|
|
|
*/
|
2013-11-04 20:43:59 +00:00
|
|
|
this.pageAlignVertically = false;
|
2013-11-01 02:07:21 +00:00
|
|
|
|
2013-09-09 11:35:20 +00:00
|
|
|
/**
|
2013-10-01 12:54:29 +00:00
|
|
|
* @property {number} maxIterations - The maximum number of times it will try to resize the canvas to fill the browser.
|
|
|
|
* @default
|
2013-09-09 11:35:20 +00:00
|
|
|
*/
|
|
|
|
this.maxIterations = 5;
|
2013-11-04 20:43:59 +00:00
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2014-09-01 00:02:41 +00:00
|
|
|
* @property {Phaser.Signal} enterLandscape - The event that is dispatched when the browser enters landscape orientation having been in portrait.
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2013-09-09 11:35:20 +00:00
|
|
|
this.enterLandscape = new Phaser.Signal();
|
2013-10-01 12:54:29 +00:00
|
|
|
|
|
|
|
/**
|
2014-09-01 00:02:41 +00:00
|
|
|
* @property {Phaser.Signal} enterPortrait - The event that is dispatched when the browser enters portrait orientation having been in landscape.
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2013-09-09 11:35:20 +00:00
|
|
|
this.enterPortrait = new Phaser.Signal();
|
|
|
|
|
2013-11-20 02:28:28 +00:00
|
|
|
/**
|
|
|
|
* @property {Phaser.Signal} enterIncorrectOrientation - The event that is dispatched when the browser enters an incorrect orientation, as defined by forceOrientation.
|
|
|
|
*/
|
|
|
|
this.enterIncorrectOrientation = new Phaser.Signal();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {Phaser.Signal} leaveIncorrectOrientation - The event that is dispatched when the browser leaves an incorrect orientation, as defined by forceOrientation.
|
|
|
|
*/
|
|
|
|
this.leaveIncorrectOrientation = new Phaser.Signal();
|
|
|
|
|
2014-03-10 01:13:01 +00:00
|
|
|
/**
|
|
|
|
* This is the DOM element that will have the Full Screen mode called on it. It defaults to the game canvas, but can be retargetted to any valid DOM element.
|
|
|
|
* If you adjust this property it's up to you to see it has the correct CSS applied, and that you have contained the game canvas correctly.
|
|
|
|
* Note that if you use a scale property of EXACT_FIT then fullScreenTarget will have its width and height style set to 100%.
|
|
|
|
* @property {any} fullScreenTarget
|
|
|
|
*/
|
2014-09-05 00:07:51 +00:00
|
|
|
this.fullScreenTarget = null;
|
2014-03-10 01:13:01 +00:00
|
|
|
|
2014-02-25 17:10:37 +00:00
|
|
|
/**
|
|
|
|
* @property {Phaser.Signal} enterFullScreen - The event that is dispatched when the browser enters full screen mode (if it supports the FullScreen API).
|
|
|
|
*/
|
|
|
|
this.enterFullScreen = new Phaser.Signal();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {Phaser.Signal} leaveFullScreen - The event that is dispatched when the browser leaves full screen mode (if it supports the FullScreen API).
|
|
|
|
*/
|
|
|
|
this.leaveFullScreen = new Phaser.Signal();
|
|
|
|
|
2014-02-13 12:50:10 +00:00
|
|
|
/**
|
|
|
|
* @property {number} orientation - The orientation value of the game (as defined by window.orientation if set). 90 = landscape. 0 = portrait.
|
|
|
|
*/
|
|
|
|
this.orientation = 0;
|
|
|
|
|
2013-09-09 11:35:20 +00:00
|
|
|
if (window['orientation'])
|
|
|
|
{
|
|
|
|
this.orientation = window['orientation'];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (window.outerWidth > window.outerHeight)
|
|
|
|
{
|
|
|
|
this.orientation = 90;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2013-11-04 20:43:59 +00:00
|
|
|
* @property {Phaser.Point} scaleFactor - The scale factor based on the game dimensions vs. the scaled dimensions.
|
2013-11-24 11:04:58 +00:00
|
|
|
* @readonly
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2013-09-09 11:35:20 +00:00
|
|
|
this.scaleFactor = new Phaser.Point(1, 1);
|
2013-10-01 12:54:29 +00:00
|
|
|
|
2013-11-24 11:04:58 +00:00
|
|
|
/**
|
|
|
|
* @property {Phaser.Point} scaleFactorInversed - The inversed scale factor. The displayed dimensions divided by the game dimensions.
|
|
|
|
* @readonly
|
|
|
|
*/
|
|
|
|
this.scaleFactorInversed = new Phaser.Point(1, 1);
|
|
|
|
|
|
|
|
/**
|
2014-04-27 09:17:37 +00:00
|
|
|
* @property {Phaser.Point} margin - If the game canvas is set to align by adjusting the margin, the margin calculation values are stored in this Point.
|
2013-11-24 11:04:58 +00:00
|
|
|
* @readonly
|
|
|
|
*/
|
|
|
|
this.margin = new Phaser.Point(0, 0);
|
|
|
|
|
2014-05-19 17:49:16 +00:00
|
|
|
/**
|
|
|
|
* @property {Phaser.Rectangle} bounds - The bounds of the scaled game. The x/y will match the offset of the canvas element and the width/height the scaled width and height.
|
|
|
|
* @readonly
|
|
|
|
*/
|
2014-08-31 00:57:50 +00:00
|
|
|
this.bounds = new Phaser.Rectangle();
|
2014-05-19 17:49:16 +00:00
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2014-02-13 12:50:10 +00:00
|
|
|
* @property {number} aspectRatio - The aspect ratio of the scaled game.
|
|
|
|
* @readonly
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2013-09-09 11:35:20 +00:00
|
|
|
this.aspectRatio = 0;
|
|
|
|
|
2014-02-13 12:50:10 +00:00
|
|
|
/**
|
|
|
|
* @property {number} sourceAspectRatio - The aspect ratio (width / height) of the original game dimensions.
|
|
|
|
* @readonly
|
|
|
|
*/
|
2014-08-31 00:57:50 +00:00
|
|
|
this.sourceAspectRatio = 0;
|
2014-02-13 12:50:10 +00:00
|
|
|
|
2013-11-25 04:40:04 +00:00
|
|
|
/**
|
|
|
|
* @property {any} event- The native browser events from full screen API changes.
|
|
|
|
*/
|
|
|
|
this.event = null;
|
|
|
|
|
2014-02-13 12:50:10 +00:00
|
|
|
/*
|
|
|
|
* @property {number} fullScreenScaleMode - Scale mode to be used in fullScreen
|
|
|
|
*/
|
2014-02-25 14:46:48 +00:00
|
|
|
this.fullScreenScaleMode = Phaser.ScaleManager.NO_SCALE;
|
2014-02-13 12:50:10 +00:00
|
|
|
|
2014-08-31 10:09:27 +00:00
|
|
|
/**
|
|
|
|
* @property {boolean} parentIsWindow - If the parent container of the game is the browser window, rather than a div, this is set to `true`.
|
|
|
|
* @readonly
|
|
|
|
*/
|
|
|
|
this.parentIsWindow = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {object} parentNode - The fully parsed parent container of the game. If the parent is the browser window this will be `null`.
|
|
|
|
* @readonly
|
|
|
|
*/
|
|
|
|
this.parentNode = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {Phaser.Point} parentScaleFactor - The scale of the game in relation to its parent container.
|
|
|
|
* @readonly
|
|
|
|
*/
|
|
|
|
this.parentScaleFactor = new Phaser.Point(1, 1);
|
|
|
|
|
2014-08-31 11:17:07 +00:00
|
|
|
/**
|
|
|
|
* @property {number} trackParentInterval - The interval (in ms) upon which the ScaleManager checks if the parent has changed dimensions. Only applies if scaleMode = RESIZE and the game is contained within another html element.
|
|
|
|
* @default
|
|
|
|
*/
|
2014-09-01 07:19:43 +00:00
|
|
|
this.trackParentInterval = 2000;
|
2014-09-01 00:02:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {function} onResize - The callback that will be called each time a window.resize event happens or if set, the parent container resizes.
|
|
|
|
* @default
|
|
|
|
*/
|
|
|
|
this.onResize = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @property {object} onResizeContext - The context in which the callback will be called.
|
|
|
|
* @default
|
|
|
|
*/
|
|
|
|
this.onResizeContext = null;
|
2014-08-31 11:17:07 +00:00
|
|
|
|
2014-08-31 10:09:27 +00:00
|
|
|
/**
|
|
|
|
* @property {number} scaleMode - The current scaling method being used.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._scaleMode = Phaser.ScaleManager.NO_SCALE;
|
|
|
|
|
2014-02-13 12:50:10 +00:00
|
|
|
/**
|
2014-09-01 07:19:43 +00:00
|
|
|
* @property {number} _width - Cached game width for full screen mode.
|
2014-02-13 12:50:10 +00:00
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._width = 0;
|
|
|
|
|
|
|
|
/**
|
2014-09-01 07:19:43 +00:00
|
|
|
* @property {number} _height - Cached game height for full screen mode.
|
2014-02-13 12:50:10 +00:00
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._height = 0;
|
|
|
|
|
2014-04-29 18:33:03 +00:00
|
|
|
/**
|
|
|
|
* @property {number} _check - Cached size interval var.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._check = null;
|
|
|
|
|
2014-08-31 11:17:07 +00:00
|
|
|
/**
|
|
|
|
* @property {number} _nextParentCheck - The time to run the next parent bounds check.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._nextParentCheck = 0;
|
|
|
|
|
2014-09-01 00:02:41 +00:00
|
|
|
/**
|
|
|
|
* @property {object} _parentBounds - The cached result of getBoundingClientRect from the parent.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._parentBounds = null;
|
|
|
|
|
|
|
|
if (game.config)
|
|
|
|
{
|
|
|
|
this.parseConfig(game.config);
|
|
|
|
}
|
|
|
|
|
2014-09-01 07:19:43 +00:00
|
|
|
this.setupScale(width, height);
|
2014-08-31 00:57:50 +00:00
|
|
|
|
2013-09-09 11:35:20 +00:00
|
|
|
};
|
|
|
|
|
2013-10-03 00:21:08 +00:00
|
|
|
/**
|
|
|
|
* @constant
|
|
|
|
* @type {number}
|
|
|
|
*/
|
2014-02-25 14:46:48 +00:00
|
|
|
Phaser.ScaleManager.EXACT_FIT = 0;
|
2013-10-03 00:21:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @constant
|
|
|
|
* @type {number}
|
|
|
|
*/
|
2014-02-25 14:46:48 +00:00
|
|
|
Phaser.ScaleManager.NO_SCALE = 1;
|
2013-10-03 00:21:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @constant
|
|
|
|
* @type {number}
|
|
|
|
*/
|
2014-02-25 14:46:48 +00:00
|
|
|
Phaser.ScaleManager.SHOW_ALL = 2;
|
2013-09-09 11:35:20 +00:00
|
|
|
|
2014-08-31 00:57:50 +00:00
|
|
|
/**
|
|
|
|
* @constant
|
|
|
|
* @type {number}
|
|
|
|
*/
|
2014-09-01 00:02:41 +00:00
|
|
|
Phaser.ScaleManager.RESIZE = 3;
|
2014-08-31 00:57:50 +00:00
|
|
|
|
2014-02-25 14:46:48 +00:00
|
|
|
Phaser.ScaleManager.prototype = {
|
2013-10-03 00:21:08 +00:00
|
|
|
|
2014-09-01 00:02:41 +00:00
|
|
|
/**
|
|
|
|
* Parses the Game configuration object.
|
|
|
|
*
|
|
|
|
* @method Phaser.ScaleManager#parseConfig
|
|
|
|
* @param {object} config - The game configuration object.
|
|
|
|
*/
|
|
|
|
parseConfig: function (config) {
|
2014-08-31 11:17:07 +00:00
|
|
|
|
2014-09-01 00:02:41 +00:00
|
|
|
if (config['scaleMode'])
|
2014-08-31 11:17:07 +00:00
|
|
|
{
|
2014-09-01 00:02:41 +00:00
|
|
|
this.scaleMode = config['scaleMode'];
|
|
|
|
}
|
2014-08-31 11:17:07 +00:00
|
|
|
|
2014-09-01 00:02:41 +00:00
|
|
|
if (config['fullScreenScaleMode'])
|
|
|
|
{
|
|
|
|
this.fullScreenScaleMode = config['fullScreenScaleMode'];
|
|
|
|
}
|
2014-08-31 11:17:07 +00:00
|
|
|
|
2014-09-01 00:02:41 +00:00
|
|
|
if (config['fullScreenTarget'])
|
|
|
|
{
|
|
|
|
this.fullScreenTarget = config['fullScreenTarget'];
|
2014-08-31 11:17:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2014-08-31 00:57:50 +00:00
|
|
|
/**
|
|
|
|
* Calculates and sets the game dimensions based on the given width and height.
|
|
|
|
*
|
2014-09-01 07:19:43 +00:00
|
|
|
* @method Phaser.ScaleManager#setupScale
|
2014-08-31 00:57:50 +00:00
|
|
|
* @param {number|string} width - The width of the game.
|
|
|
|
* @param {number|string} height - The height of the game.
|
|
|
|
*/
|
2014-09-01 07:19:43 +00:00
|
|
|
setupScale: function (width, height) {
|
2014-08-31 00:57:50 +00:00
|
|
|
|
|
|
|
var target;
|
|
|
|
var rect = new Phaser.Rectangle();
|
|
|
|
|
|
|
|
if (this.game.parent !== '')
|
|
|
|
{
|
|
|
|
if (typeof this.game.parent === 'string')
|
|
|
|
{
|
|
|
|
// hopefully an element ID
|
|
|
|
target = document.getElementById(this.game.parent);
|
|
|
|
}
|
|
|
|
else if (typeof this.game.parent === 'object' && this.game.parent.nodeType === 1)
|
|
|
|
{
|
|
|
|
// quick test for a HTMLelement
|
|
|
|
target = this.game.parent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fallback, covers an invalid ID and a non HTMLelement object
|
|
|
|
if (!target)
|
|
|
|
{
|
|
|
|
// Use the full window
|
2014-08-31 10:09:27 +00:00
|
|
|
this.parentNode = null;
|
|
|
|
this.parentIsWindow = true;
|
|
|
|
|
2014-08-31 00:57:50 +00:00
|
|
|
rect.width = window.innerWidth;
|
|
|
|
rect.height = window.innerHeight;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-31 10:09:27 +00:00
|
|
|
this.parentNode = target;
|
|
|
|
this.parentIsWindow = false;
|
|
|
|
|
2014-09-01 07:19:43 +00:00
|
|
|
this._parentBounds = this.parentNode.getBoundingClientRect();
|
|
|
|
|
|
|
|
rect.width = this._parentBounds.width;
|
|
|
|
rect.height = this._parentBounds.height;
|
|
|
|
|
|
|
|
this.offset.set(this._parentBounds.left, this._parentBounds.top);
|
2014-08-31 00:57:50 +00:00
|
|
|
}
|
|
|
|
|
2014-08-31 11:17:07 +00:00
|
|
|
var newWidth = 0;
|
|
|
|
var newHeight = 0;
|
|
|
|
|
2014-08-31 00:57:50 +00:00
|
|
|
if (typeof width === 'number')
|
|
|
|
{
|
2014-08-31 11:17:07 +00:00
|
|
|
newWidth = width;
|
2014-08-31 00:57:50 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Percentage based
|
2014-08-31 10:09:27 +00:00
|
|
|
this.parentScaleFactor.x = parseInt(width, 10) / 100;
|
2014-08-31 11:17:07 +00:00
|
|
|
newWidth = rect.width * this.parentScaleFactor.x;
|
2014-08-31 00:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof height === 'number')
|
|
|
|
{
|
2014-08-31 11:17:07 +00:00
|
|
|
newHeight = height;
|
2014-08-31 00:57:50 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Percentage based
|
2014-08-31 10:09:27 +00:00
|
|
|
this.parentScaleFactor.y = parseInt(height, 10) / 100;
|
2014-08-31 11:17:07 +00:00
|
|
|
newHeight = rect.height * this.parentScaleFactor.y;
|
2014-08-31 00:57:50 +00:00
|
|
|
}
|
|
|
|
|
2014-09-05 05:02:25 +00:00
|
|
|
this.grid = new Phaser.FlexGrid(this, newWidth, newHeight);
|
|
|
|
|
2014-09-01 00:02:41 +00:00
|
|
|
this.updateDimensions(newWidth, newHeight, false);
|
2014-08-31 11:17:07 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2014-09-01 07:19:43 +00:00
|
|
|
/**
|
|
|
|
* Calculates and sets the game dimensions based on the given width and height.
|
|
|
|
*
|
|
|
|
* @method Phaser.ScaleManager#boot
|
|
|
|
*/
|
|
|
|
boot: function () {
|
|
|
|
|
2014-09-05 00:07:51 +00:00
|
|
|
// Now the canvas has been created we can target it
|
|
|
|
this.fullScreenTarget = this.game.canvas;
|
|
|
|
|
2014-09-01 07:19:43 +00:00
|
|
|
var _this = this;
|
|
|
|
|
|
|
|
this._checkOrientation = function(event) {
|
|
|
|
return _this.checkOrientation(event);
|
|
|
|
};
|
|
|
|
|
|
|
|
this._checkResize = function(event) {
|
|
|
|
return _this.checkResize(event);
|
|
|
|
};
|
|
|
|
|
|
|
|
this._fullScreenChange = function(event) {
|
|
|
|
return _this.fullScreenChange(event);
|
|
|
|
};
|
|
|
|
|
|
|
|
window.addEventListener('orientationchange', this._checkOrientation, false);
|
|
|
|
window.addEventListener('resize', this._checkResize, false);
|
|
|
|
|
|
|
|
if (!this.game.device.cocoonJS)
|
|
|
|
{
|
|
|
|
document.addEventListener('webkitfullscreenchange', this._fullScreenChange, false);
|
|
|
|
document.addEventListener('mozfullscreenchange', this._fullScreenChange, false);
|
|
|
|
document.addEventListener('fullscreenchange', this._fullScreenChange, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.updateDimensions(this.width, this.height, true);
|
|
|
|
|
|
|
|
Phaser.Canvas.getOffset(this.game.canvas, this.offset);
|
|
|
|
|
|
|
|
this.bounds.setTo(this.offset.x, this.offset.y, this.width, this.height);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2014-09-01 00:02:41 +00:00
|
|
|
/**
|
|
|
|
* Sets the callback that will be called when the window resize event occurs, or if set the parent container changes dimensions.
|
|
|
|
* Use this to handle responsive game layout options.
|
|
|
|
* Note that the callback will only be called if the ScaleManager.scaleMode is set to RESIZE.
|
|
|
|
*
|
|
|
|
* @method Phaser.ScaleManager#setResizeCallback
|
|
|
|
* @param {function} callback - The callback that will be called each time a window.resize event happens or if set, the parent container resizes.
|
|
|
|
* @param {object} context - The context in which the callback will be called.
|
|
|
|
*/
|
|
|
|
setResizeCallback: function (callback, context) {
|
2014-08-31 00:57:50 +00:00
|
|
|
|
2014-09-01 00:02:41 +00:00
|
|
|
this.onResize = callback;
|
|
|
|
this.onResizeContext = context;
|
2014-08-31 00:57:50 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2014-09-01 02:07:17 +00:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2014-09-01 00:02:41 +00:00
|
|
|
* The ScaleManager.preUpdate is called automatically by the core Game loop.
|
|
|
|
*
|
|
|
|
* @method Phaser.ScaleManager#preUpdate
|
|
|
|
* @protected
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2014-09-01 00:02:41 +00:00
|
|
|
preUpdate: function () {
|
2013-09-09 11:35:20 +00:00
|
|
|
|
2014-09-01 02:20:09 +00:00
|
|
|
if (this.game.time.now < this._nextParentCheck)
|
2013-09-09 11:35:20 +00:00
|
|
|
{
|
2014-09-01 02:20:09 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-09-09 11:35:20 +00:00
|
|
|
|
2014-09-01 02:20:09 +00:00
|
|
|
if (!this.parentIsWindow)
|
|
|
|
{
|
2014-09-01 07:19:43 +00:00
|
|
|
Phaser.Canvas.getOffset(this.game.canvas, this.offset);
|
|
|
|
|
2014-09-01 02:20:09 +00:00
|
|
|
if (this._scaleMode === Phaser.ScaleManager.RESIZE)
|
2014-09-01 00:02:41 +00:00
|
|
|
{
|
2014-09-01 07:19:43 +00:00
|
|
|
this._parentBounds = this.parentNode.getBoundingClientRect();
|
|
|
|
|
2014-09-01 02:20:09 +00:00
|
|
|
if (this._parentBounds.width !== this.width || this._parentBounds.height !== this.height)
|
|
|
|
{
|
|
|
|
// The parent has changed size, so we need to adapt
|
|
|
|
this.updateDimensions(this._parentBounds.width, this._parentBounds.height, true);
|
|
|
|
}
|
2014-09-01 00:02:41 +00:00
|
|
|
}
|
2013-09-09 11:35:20 +00:00
|
|
|
}
|
2014-09-01 02:20:09 +00:00
|
|
|
|
|
|
|
this._nextParentCheck = this.game.time.now + this.trackParentInterval;
|
2013-09-09 11:35:20 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2014-09-01 00:02:41 +00:00
|
|
|
* Called automatically when the game parent dimensions change.
|
|
|
|
*
|
|
|
|
* @method updateDimensions
|
|
|
|
* @param {number} width - The new width of the parent container.
|
|
|
|
* @param {number} height - The new height of the parent container.
|
|
|
|
* @param {boolean} resize - True if the renderer should be resized, otherwise false to just update the internal vars.
|
|
|
|
*/
|
|
|
|
updateDimensions: function (width, height, resize) {
|
2013-09-09 11:35:20 +00:00
|
|
|
|
2014-09-01 00:02:41 +00:00
|
|
|
this.width = width * this.parentScaleFactor.x;
|
|
|
|
this.height = height * this.parentScaleFactor.y;
|
2013-09-09 11:35:20 +00:00
|
|
|
|
2014-09-01 00:02:41 +00:00
|
|
|
this.game.width = this.width;
|
|
|
|
this.game.height = this.height;
|
2013-09-09 11:35:20 +00:00
|
|
|
|
2014-09-01 00:02:41 +00:00
|
|
|
this.sourceAspectRatio = this.width / this.height;
|
2013-11-01 02:07:21 +00:00
|
|
|
|
2014-09-01 00:02:41 +00:00
|
|
|
this.bounds.width = this.width;
|
|
|
|
this.bounds.height = this.height;
|
2013-11-25 04:40:04 +00:00
|
|
|
|
2014-09-01 00:02:41 +00:00
|
|
|
if (resize)
|
2013-11-01 02:07:21 +00:00
|
|
|
{
|
2014-09-01 00:02:41 +00:00
|
|
|
this.game.renderer.resize(this.width, this.height);
|
2013-11-01 02:07:21 +00:00
|
|
|
|
2014-09-01 00:02:41 +00:00
|
|
|
// The Camera can never be smaller than the game size
|
|
|
|
this.game.camera.setSize(this.width, this.height);
|
2013-11-01 02:07:21 +00:00
|
|
|
|
2014-09-01 00:02:41 +00:00
|
|
|
// This should only happen if the world is smaller than the new canvas size
|
|
|
|
this.game.world.resize(this.width, this.height);
|
2013-11-01 02:07:21 +00:00
|
|
|
}
|
|
|
|
|
2014-09-05 05:02:25 +00:00
|
|
|
this.grid.onResize(width, height);
|
|
|
|
|
2014-09-01 00:02:41 +00:00
|
|
|
if (this.onResize)
|
|
|
|
{
|
|
|
|
this.onResize.call(this.onResizeContext, this.width, this.height);
|
2013-11-01 02:07:21 +00:00
|
|
|
}
|
|
|
|
|
2014-09-05 05:21:53 +00:00
|
|
|
this.game.state.resize(width, height);
|
|
|
|
|
2013-11-01 02:07:21 +00:00
|
|
|
},
|
|
|
|
|
2013-11-04 20:43:59 +00:00
|
|
|
/**
|
|
|
|
* If you need your game to run in only one orientation you can force that to happen.
|
2014-09-01 02:30:02 +00:00
|
|
|
*
|
2014-02-25 14:46:48 +00:00
|
|
|
* @method Phaser.ScaleManager#forceOrientation
|
2013-11-04 20:43:59 +00:00
|
|
|
* @param {boolean} forceLandscape - true if the game should run in landscape mode only.
|
2013-11-18 20:27:40 +00:00
|
|
|
* @param {boolean} [forcePortrait=false] - true if the game should run in portrait mode only.
|
2013-11-04 20:43:59 +00:00
|
|
|
*/
|
2014-09-01 02:30:02 +00:00
|
|
|
forceOrientation: function (forceLandscape, forcePortrait) {
|
2013-11-04 20:43:59 +00:00
|
|
|
|
2013-11-18 20:27:40 +00:00
|
|
|
if (typeof forcePortrait === 'undefined') { forcePortrait = false; }
|
2013-11-04 20:43:59 +00:00
|
|
|
|
2013-11-18 20:27:40 +00:00
|
|
|
this.forceLandscape = forceLandscape;
|
|
|
|
this.forcePortrait = forcePortrait;
|
2013-11-04 20:43:59 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2013-10-03 00:21:08 +00:00
|
|
|
* Checks if the browser is in the correct orientation for your game (if forceLandscape or forcePortrait have been set)
|
2014-09-01 02:30:02 +00:00
|
|
|
*
|
2014-02-25 14:46:48 +00:00
|
|
|
* @method Phaser.ScaleManager#checkOrientationState
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2013-09-09 11:35:20 +00:00
|
|
|
checkOrientationState: function () {
|
|
|
|
|
|
|
|
// They are in the wrong orientation
|
|
|
|
if (this.incorrectOrientation)
|
|
|
|
{
|
|
|
|
if ((this.forceLandscape && window.innerWidth > window.innerHeight) || (this.forcePortrait && window.innerHeight > window.innerWidth))
|
|
|
|
{
|
|
|
|
// Back to normal
|
|
|
|
this.incorrectOrientation = false;
|
2013-11-20 02:28:28 +00:00
|
|
|
this.leaveIncorrectOrientation.dispatch();
|
2013-11-04 20:43:59 +00:00
|
|
|
|
2014-02-28 04:15:28 +00:00
|
|
|
if (this.scaleMode !== Phaser.ScaleManager.NO_SCALE)
|
|
|
|
{
|
|
|
|
this.refresh();
|
|
|
|
}
|
2013-09-09 11:35:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((this.forceLandscape && window.innerWidth < window.innerHeight) || (this.forcePortrait && window.innerHeight < window.innerWidth))
|
|
|
|
{
|
|
|
|
// Show orientation screen
|
|
|
|
this.incorrectOrientation = true;
|
2013-11-20 02:28:28 +00:00
|
|
|
this.enterIncorrectOrientation.dispatch();
|
2013-11-04 20:43:59 +00:00
|
|
|
|
2014-02-28 04:15:28 +00:00
|
|
|
if (this.scaleMode !== Phaser.ScaleManager.NO_SCALE)
|
|
|
|
{
|
|
|
|
this.refresh();
|
|
|
|
}
|
2013-09-09 11:35:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2014-09-01 00:02:41 +00:00
|
|
|
* window.orientationchange event handler.
|
|
|
|
*
|
2014-02-25 14:46:48 +00:00
|
|
|
* @method Phaser.ScaleManager#checkOrientation
|
2013-10-03 00:21:08 +00:00
|
|
|
* @param {Event} event - The orientationchange event data.
|
2013-09-09 11:35:20 +00:00
|
|
|
*/
|
|
|
|
checkOrientation: function (event) {
|
|
|
|
|
2013-11-25 04:40:04 +00:00
|
|
|
this.event = event;
|
|
|
|
|
2013-09-09 11:35:20 +00:00
|
|
|
this.orientation = window['orientation'];
|
|
|
|
|
|
|
|
if (this.isLandscape)
|
|
|
|
{
|
|
|
|
this.enterLandscape.dispatch(this.orientation, true, false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.enterPortrait.dispatch(this.orientation, false, true);
|
|
|
|
}
|
|
|
|
|
2014-02-25 14:46:48 +00:00
|
|
|
if (this.scaleMode !== Phaser.ScaleManager.NO_SCALE)
|
2013-09-09 11:35:20 +00:00
|
|
|
{
|
|
|
|
this.refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2014-09-01 00:02:41 +00:00
|
|
|
* window.resize event handler.
|
|
|
|
*
|
2014-02-25 14:46:48 +00:00
|
|
|
* @method Phaser.ScaleManager#checkResize
|
2013-10-03 00:21:08 +00:00
|
|
|
* @param {Event} event - The resize event data.
|
2013-09-09 11:35:20 +00:00
|
|
|
*/
|
|
|
|
checkResize: function (event) {
|
|
|
|
|
2013-11-25 04:40:04 +00:00
|
|
|
this.event = event;
|
|
|
|
|
2014-09-01 00:02:41 +00:00
|
|
|
var wasLandscape = this.isLandscape;
|
|
|
|
|
2013-09-09 11:35:20 +00:00
|
|
|
if (window.outerWidth > window.outerHeight)
|
|
|
|
{
|
|
|
|
this.orientation = 90;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.orientation = 0;
|
|
|
|
}
|
|
|
|
|
2014-09-01 00:02:41 +00:00
|
|
|
// If it WAS in Landscape but is now in portrait ...
|
|
|
|
if (wasLandscape && this.isPortrait)
|
2013-09-09 11:35:20 +00:00
|
|
|
{
|
2014-09-01 00:02:41 +00:00
|
|
|
this.enterPortrait.dispatch(this.orientation, false, true);
|
|
|
|
|
|
|
|
if (this.forceLandscape)
|
|
|
|
{
|
|
|
|
this.enterIncorrectOrientation.dispatch();
|
|
|
|
}
|
|
|
|
else if (this.forcePortrait)
|
|
|
|
{
|
|
|
|
this.leaveIncorrectOrientation.dispatch();
|
|
|
|
}
|
2013-09-09 11:35:20 +00:00
|
|
|
}
|
2014-09-01 00:02:41 +00:00
|
|
|
else if (!wasLandscape && this.isLandscape)
|
2013-09-09 11:35:20 +00:00
|
|
|
{
|
2014-09-01 00:02:41 +00:00
|
|
|
// It WAS in portrait mode, but is now in Landscape ...
|
|
|
|
this.enterLandscape.dispatch(this.orientation, true, false);
|
|
|
|
|
|
|
|
if (this.forceLandscape)
|
|
|
|
{
|
|
|
|
this.leaveIncorrectOrientation.dispatch();
|
|
|
|
}
|
|
|
|
else if (this.forcePortrait)
|
|
|
|
{
|
|
|
|
this.enterIncorrectOrientation.dispatch();
|
|
|
|
}
|
2013-09-09 11:35:20 +00:00
|
|
|
}
|
|
|
|
|
2014-09-01 00:02:41 +00:00
|
|
|
if (this._scaleMode === Phaser.ScaleManager.RESIZE && this.parentIsWindow)
|
|
|
|
{
|
|
|
|
// The window has changed size, so we need to adapt
|
|
|
|
this.updateDimensions(window.innerWidth, window.innerHeight, true);
|
|
|
|
}
|
|
|
|
else if (this._scaleMode === Phaser.ScaleManager.EXACT_FIT || this._scaleMode === Phaser.ScaleManager.SHOW_ALL)
|
2013-09-09 11:35:20 +00:00
|
|
|
{
|
|
|
|
this.refresh();
|
2014-09-01 00:02:41 +00:00
|
|
|
this.checkOrientationState();
|
|
|
|
|
|
|
|
if (this.onResize)
|
|
|
|
{
|
|
|
|
this.onResize.call(this.onResizeContext, this.width, this.height);
|
|
|
|
}
|
2013-09-09 11:35:20 +00:00
|
|
|
}
|
2013-11-04 20:43:59 +00:00
|
|
|
|
2013-09-09 11:35:20 +00:00
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2014-09-09 11:48:21 +00:00
|
|
|
* Re-calculate scale mode and update screen size. This only applies if ScaleMode is not set to RESIZE.
|
2014-09-01 00:02:41 +00:00
|
|
|
*
|
2014-02-25 14:46:48 +00:00
|
|
|
* @method Phaser.ScaleManager#refresh
|
2013-09-09 11:35:20 +00:00
|
|
|
*/
|
|
|
|
refresh: function () {
|
|
|
|
|
2014-09-09 11:48:21 +00:00
|
|
|
// Not needed for RESIZE
|
|
|
|
if (this.scaleMode === Phaser.ScaleManager.RESIZE)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-09 11:35:20 +00:00
|
|
|
// We can't do anything about the status bars in iPads, web apps or desktops
|
2014-04-27 09:17:37 +00:00
|
|
|
if (!this.game.device.iPad && !this.game.device.webApp && !this.game.device.desktop)
|
2013-09-09 11:35:20 +00:00
|
|
|
{
|
2014-04-27 09:17:37 +00:00
|
|
|
if (this.game.device.android && !this.game.device.chrome)
|
2013-09-09 11:35:20 +00:00
|
|
|
{
|
|
|
|
window.scrollTo(0, 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
window.scrollTo(0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-27 09:17:37 +00:00
|
|
|
if (this._check === null && this.maxIterations > 0)
|
2013-09-09 11:35:20 +00:00
|
|
|
{
|
|
|
|
this._iterations = this.maxIterations;
|
2013-11-24 11:04:58 +00:00
|
|
|
|
|
|
|
var _this = this;
|
|
|
|
|
2013-09-09 11:35:20 +00:00
|
|
|
this._check = window.setInterval(function () {
|
|
|
|
return _this.setScreenSize();
|
|
|
|
}, 10);
|
2013-11-24 11:04:58 +00:00
|
|
|
|
2013-09-09 11:35:20 +00:00
|
|
|
this.setScreenSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2014-09-09 11:48:21 +00:00
|
|
|
* Set screen size automatically based on the scaleMode. This is only needed if ScaleMode is not set to RESIZE.
|
2014-09-01 00:02:41 +00:00
|
|
|
*
|
2013-11-04 20:43:59 +00:00
|
|
|
* @param {boolean} force - If force is true it will try to resize the game regardless of the document dimensions.
|
2013-09-09 11:35:20 +00:00
|
|
|
*/
|
|
|
|
setScreenSize: function (force) {
|
|
|
|
|
2014-09-09 11:48:21 +00:00
|
|
|
if (this.scaleMode === Phaser.ScaleManager.RESIZE)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-27 09:17:37 +00:00
|
|
|
if (typeof force === 'undefined')
|
2013-09-10 15:46:39 +00:00
|
|
|
{
|
|
|
|
force = false;
|
|
|
|
}
|
2014-03-23 07:59:28 +00:00
|
|
|
|
2014-04-27 09:17:37 +00:00
|
|
|
if (!this.game.device.iPad && !this.game.device.webApp && !this.game.device.desktop)
|
2013-09-09 11:35:20 +00:00
|
|
|
{
|
2014-04-27 09:17:37 +00:00
|
|
|
if (this.game.device.android && !this.game.device.chrome)
|
2013-09-09 11:35:20 +00:00
|
|
|
{
|
|
|
|
window.scrollTo(0, 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
window.scrollTo(0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this._iterations--;
|
|
|
|
|
2014-09-01 01:44:35 +00:00
|
|
|
if (force || this._iterations < 0)
|
2013-09-09 11:35:20 +00:00
|
|
|
{
|
|
|
|
// Set minimum height of content to new window height
|
|
|
|
document.documentElement['style'].minHeight = window.innerHeight + 'px';
|
2014-03-23 07:59:28 +00:00
|
|
|
|
2014-04-27 09:17:37 +00:00
|
|
|
if (this.incorrectOrientation)
|
2013-09-10 15:46:39 +00:00
|
|
|
{
|
2013-09-09 11:35:20 +00:00
|
|
|
this.setMaximum();
|
|
|
|
}
|
2013-12-05 01:00:36 +00:00
|
|
|
else if (!this.isFullScreen)
|
2013-09-09 11:35:20 +00:00
|
|
|
{
|
2014-04-27 09:17:37 +00:00
|
|
|
if (this.scaleMode === Phaser.ScaleManager.EXACT_FIT)
|
2013-12-05 01:00:36 +00:00
|
|
|
{
|
|
|
|
this.setExactFit();
|
|
|
|
}
|
2014-04-27 09:17:37 +00:00
|
|
|
else if (this.scaleMode === Phaser.ScaleManager.SHOW_ALL)
|
2013-12-05 01:00:36 +00:00
|
|
|
{
|
|
|
|
this.setShowAll();
|
|
|
|
}
|
2013-09-09 11:35:20 +00:00
|
|
|
}
|
2013-12-05 01:00:36 +00:00
|
|
|
else
|
2013-09-09 11:35:20 +00:00
|
|
|
{
|
2014-04-27 09:17:37 +00:00
|
|
|
if (this.fullScreenScaleMode === Phaser.ScaleManager.EXACT_FIT)
|
2013-12-05 01:00:36 +00:00
|
|
|
{
|
|
|
|
this.setExactFit();
|
|
|
|
}
|
2014-04-27 09:17:37 +00:00
|
|
|
else if (this.fullScreenScaleMode === Phaser.ScaleManager.SHOW_ALL)
|
2013-12-05 01:00:36 +00:00
|
|
|
{
|
|
|
|
this.setShowAll();
|
|
|
|
}
|
2013-09-09 11:35:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.setSize();
|
|
|
|
clearInterval(this._check);
|
|
|
|
this._check = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2013-10-03 00:21:08 +00:00
|
|
|
* Sets the canvas style width and height values based on minWidth/Height and maxWidth/Height.
|
2014-09-01 00:02:41 +00:00
|
|
|
*
|
2014-02-25 14:46:48 +00:00
|
|
|
* @method Phaser.ScaleManager#setSize
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2013-09-09 11:35:20 +00:00
|
|
|
setSize: function () {
|
|
|
|
|
2014-04-27 09:17:37 +00:00
|
|
|
if (!this.incorrectOrientation)
|
2013-09-09 11:35:20 +00:00
|
|
|
{
|
|
|
|
if (this.maxWidth && this.width > this.maxWidth)
|
|
|
|
{
|
|
|
|
this.width = this.maxWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.maxHeight && this.height > this.maxHeight)
|
|
|
|
{
|
|
|
|
this.height = this.maxHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.minWidth && this.width < this.minWidth)
|
|
|
|
{
|
|
|
|
this.width = this.minWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.minHeight && this.height < this.minHeight)
|
|
|
|
{
|
|
|
|
this.height = this.minHeight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-10 15:46:39 +00:00
|
|
|
this.game.canvas.style.width = this.width + 'px';
|
|
|
|
this.game.canvas.style.height = this.height + 'px';
|
2014-03-23 07:59:28 +00:00
|
|
|
|
2013-09-10 15:46:39 +00:00
|
|
|
this.game.input.scale.setTo(this.game.width / this.width, this.game.height / this.height);
|
2013-09-09 11:35:20 +00:00
|
|
|
|
|
|
|
if (this.pageAlignHorizontally)
|
|
|
|
{
|
2014-04-27 09:17:37 +00:00
|
|
|
if (this.width < window.innerWidth && !this.incorrectOrientation)
|
2013-09-09 11:35:20 +00:00
|
|
|
{
|
2013-11-24 11:04:58 +00:00
|
|
|
this.margin.x = Math.round((window.innerWidth - this.width) / 2);
|
|
|
|
this.game.canvas.style.marginLeft = this.margin.x + 'px';
|
2013-09-09 11:35:20 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-24 11:04:58 +00:00
|
|
|
this.margin.x = 0;
|
2013-09-10 15:46:39 +00:00
|
|
|
this.game.canvas.style.marginLeft = '0px';
|
2013-09-09 11:35:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-06 15:27:39 +00:00
|
|
|
if (this.pageAlignVertically)
|
2013-09-09 11:35:20 +00:00
|
|
|
{
|
2014-04-27 09:17:37 +00:00
|
|
|
if (this.height < window.innerHeight && !this.incorrectOrientation)
|
2013-09-09 11:35:20 +00:00
|
|
|
{
|
2013-11-24 11:04:58 +00:00
|
|
|
this.margin.y = Math.round((window.innerHeight - this.height) / 2);
|
|
|
|
this.game.canvas.style.marginTop = this.margin.y + 'px';
|
2013-09-09 11:35:20 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-24 11:04:58 +00:00
|
|
|
this.margin.y = 0;
|
2013-09-10 15:46:39 +00:00
|
|
|
this.game.canvas.style.marginTop = '0px';
|
2013-09-09 11:35:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-01 07:19:43 +00:00
|
|
|
Phaser.Canvas.getOffset(this.game.canvas, this.offset);
|
|
|
|
this.bounds.setTo(this.offset.x, this.offset.y, this.width, this.height);
|
2014-05-19 17:49:16 +00:00
|
|
|
|
2013-09-09 11:35:20 +00:00
|
|
|
this.aspectRatio = this.width / this.height;
|
2014-03-23 07:59:28 +00:00
|
|
|
|
2013-09-10 15:46:39 +00:00
|
|
|
this.scaleFactor.x = this.game.width / this.width;
|
|
|
|
this.scaleFactor.y = this.game.height / this.height;
|
|
|
|
|
2013-11-24 11:04:58 +00:00
|
|
|
this.scaleFactorInversed.x = this.width / this.game.width;
|
|
|
|
this.scaleFactorInversed.y = this.height / this.game.height;
|
|
|
|
|
2013-11-04 20:43:59 +00:00
|
|
|
this.checkOrientationState();
|
|
|
|
|
2013-09-09 11:35:20 +00:00
|
|
|
},
|
|
|
|
|
2014-09-05 05:21:53 +00:00
|
|
|
reset: function (clearWorld) {
|
|
|
|
|
|
|
|
if (clearWorld)
|
|
|
|
{
|
|
|
|
this.grid.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2014-09-01 00:02:41 +00:00
|
|
|
* Sets this.width equal to window.innerWidth and this.height equal to window.innerHeight.
|
|
|
|
*
|
2014-02-25 14:46:48 +00:00
|
|
|
* @method Phaser.ScaleManager#setMaximum
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2013-09-09 11:35:20 +00:00
|
|
|
setMaximum: function () {
|
|
|
|
|
|
|
|
this.width = window.innerWidth;
|
|
|
|
this.height = window.innerHeight;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2013-10-03 00:21:08 +00:00
|
|
|
* Calculates the multiplier needed to scale the game proportionally.
|
2014-09-01 00:02:41 +00:00
|
|
|
*
|
2014-02-25 14:46:48 +00:00
|
|
|
* @method Phaser.ScaleManager#setShowAll
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2013-09-09 11:35:20 +00:00
|
|
|
setShowAll: function () {
|
|
|
|
|
2013-09-10 15:46:39 +00:00
|
|
|
var multiplier = Math.min((window.innerHeight / this.game.height), (window.innerWidth / this.game.width));
|
2013-09-09 11:35:20 +00:00
|
|
|
|
2013-09-10 15:46:39 +00:00
|
|
|
this.width = Math.round(this.game.width * multiplier);
|
|
|
|
this.height = Math.round(this.game.height * multiplier);
|
2013-09-09 11:35:20 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2013-10-03 00:21:08 +00:00
|
|
|
* Sets the width and height values of the canvas, no larger than the maxWidth/Height.
|
2014-09-01 00:02:41 +00:00
|
|
|
*
|
2014-02-25 14:46:48 +00:00
|
|
|
* @method Phaser.ScaleManager#setExactFit
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2013-09-09 11:35:20 +00:00
|
|
|
setExactFit: function () {
|
|
|
|
|
2013-11-01 02:07:21 +00:00
|
|
|
var availableWidth = window.innerWidth;
|
|
|
|
var availableHeight = window.innerHeight;
|
2013-09-10 15:46:39 +00:00
|
|
|
|
|
|
|
if (this.maxWidth && availableWidth > this.maxWidth)
|
2013-09-09 11:35:20 +00:00
|
|
|
{
|
|
|
|
this.width = this.maxWidth;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-10 15:46:39 +00:00
|
|
|
this.width = availableWidth;
|
2013-09-09 11:35:20 +00:00
|
|
|
}
|
|
|
|
|
2013-09-10 15:46:39 +00:00
|
|
|
if (this.maxHeight && availableHeight > this.maxHeight)
|
2013-09-09 11:35:20 +00:00
|
|
|
{
|
|
|
|
this.height = this.maxHeight;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-10 15:46:39 +00:00
|
|
|
this.height = availableHeight;
|
2013-09-09 11:35:20 +00:00
|
|
|
}
|
|
|
|
|
2014-08-28 02:31:47 +00:00
|
|
|
},
|
|
|
|
|
2014-09-01 00:02:41 +00:00
|
|
|
/**
|
|
|
|
* Tries to enter the browser into full screen mode.
|
|
|
|
* Please note that this needs to be supported by the web browser and isn't the same thing as setting your game to fill the browser.
|
|
|
|
*
|
|
|
|
* @method Phaser.ScaleManager#startFullScreen
|
|
|
|
* @param {boolean} antialias - You can toggle the anti-alias feature of the canvas before jumping in to full screen (false = retain pixel art, true = smooth art)
|
|
|
|
*/
|
|
|
|
startFullScreen: function (antialias) {
|
|
|
|
|
|
|
|
if (this.isFullScreen || !this.game.device.fullscreen)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof antialias !== 'undefined' && this.game.renderType === Phaser.CANVAS)
|
|
|
|
{
|
|
|
|
this.game.stage.smoothed = antialias;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._width = this.width;
|
|
|
|
this._height = this.height;
|
|
|
|
|
|
|
|
if (this.game.device.fullscreenKeyboard)
|
|
|
|
{
|
|
|
|
this.fullScreenTarget[this.game.device.requestFullscreen](Element.ALLOW_KEYBOARD_INPUT);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.fullScreenTarget[this.game.device.requestFullscreen]();
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stops full screen mode if the browser is in it.
|
|
|
|
* @method Phaser.ScaleManager#stopFullScreen
|
|
|
|
*/
|
|
|
|
stopFullScreen: function () {
|
|
|
|
|
|
|
|
document[this.game.device.cancelFullscreen]();
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called automatically when the browser enters of leaves full screen mode.
|
|
|
|
* @method Phaser.ScaleManager#fullScreenChange
|
|
|
|
* @param {Event} event - The fullscreenchange event
|
|
|
|
* @protected
|
|
|
|
*/
|
|
|
|
fullScreenChange: function (event) {
|
|
|
|
|
|
|
|
this.event = event;
|
|
|
|
|
|
|
|
if (this.isFullScreen)
|
|
|
|
{
|
|
|
|
if (this.fullScreenScaleMode === Phaser.ScaleManager.EXACT_FIT)
|
|
|
|
{
|
|
|
|
this.fullScreenTarget.style['width'] = '100%';
|
|
|
|
this.fullScreenTarget.style['height'] = '100%';
|
|
|
|
|
|
|
|
this.width = window.outerWidth;
|
|
|
|
this.height = window.outerHeight;
|
|
|
|
|
|
|
|
this.game.input.scale.setTo(this.game.width / this.width, this.game.height / this.height);
|
|
|
|
|
|
|
|
this.aspectRatio = this.width / this.height;
|
|
|
|
this.scaleFactor.x = this.game.width / this.width;
|
|
|
|
this.scaleFactor.y = this.game.height / this.height;
|
|
|
|
|
|
|
|
this.checkResize();
|
|
|
|
}
|
|
|
|
else if (this.fullScreenScaleMode === Phaser.ScaleManager.SHOW_ALL)
|
|
|
|
{
|
|
|
|
this.setShowAll();
|
|
|
|
this.refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.enterFullScreen.dispatch(this.width, this.height);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.fullScreenTarget.style['width'] = this.game.width + 'px';
|
|
|
|
this.fullScreenTarget.style['height'] = this.game.height + 'px';
|
|
|
|
|
|
|
|
this.width = this._width;
|
|
|
|
this.height = this._height;
|
|
|
|
|
|
|
|
this.game.input.scale.setTo(this.game.width / this.width, this.game.height / this.height);
|
|
|
|
|
|
|
|
this.aspectRatio = this.width / this.height;
|
|
|
|
this.scaleFactor.x = this.game.width / this.width;
|
|
|
|
this.scaleFactor.y = this.game.height / this.height;
|
|
|
|
|
|
|
|
this.leaveFullScreen.dispatch(this.width, this.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2014-08-28 02:31:47 +00:00
|
|
|
/**
|
|
|
|
* Destroys the ScaleManager and removes any event listeners.
|
|
|
|
*
|
|
|
|
* @method destroy
|
|
|
|
*/
|
|
|
|
destroy: function () {
|
|
|
|
|
2014-08-28 20:54:09 +00:00
|
|
|
window.removeEventListener('orientationchange', this._checkOrientation, false);
|
|
|
|
window.removeEventListener('resize', this._checkResize, false);
|
2014-08-28 02:31:47 +00:00
|
|
|
|
|
|
|
if (!this.game.device.cocoonJS)
|
|
|
|
{
|
2014-08-28 20:54:09 +00:00
|
|
|
document.removeEventListener('webkitfullscreenchange', this._fullScreenChange, false);
|
|
|
|
document.removeEventListener('mozfullscreenchange', this._fullScreenChange, false);
|
|
|
|
document.removeEventListener('fullscreenchange', this._fullScreenChange, false);
|
2014-08-28 02:31:47 +00:00
|
|
|
}
|
|
|
|
|
2013-09-09 11:35:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2014-02-25 14:46:48 +00:00
|
|
|
Phaser.ScaleManager.prototype.constructor = Phaser.ScaleManager;
|
2013-12-30 16:54:00 +00:00
|
|
|
|
2014-08-31 10:09:27 +00:00
|
|
|
/**
|
|
|
|
* @name Phaser.ScaleManager#scaleMode
|
|
|
|
* @property {number} scaleMode - The scaling method used by the ScaleManager.
|
|
|
|
*/
|
|
|
|
Object.defineProperty(Phaser.ScaleManager.prototype, "scaleMode", {
|
|
|
|
|
|
|
|
get: function () {
|
|
|
|
|
|
|
|
return this._scaleMode;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value) {
|
|
|
|
|
|
|
|
if (value !== this._scaleMode)
|
|
|
|
{
|
|
|
|
this._scaleMode = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2014-02-25 14:46:48 +00:00
|
|
|
* @name Phaser.ScaleManager#isFullScreen
|
2013-10-03 00:21:08 +00:00
|
|
|
* @property {boolean} isFullScreen - Returns true if the browser is in full screen mode, otherwise false.
|
|
|
|
* @readonly
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2014-02-25 14:46:48 +00:00
|
|
|
Object.defineProperty(Phaser.ScaleManager.prototype, "isFullScreen", {
|
2013-09-09 11:35:20 +00:00
|
|
|
|
|
|
|
get: function () {
|
2014-03-23 08:29:04 +00:00
|
|
|
return (document['fullscreenElement'] || document['mozFullScreenElement'] || document['webkitFullscreenElement']);
|
2013-09-11 12:21:07 +00:00
|
|
|
}
|
2013-09-09 11:35:20 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2014-02-25 14:46:48 +00:00
|
|
|
* @name Phaser.ScaleManager#isPortrait
|
2013-10-03 00:21:08 +00:00
|
|
|
* @property {boolean} isPortrait - Returns true if the browser dimensions match a portrait display.
|
|
|
|
* @readonly
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2014-02-25 14:46:48 +00:00
|
|
|
Object.defineProperty(Phaser.ScaleManager.prototype, "isPortrait", {
|
2013-09-09 11:35:20 +00:00
|
|
|
|
|
|
|
get: function () {
|
2014-04-27 09:17:37 +00:00
|
|
|
return (this.orientation === 0 || this.orientation === 180);
|
2013-09-11 12:21:07 +00:00
|
|
|
}
|
2013-09-09 11:35:20 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2014-02-25 14:46:48 +00:00
|
|
|
* @name Phaser.ScaleManager#isLandscape
|
2013-10-03 00:21:08 +00:00
|
|
|
* @property {boolean} isLandscape - Returns true if the browser dimensions match a landscape display.
|
|
|
|
* @readonly
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2014-02-25 14:46:48 +00:00
|
|
|
Object.defineProperty(Phaser.ScaleManager.prototype, "isLandscape", {
|
2013-09-09 11:35:20 +00:00
|
|
|
|
|
|
|
get: function () {
|
2014-04-27 09:17:37 +00:00
|
|
|
return (this.orientation === 90 || this.orientation === -90);
|
2013-09-11 12:21:07 +00:00
|
|
|
}
|
2013-09-09 11:35:20 +00:00
|
|
|
|
|
|
|
});
|