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-10-31 10:29:54 +00:00
|
|
|
* The ScaleManager object is responsible managing the scaling, resizing and alignment of the game and display canvas.
|
|
|
|
*
|
|
|
|
* The `width` and `height` constructor parameters can either be a number which represents pixels or a string that represents a percentage: e.g. `800` (for 800 pixels) or `"80%"` for 80%.
|
2013-10-01 12:54:29 +00:00
|
|
|
*
|
2014-11-08 13:24:38 +00:00
|
|
|
* Some parts of ScaleManager were inspired by the research of Ryan Van Etten, released under MIT License 2013.
|
|
|
|
*
|
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-10-31 10:29:54 +00:00
|
|
|
* @param {number|string} width - The width of the game. See above.
|
|
|
|
* @param {number|string} height - The height of the game. See above.
|
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
|
|
|
|
|
|
|
/**
|
2014-10-31 10:29:54 +00:00
|
|
|
* A reference to the currently running game.
|
|
|
|
* @property {Phaser.Game} game
|
|
|
|
* @protected
|
|
|
|
* @readonly
|
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-10-31 10:29:54 +00:00
|
|
|
* _EXPERIMENTAL:_ A responsive grid on which you can align game objects.
|
|
|
|
* @property {Phaser.FlexGrid} gridobjects.
|
|
|
|
* @public
|
2014-09-05 05:02:25 +00:00
|
|
|
*/
|
|
|
|
this.grid = null;
|
|
|
|
|
2013-09-09 11:35:20 +00:00
|
|
|
/**
|
2014-11-08 09:13:25 +00:00
|
|
|
* Target width (in pixels) of the Game canvas.
|
2014-10-31 08:41:06 +00:00
|
|
|
* @property {number} width
|
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-11-08 09:13:25 +00:00
|
|
|
* Target height (in pixels) of the Game canvas.
|
2014-10-31 08:41:06 +00:00
|
|
|
* @property {number} height
|
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
|
|
|
|
|
|
|
/**
|
2014-10-31 10:29:54 +00:00
|
|
|
* Minimum width the canvas should be scaled to (in pixels).
|
|
|
|
* Change with `setMinMax`.
|
|
|
|
* @property {number} minWidth
|
|
|
|
* @readonly
|
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-10-31 10:29:54 +00:00
|
|
|
* Maximum width the canvas should be scaled to (in pixels).
|
|
|
|
* If null it will scale to whatever width the browser can handle.
|
|
|
|
* Change with `setMinMax`.
|
|
|
|
* @property {number} maxWidth
|
|
|
|
* @readonly
|
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
|
|
|
|
|
|
|
/**
|
2014-10-31 10:29:54 +00:00
|
|
|
* Minimum height the canvas should be scaled to (in pixels).
|
|
|
|
* Change with `setMinMax`.
|
|
|
|
* @property {number} minHeight
|
|
|
|
* @readonly
|
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-10-31 10:29:54 +00:00
|
|
|
* Maximum height the canvas should be scaled to (in pixels).
|
|
|
|
* If null it will scale to whatever height the browser can handle.
|
|
|
|
* Change with `setMinMax`.
|
|
|
|
* @property {number} maxHeight
|
|
|
|
* @readonly
|
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
|
|
|
/**
|
2014-11-09 00:38:21 +00:00
|
|
|
* The offset coordinates of the Game canvas from the top-left of the browser window.
|
|
|
|
* The is used internally by Phaser.Pointer (for Input) and possibly other types.
|
2014-10-31 10:29:54 +00:00
|
|
|
* @property {Phaser.Point} offset
|
|
|
|
* @readonly
|
|
|
|
* @protected
|
2014-08-31 11:17:07 +00:00
|
|
|
*/
|
|
|
|
this.offset = new Phaser.Point();
|
|
|
|
|
2013-09-09 11:35:20 +00:00
|
|
|
/**
|
2014-10-31 10:29:54 +00:00
|
|
|
* If true, the game should only run in a landscape orientation.
|
|
|
|
* Change with `forceOrientation`.
|
|
|
|
* @property {boolean} forceLandscape
|
|
|
|
* @readonly
|
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-10-31 10:29:54 +00:00
|
|
|
* If true, the game should only run in a portrait
|
|
|
|
* Change with `forceOrientation`.
|
|
|
|
* @property {boolean} forcePortrait
|
|
|
|
* @readonly
|
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-10-31 10:29:54 +00:00
|
|
|
* True if the `forceLandscape` or `forcePortrait` are set and do not agree with the browser orientation.
|
2014-10-31 08:41:06 +00:00
|
|
|
* @property {boolean} incorrectOrientation
|
2014-10-31 10:29:54 +00:00
|
|
|
* @protected
|
|
|
|
* @readonly
|
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
|
|
|
|
|
|
|
/**
|
2014-11-07 21:18:56 +00:00
|
|
|
* See `pageAlignHorizontally`.
|
|
|
|
* @property {boolean} _pageAlignHorizontally
|
2014-10-31 08:41:06 +00:00
|
|
|
* @private
|
2013-09-09 11:35:20 +00:00
|
|
|
*/
|
2014-10-31 08:41:06 +00:00
|
|
|
this._pageAlignHorizontally = false;
|
2013-09-09 11:35:20 +00:00
|
|
|
|
|
|
|
/**
|
2014-11-07 21:18:56 +00:00
|
|
|
* See `pageAlignVertically`.
|
|
|
|
* @property {boolean} _pageAlignVertically
|
2014-10-31 08:41:06 +00:00
|
|
|
* @private
|
2013-11-01 02:07:21 +00:00
|
|
|
*/
|
2014-10-31 08:41:06 +00:00
|
|
|
this._pageAlignVertically = false;
|
2013-11-01 02:07:21 +00:00
|
|
|
|
2013-09-09 11:35:20 +00:00
|
|
|
/**
|
2014-10-31 08:41:06 +00:00
|
|
|
* The maximum number of times a canvas will be resized (in a row) in order to fill the browser.
|
|
|
|
* @property {number} maxIterations
|
2014-10-31 10:29:54 +00:00
|
|
|
* @protected
|
2013-10-01 12:54:29 +00:00
|
|
|
* @default
|
2014-11-09 00:38:21 +00:00
|
|
|
* @deprecated 2.1.4 - This is not used anymore as reflow iterations are "automatic".
|
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-10-31 10:29:54 +00:00
|
|
|
* This signal is dispatched when the browser enters landscape orientation, having been in portrait.
|
|
|
|
* @property {Phaser.Signal} enterLandscape
|
|
|
|
* @public
|
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-10-31 10:29:54 +00:00
|
|
|
* This signal is dispatched when the browser enters portrait orientation, having been in landscape.
|
|
|
|
* @property {Phaser.Signal} enterPortrait
|
|
|
|
* @public
|
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
|
|
|
/**
|
2014-10-31 10:29:54 +00:00
|
|
|
* This signal is dispatched when the browser enters an incorrect orientation, as defined by `forceOrientation`.
|
|
|
|
* @property {Phaser.Signal} enterIncorrectOrientation
|
|
|
|
* @public
|
2013-11-20 02:28:28 +00:00
|
|
|
*/
|
|
|
|
this.enterIncorrectOrientation = new Phaser.Signal();
|
|
|
|
|
|
|
|
/**
|
2014-10-31 10:29:54 +00:00
|
|
|
* This signal is dispatched when the browser leaves an incorrect orientation, as defined by `forceOrientation`.
|
|
|
|
* @property {Phaser.Signal} leaveIncorrectOrientation -
|
|
|
|
* @public
|
2013-11-20 02:28:28 +00:00
|
|
|
*/
|
|
|
|
this.leaveIncorrectOrientation = new Phaser.Signal();
|
|
|
|
|
2014-03-10 01:13:01 +00:00
|
|
|
/**
|
2014-11-09 00:38:21 +00:00
|
|
|
* This is the DOM element on which the Full Screen API will be invoked.
|
|
|
|
* It can be any valid DOM element - the target element must have the correct CSS styling and should contain the game canvas.
|
2014-10-31 08:41:06 +00:00
|
|
|
*
|
2014-11-07 21:18:56 +00:00
|
|
|
* This element's style will be modified (ie. the width and height might be set to 100%)
|
|
|
|
* but it will not be added to, removed from, or repositioned within the DOM.
|
|
|
|
* An attempt is made to restore relevant style changes when fullscreen mode is left.
|
2014-10-31 08:41:06 +00:00
|
|
|
*
|
2014-11-09 00:38:21 +00:00
|
|
|
* For pre 2.1.4 behavior set `game.scale.fullScreenTarget = game.canvas`.
|
2014-11-08 09:13:25 +00:00
|
|
|
*
|
2014-10-31 08:41:06 +00:00
|
|
|
* @property {DOMElement|null} fullScreenTarget
|
2014-11-08 09:13:25 +00:00
|
|
|
* @default
|
|
|
|
* @deprecated 2.1.4 - See `createFullScreenTarget` as an alternative.
|
2014-03-10 01:13:01 +00:00
|
|
|
*/
|
2014-09-05 00:07:51 +00:00
|
|
|
this.fullScreenTarget = null;
|
2014-03-10 01:13:01 +00:00
|
|
|
|
2014-11-07 21:18:56 +00:00
|
|
|
/**
|
2014-11-09 00:38:21 +00:00
|
|
|
* The `createFullScreenTarget` function creates a fullscreen target when `fullScreenTarget` is not set.
|
|
|
|
*
|
|
|
|
* The Game canvas is moved onto the created element for the duration of the fullscreen mode
|
|
|
|
* and restored to it's original DOM location when fullscreen is exited.
|
2014-11-07 21:18:56 +00:00
|
|
|
*
|
2014-11-09 00:38:21 +00:00
|
|
|
* The returned element (which should probably be newly created) is moved/reparanted within
|
|
|
|
* the DOM and may have its CSS styles updated. Assign an element to `fullScreenTarget` to avoid
|
|
|
|
* this DOM manipulation and revert to earlier behavior.
|
2014-11-07 21:18:56 +00:00
|
|
|
*
|
2014-11-09 00:38:21 +00:00
|
|
|
* The default implementation is to create a new element with a black background.
|
2014-11-07 21:18:56 +00:00
|
|
|
*
|
|
|
|
* @public {function} createFullScreenTarget
|
|
|
|
*/
|
|
|
|
this.createFullScreenTarget = function () {
|
|
|
|
var fsTarget = document.createElement('div');
|
2014-11-09 00:38:21 +00:00
|
|
|
fsTarget.style.margin = '0';
|
|
|
|
fsTarget.style.padding = '0';
|
|
|
|
fsTarget.style.background = '#000';
|
2014-11-07 21:18:56 +00:00
|
|
|
return fsTarget;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2014-11-09 00:38:21 +00:00
|
|
|
* The fullscreen target, as created by `createFullScreenTarget`.
|
|
|
|
* This is not set if `fullScreenTarget` is used and is cleared when fullscreen mode ends.
|
2014-11-08 09:13:25 +00:00
|
|
|
* @property {DOMElement|null} _createdFullScreenTarget
|
2014-11-07 21:18:56 +00:00
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._createdFullScreenTarget = null;
|
|
|
|
|
2014-02-25 17:10:37 +00:00
|
|
|
/**
|
2014-11-09 00:38:21 +00:00
|
|
|
* This signal is dispatched when the browser enters fullscreen mode, if supported.
|
2014-10-31 10:29:54 +00:00
|
|
|
* @property {Phaser.Signal} enterFullScreen
|
2014-11-08 09:13:25 +00:00
|
|
|
* @public
|
2014-02-25 17:10:37 +00:00
|
|
|
*/
|
|
|
|
this.enterFullScreen = new Phaser.Signal();
|
|
|
|
|
|
|
|
/**
|
2014-11-09 00:38:21 +00:00
|
|
|
* This signal is dispatched when the browser leaves fullscreen mode.
|
2014-10-31 10:29:54 +00:00
|
|
|
* @property {Phaser.Signal} leaveFullScreen
|
2014-11-08 09:13:25 +00:00
|
|
|
* @public
|
2014-02-25 17:10:37 +00:00
|
|
|
*/
|
|
|
|
this.leaveFullScreen = new Phaser.Signal();
|
|
|
|
|
2014-10-31 22:31:03 +00:00
|
|
|
/**
|
2014-11-09 00:38:21 +00:00
|
|
|
* This signal is dispatched when the browser fails to enter fullscreen mode;
|
2014-10-31 22:31:03 +00:00
|
|
|
* or if the device does not support fullscreen mode and `startFullScreen` is invoked.
|
|
|
|
* @property {Phaser.Signal} leaveFullScreen
|
2014-11-08 09:13:25 +00:00
|
|
|
* @public
|
2014-10-31 22:31:03 +00:00
|
|
|
*/
|
|
|
|
this.fullScreenFailed = new Phaser.Signal();
|
|
|
|
|
2014-02-13 12:50:10 +00:00
|
|
|
/**
|
2014-11-09 00:38:21 +00:00
|
|
|
* The orientation value of the game, as defined by `window.orientation` or guessed.
|
2014-10-31 10:29:54 +00:00
|
|
|
* A value of 90 is landscape and 0 is portrait.
|
|
|
|
* @property {number} orientation
|
2014-11-08 09:13:25 +00:00
|
|
|
* @public
|
2014-10-31 10:29:54 +00:00
|
|
|
* @readonly
|
2014-02-13 12:50:10 +00:00
|
|
|
*/
|
|
|
|
this.orientation = 0;
|
|
|
|
|
2014-11-09 00:38:21 +00:00
|
|
|
if (window.orientation)
|
2013-09-09 11:35:20 +00:00
|
|
|
{
|
2014-11-09 00:38:21 +00:00
|
|
|
this.orientation = window.orientation | 0;
|
2013-09-09 11:35:20 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (window.outerWidth > window.outerHeight)
|
|
|
|
{
|
|
|
|
this.orientation = 90;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2014-11-09 00:38:21 +00:00
|
|
|
* The _current_ scale factor based on the game dimensions vs. the scaled dimensions.
|
2014-10-31 10:29:54 +00:00
|
|
|
* @property {Phaser.Point} scaleFactor
|
|
|
|
* @public
|
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
|
|
|
/**
|
2014-11-09 00:38:21 +00:00
|
|
|
* The _current_ inversed scale factor. The displayed dimensions divided by the game dimensions.
|
2014-10-31 10:29:54 +00:00
|
|
|
* @property {Phaser.Point} scaleFactorInversed
|
|
|
|
* @protected
|
2013-11-24 11:04:58 +00:00
|
|
|
* @readonly
|
|
|
|
*/
|
|
|
|
this.scaleFactorInversed = new Phaser.Point(1, 1);
|
|
|
|
|
2014-11-08 09:13:25 +00:00
|
|
|
/**
|
|
|
|
* The game canvas is aligned by adjusting the margins; the last margins are stored here.
|
2014-11-09 00:38:21 +00:00
|
|
|
* @property {Bounds-like} margin
|
2013-11-24 11:04:58 +00:00
|
|
|
* @readonly
|
|
|
|
*/
|
2014-11-09 00:38:21 +00:00
|
|
|
this.margin = {left: 0, top: 0, right: 0, bottom: 0, x: 0, y: 0};
|
2013-11-24 11:04:58 +00:00
|
|
|
|
2014-05-19 17:49:16 +00:00
|
|
|
/**
|
2014-10-31 10:29:54 +00:00
|
|
|
* 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.
|
|
|
|
* @property {Phaser.Rectangle} bounds
|
2014-05-19 17:49:16 +00:00
|
|
|
* @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-10-31 10:29:54 +00:00
|
|
|
* The aspect ratio of the scaled game canvas.
|
|
|
|
* @property {number} aspectRatio
|
2014-10-31 08:41:06 +00:00
|
|
|
* @public
|
2014-02-13 12:50:10 +00:00
|
|
|
* @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
|
|
|
/**
|
2014-10-31 10:29:54 +00:00
|
|
|
* The aspect ratio of the original game dimensions.
|
|
|
|
* @property {number} sourceAspectRatio
|
2014-10-31 08:41:06 +00:00
|
|
|
* @public
|
2014-02-13 12:50:10 +00:00
|
|
|
* @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
|
|
|
/**
|
2014-11-09 00:38:21 +00:00
|
|
|
* The native browser events from Fullscreen API changes.
|
2014-10-31 10:29:54 +00:00
|
|
|
* @property {any} event
|
2014-11-08 09:13:25 +00:00
|
|
|
* @private
|
2014-10-31 10:29:54 +00:00
|
|
|
* @readonly
|
2013-11-25 04:40:04 +00:00
|
|
|
*/
|
|
|
|
this.event = null;
|
|
|
|
|
2014-10-31 08:41:06 +00:00
|
|
|
/**
|
2014-11-09 00:38:21 +00:00
|
|
|
* The edges on which to constrain the Canvas _to_ the Window viewport in _addition_ to any restrictions of the parent container.
|
|
|
|
* @property {boolean} windowConstraints
|
2014-11-08 09:13:25 +00:00
|
|
|
* @public
|
|
|
|
* @default
|
|
|
|
*/
|
2014-11-08 14:04:17 +00:00
|
|
|
this.windowConstraints = {
|
|
|
|
bottom: true,
|
|
|
|
right: true
|
|
|
|
};
|
2014-11-08 09:13:25 +00:00
|
|
|
|
|
|
|
/**
|
2014-11-09 00:38:21 +00:00
|
|
|
* Various compatibility settings. The `(auto)` settings are automatically configured on boot based on device and other runtime information.
|
|
|
|
* @protected
|
|
|
|
*
|
|
|
|
* @property {boolean} [supportsFullscreen=(auto)] - True only if fullscreen support will be used. (Changing to fullscreen still might not work.)
|
|
|
|
*
|
|
|
|
* @property {boolean} [noMargins=false] - If true then the Game canvas's margins will not be updated anymore: existing margins must be manually cleared. Disabling margins prevents automatic canvas alignment/centering, possibly in fullscreen.
|
|
|
|
*
|
|
|
|
* @property {Phaser.Point|null} [scrollTo=(auto)] - If specified the window will be scrolled to this position on every refresh.
|
|
|
|
*
|
|
|
|
* @property {boolean} [forceMinimumDocumentHeight=true] - If enabled the document element's minimum height is explicity set on updates.
|
|
|
|
*
|
|
|
|
* @property {boolean} [showAllCanExpand=true] - If enabled then SHOW_ALL is allowed to try and expand it's non-window parent. It may be necessary for the parent element to impose CSS width/height restrictions.
|
|
|
|
*/
|
|
|
|
this.compatibility = {
|
|
|
|
supportsFullScreen: false,
|
|
|
|
noMargins: false,
|
|
|
|
scrollTo: null,
|
|
|
|
forceMinimumDocumentHeight: true,
|
|
|
|
showAllCanExpand: true
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Scale mode to be used when not in fullscreen.
|
2014-10-31 08:41:06 +00:00
|
|
|
* @property {number} _scaleMode
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._scaleMode = Phaser.ScaleManager.NO_SCALE;
|
|
|
|
|
2014-02-13 12:50:10 +00:00
|
|
|
/*
|
2014-11-09 00:38:21 +00:00
|
|
|
* Scale mode to be used in fullscreen.
|
2014-10-31 08:41:06 +00:00
|
|
|
* @property {number} _fullScreenScaleMode
|
|
|
|
* @private
|
2014-02-13 12:50:10 +00:00
|
|
|
*/
|
2014-10-31 08:41:06 +00:00
|
|
|
this._fullScreenScaleMode = Phaser.ScaleManager.NO_SCALE;
|
2014-02-13 12:50:10 +00:00
|
|
|
|
2014-08-31 10:09:27 +00:00
|
|
|
/**
|
2014-11-07 21:18:56 +00:00
|
|
|
* If the parent container of the game is the browser window (ie. document.body), rather than a div, this should set to `true`.
|
2014-10-31 08:41:06 +00:00
|
|
|
* @property {boolean} parentIsWindow
|
2014-08-31 10:09:27 +00:00
|
|
|
* @readonly
|
|
|
|
*/
|
|
|
|
this.parentIsWindow = false;
|
|
|
|
|
|
|
|
/**
|
2014-11-07 21:18:56 +00:00
|
|
|
* The _original_ DOM element for the parent of the game canvas.
|
2014-11-09 00:38:21 +00:00
|
|
|
* This may be different in fullscreen - see `createFullScreenTarget`.
|
2014-11-08 09:13:25 +00:00
|
|
|
*
|
|
|
|
* If the `parentIsWindow` is true then this should likely be `null`.
|
2014-11-07 21:18:56 +00:00
|
|
|
*
|
2014-11-08 09:13:25 +00:00
|
|
|
* @property {DOMElement|null} parentNode
|
2014-08-31 10:09:27 +00:00
|
|
|
* @readonly
|
|
|
|
*/
|
|
|
|
this.parentNode = null;
|
|
|
|
|
|
|
|
/**
|
2014-10-31 10:29:54 +00:00
|
|
|
* The scale of the game in relation to its parent container.
|
|
|
|
* @property {Phaser.Point} parentScaleFactor
|
2014-08-31 10:09:27 +00:00
|
|
|
* @readonly
|
|
|
|
*/
|
|
|
|
this.parentScaleFactor = new Phaser.Point(1, 1);
|
|
|
|
|
2014-08-31 11:17:07 +00:00
|
|
|
/**
|
2014-11-08 09:13:25 +00:00
|
|
|
* The maximum time (in ms) between dimension update checks for the Canvas's parent element (or window).
|
|
|
|
* Update checks normally happen quicker in response to other events.
|
|
|
|
* @property {integer} trackParentInterval
|
2014-11-07 21:18:56 +00:00
|
|
|
* @protected
|
2014-08-31 11:17:07 +00:00
|
|
|
* @default
|
|
|
|
*/
|
2014-09-01 07:19:43 +00:00
|
|
|
this.trackParentInterval = 2000;
|
2014-09-01 00:02:41 +00:00
|
|
|
|
2014-11-08 09:13:25 +00:00
|
|
|
/*
|
|
|
|
* This signal is dispatched when the size of the Game canvas changes _or_ the size of the Game changes.
|
|
|
|
* When invoked this is done _after_ the Canvas size/position have been updated.
|
|
|
|
*
|
|
|
|
* This signal is _only_ called when a change occurs and a reflow may be required.
|
|
|
|
* For example, if the canvas does not change sizes because of CSS settings (such as min-width)
|
|
|
|
* then this signal will _not_ be triggered.
|
|
|
|
*
|
|
|
|
* Use this to handle responsive game layout options.
|
|
|
|
*
|
|
|
|
* @property {Phaser.Signal} onSizeChange
|
|
|
|
* @public
|
|
|
|
* @todo Formalize the arguments, if any, supplied to this signal.
|
|
|
|
*/
|
|
|
|
this.onSizeChange = new Phaser.Signal();
|
|
|
|
|
2014-09-01 00:02:41 +00:00
|
|
|
/**
|
2014-11-07 21:18:56 +00:00
|
|
|
* The callback that will be called each the parent container resizes.
|
2014-10-31 10:29:54 +00:00
|
|
|
* @property {function} onResize
|
2014-11-07 21:18:56 +00:00
|
|
|
* @private
|
2014-09-01 00:02:41 +00:00
|
|
|
*/
|
|
|
|
this.onResize = null;
|
|
|
|
|
|
|
|
/**
|
2014-10-31 10:29:54 +00:00
|
|
|
* The context in which the `onResize` callback will be called.
|
|
|
|
* @property {object} onResizeContext
|
2014-11-07 21:18:56 +00:00
|
|
|
* @private
|
2014-09-01 00:02:41 +00:00
|
|
|
*/
|
|
|
|
this.onResizeContext = null;
|
2014-08-31 11:17:07 +00:00
|
|
|
|
2014-10-31 22:31:03 +00:00
|
|
|
/**
|
2014-11-09 00:38:21 +00:00
|
|
|
* Information saved when fullscreen mode is started.
|
2014-11-07 21:18:56 +00:00
|
|
|
* @property {object|null} _fullScreenRestore
|
2014-08-31 10:09:27 +00:00
|
|
|
* @private
|
|
|
|
*/
|
2014-11-07 21:18:56 +00:00
|
|
|
this._fullScreenRestore = null;
|
2014-08-31 10:09:27 +00:00
|
|
|
|
2014-02-13 12:50:10 +00:00
|
|
|
/**
|
2014-11-08 09:13:25 +00:00
|
|
|
* The _actual_ game dimensions, as initially set or set by `setGameSize`.
|
2014-11-07 21:18:56 +00:00
|
|
|
* @property {Phaser.Rectangle} _gameSize
|
2014-02-13 12:50:10 +00:00
|
|
|
* @private
|
|
|
|
*/
|
2014-11-07 21:18:56 +00:00
|
|
|
this._gameSize = new Phaser.Rectangle();
|
2014-02-13 12:50:10 +00:00
|
|
|
|
2014-11-09 00:38:21 +00:00
|
|
|
/**
|
|
|
|
* The user-supplied scale factor, used with the USER_SCALE scaling mode.
|
|
|
|
* @property {Phaser.Point} _userScaleFactor
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._userScaleFactor = new Phaser.Point(1, 1);
|
|
|
|
|
2014-02-13 12:50:10 +00:00
|
|
|
/**
|
2014-11-07 21:18:56 +00:00
|
|
|
* The last time the bounds were checked in `preUpdate`.
|
|
|
|
* @property {number} _lastSizeCheck
|
2014-10-31 10:29:54 +00:00
|
|
|
* @private
|
2014-02-13 12:50:10 +00:00
|
|
|
*/
|
2014-11-07 21:18:56 +00:00
|
|
|
this._lastSizeCheck = 0;
|
2014-02-13 12:50:10 +00:00
|
|
|
|
2014-04-29 18:33:03 +00:00
|
|
|
/**
|
2014-11-07 21:18:56 +00:00
|
|
|
* Size checks updates are delayed according to the throttle.
|
|
|
|
* The throttle increases to `trackParentInterval` over time and is used to more
|
|
|
|
* rapidly detect changes in certain browsers (eg. IE) while providing back-off.
|
|
|
|
* @property {integer} _sizeCheckThrottle
|
2014-04-29 18:33:03 +00:00
|
|
|
* @private
|
|
|
|
*/
|
2014-11-08 09:13:25 +00:00
|
|
|
this._sizeThrottle = 0;
|
2014-04-29 18:33:03 +00:00
|
|
|
|
2014-08-31 11:17:07 +00:00
|
|
|
/**
|
2014-11-08 09:13:25 +00:00
|
|
|
* The reset barrier of the throttle; it will only be reset if above this limit.
|
2014-08-31 11:17:07 +00:00
|
|
|
* @private
|
|
|
|
*/
|
2014-11-08 09:13:25 +00:00
|
|
|
this._sizeThrottleReset = 100;
|
2014-08-31 11:17:07 +00:00
|
|
|
|
2014-09-01 00:02:41 +00:00
|
|
|
/**
|
2014-11-07 21:18:56 +00:00
|
|
|
* The cached result of the parent (possibly window) bounds; used to invalidate sizing.
|
2014-10-31 08:41:06 +00:00
|
|
|
* @property {Phaser.Rectangle} _parentBounds
|
2014-09-01 00:02:41 +00:00
|
|
|
* @private
|
|
|
|
*/
|
2014-10-31 08:41:06 +00:00
|
|
|
this._parentBounds = new Phaser.Rectangle();
|
2014-09-01 00:02:41 +00:00
|
|
|
|
2014-11-08 09:13:25 +00:00
|
|
|
/**
|
2014-11-09 00:38:21 +00:00
|
|
|
* The Canvas size at which the last onSizeChange signal was triggered.
|
|
|
|
* @property {Phaser.Rectangle} _lastReportedCanvasSize
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._lastReportedCanvasSize = new Phaser.Rectangle();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Game size at which the last onSizeChange signal was triggered.
|
|
|
|
* @property {Phaser.Rectangle} _lastReportedGameSize
|
2014-11-08 09:13:25 +00:00
|
|
|
* @private
|
|
|
|
*/
|
2014-11-09 00:38:21 +00:00
|
|
|
this._lastReportedGameSize = new Phaser.Rectangle();
|
2014-11-08 09:13:25 +00:00
|
|
|
|
2014-09-01 00:02:41 +00:00
|
|
|
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
|
|
|
/**
|
2014-11-08 09:13:25 +00:00
|
|
|
* The Game display area will be _stretched_ to fill the entire size of the canvas's parent element and/or screen.
|
|
|
|
* Proportions are not mainted.
|
|
|
|
*
|
2013-10-03 00:21:08 +00:00
|
|
|
* @constant
|
2014-10-31 08:41:06 +00:00
|
|
|
* @type {integer}
|
2013-10-03 00:21:08 +00:00
|
|
|
*/
|
2014-02-25 14:46:48 +00:00
|
|
|
Phaser.ScaleManager.EXACT_FIT = 0;
|
2013-10-03 00:21:08 +00:00
|
|
|
|
|
|
|
/**
|
2014-11-08 09:13:25 +00:00
|
|
|
* The Game display area will not be scaled - even if it is too large for the canvas/screen.
|
|
|
|
*
|
|
|
|
* This mode _ignores_ any applied scaling factor and displays the canvas at the Game size.
|
|
|
|
*
|
2013-10-03 00:21:08 +00:00
|
|
|
* @constant
|
2014-10-31 08:41:06 +00:00
|
|
|
* @type {integer}
|
2013-10-03 00:21:08 +00:00
|
|
|
*/
|
2014-02-25 14:46:48 +00:00
|
|
|
Phaser.ScaleManager.NO_SCALE = 1;
|
2013-10-03 00:21:08 +00:00
|
|
|
|
|
|
|
/**
|
2014-10-31 08:41:06 +00:00
|
|
|
* Show the entire game display area while _maintaining_ the original aspect ratio.
|
2014-11-08 09:13:25 +00:00
|
|
|
*
|
2013-10-03 00:21:08 +00:00
|
|
|
* @constant
|
2014-10-31 08:41:06 +00:00
|
|
|
* @type {integer}
|
2013-10-03 00:21:08 +00:00
|
|
|
*/
|
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
|
|
|
/**
|
2014-10-31 08:41:06 +00:00
|
|
|
* The dimensions of the game display area are changed to match the size of the parent container.
|
2014-11-08 09:13:25 +00:00
|
|
|
* That is, this mode _changes the Game size_ to match the display size.
|
|
|
|
*
|
|
|
|
* Any manually set Game size (see `setGameSize`) is ignored while in effect.
|
|
|
|
*
|
2014-08-31 00:57:50 +00:00
|
|
|
* @constant
|
2014-10-31 08:41:06 +00:00
|
|
|
* @type {integer}
|
2014-08-31 00:57:50 +00:00
|
|
|
*/
|
2014-09-01 00:02:41 +00:00
|
|
|
Phaser.ScaleManager.RESIZE = 3;
|
2014-08-31 00:57:50 +00:00
|
|
|
|
2014-11-09 00:38:21 +00:00
|
|
|
/**
|
|
|
|
* _Experimental_: The Game display area is scaled according to a user-speficied scale.
|
|
|
|
* Use `setUserScale` to change the scale factor.
|
|
|
|
*
|
|
|
|
* @constant
|
|
|
|
* @protected
|
|
|
|
* @type {integer}
|
|
|
|
*/
|
|
|
|
Phaser.ScaleManager.USER_SCALE = 4;
|
|
|
|
|
|
|
|
|
2014-02-25 14:46:48 +00:00
|
|
|
Phaser.ScaleManager.prototype = {
|
2013-10-03 00:21:08 +00:00
|
|
|
|
2014-11-04 23:56:23 +00:00
|
|
|
/**
|
2014-11-09 03:29:47 +00:00
|
|
|
* Start the ScaleManager.
|
2014-11-04 23:56:23 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.ScaleManager#boot
|
|
|
|
* @protected
|
|
|
|
*/
|
|
|
|
boot: function () {
|
|
|
|
|
2014-11-09 03:29:47 +00:00
|
|
|
// Configure device-dependent compatibility
|
|
|
|
|
|
|
|
var compat = this.compatibility;
|
|
|
|
|
|
|
|
compat.supportsFullScreen = this.game.device.fullscreen && !this.game.device.cocoonJS;
|
|
|
|
|
|
|
|
// We can't do anything about the status bars in iPads, web apps or desktops
|
|
|
|
if (!this.game.device.iPad && !this.game.device.webApp && !this.game.device.desktop)
|
|
|
|
{
|
|
|
|
if (this.game.device.android && !this.game.device.chrome)
|
|
|
|
{
|
|
|
|
compat.scrollTo = new Phaser.Point(0, 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
compat.scrollTo = new Phaser.Point(0, 0);
|
|
|
|
}
|
|
|
|
}
|
2014-11-04 23:56:23 +00:00
|
|
|
|
2014-11-09 03:29:47 +00:00
|
|
|
// Configure event listeners
|
2014-11-04 23:56:23 +00:00
|
|
|
|
|
|
|
var _this = this;
|
|
|
|
|
|
|
|
this._orientationChange = function(event) {
|
|
|
|
return _this.orientationChange(event);
|
|
|
|
};
|
|
|
|
|
|
|
|
this._windowResize = function(event) {
|
|
|
|
return _this.windowResize(event);
|
|
|
|
};
|
|
|
|
|
|
|
|
window.addEventListener('orientationchange', this._orientationChange, false);
|
|
|
|
window.addEventListener('resize', this._windowResize, false);
|
|
|
|
|
2014-11-09 03:29:47 +00:00
|
|
|
if (this.compatibility.supportsFullScreen)
|
2014-11-04 23:56:23 +00:00
|
|
|
{
|
|
|
|
this._fullScreenChange = function(event) {
|
|
|
|
return _this.fullScreenChange(event);
|
|
|
|
};
|
|
|
|
|
|
|
|
this._fullScreenError = function(event) {
|
|
|
|
return _this.fullScreenError(event);
|
|
|
|
};
|
|
|
|
|
|
|
|
document.addEventListener('webkitfullscreenchange', this._fullScreenChange, false);
|
|
|
|
document.addEventListener('mozfullscreenchange', this._fullScreenChange, false);
|
|
|
|
document.addEventListener('MSFullscreenChange', this._fullScreenChange, false);
|
|
|
|
document.addEventListener('fullscreenchange', this._fullScreenChange, false);
|
|
|
|
|
|
|
|
document.addEventListener('webkitfullscreenerror', this._fullScreenError, false);
|
|
|
|
document.addEventListener('mozfullscreenerror', this._fullScreenError, false);
|
|
|
|
document.addEventListener('MSFullscreenError', this._fullScreenError, false);
|
|
|
|
document.addEventListener('fullscreenerror', this._fullScreenError, false);
|
|
|
|
}
|
|
|
|
|
2014-11-09 03:29:47 +00:00
|
|
|
// Initialize core bounds
|
2014-11-04 23:56:23 +00:00
|
|
|
|
|
|
|
Phaser.Canvas.getOffset(this.game.canvas, this.offset);
|
|
|
|
|
|
|
|
this.bounds.setTo(this.offset.x, this.offset.y, this.width, this.height);
|
|
|
|
|
2014-11-09 03:29:47 +00:00
|
|
|
this.setGameSize(this.game.width, this.game.height);
|
|
|
|
|
2014-11-04 23:56:23 +00:00
|
|
|
},
|
|
|
|
|
2014-09-01 00:02:41 +00:00
|
|
|
/**
|
2014-10-31 10:29:54 +00:00
|
|
|
* Load configuration settings.
|
2014-09-01 00:02:41 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.ScaleManager#parseConfig
|
2014-10-31 10:29:54 +00:00
|
|
|
* @protected
|
2014-09-01 00:02:41 +00:00
|
|
|
* @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-10-31 08:41:06 +00:00
|
|
|
*
|
|
|
|
* This should _not_ be called when in fullscreen mode.
|
2014-08-31 00:57:50 +00:00
|
|
|
*
|
2014-09-01 07:19:43 +00:00
|
|
|
* @method Phaser.ScaleManager#setupScale
|
2014-10-31 08:41:06 +00:00
|
|
|
* @protected
|
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);
|
|
|
|
}
|
2014-10-31 08:41:06 +00:00
|
|
|
else if (this.game.parent && this.game.parent.nodeType === 1)
|
2014-08-31 00:57:50 +00:00
|
|
|
{
|
|
|
|
// 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;
|
2014-10-31 08:41:06 +00:00
|
|
|
|
|
|
|
this.offset.set(0, 0);
|
2014-08-31 00:57:50 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-31 10:09:27 +00:00
|
|
|
this.parentNode = target;
|
|
|
|
this.parentIsWindow = false;
|
|
|
|
|
2014-11-08 07:24:57 +00:00
|
|
|
this.getParentBounds(this._parentBounds);
|
2014-09-01 07:19:43 +00:00
|
|
|
|
|
|
|
rect.width = this._parentBounds.width;
|
|
|
|
rect.height = this._parentBounds.height;
|
|
|
|
|
2014-10-31 08:41:06 +00:00
|
|
|
this.offset.set(this._parentBounds.x, this._parentBounds.y);
|
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-11-09 01:43:28 +00:00
|
|
|
this._gameSize.setTo(0, 0, newWidth, newHeight);
|
|
|
|
|
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-11-08 07:24:57 +00:00
|
|
|
/**
|
2014-11-09 00:38:21 +00:00
|
|
|
* Set the actual Game size.
|
2014-11-08 09:13:25 +00:00
|
|
|
* Use this instead of directly changing `game.width` or `game.height`.
|
2014-11-08 07:24:57 +00:00
|
|
|
*
|
2014-11-09 00:38:21 +00:00
|
|
|
* The actual physical display (Canvas element size) depends on various settings including
|
|
|
|
* - Scale mode
|
|
|
|
* - Scaling factor
|
|
|
|
* - Size of Canvas's parent element or CSS rules such as min-height/max-height;
|
|
|
|
* - The size of the Window
|
2014-11-08 07:24:57 +00:00
|
|
|
*
|
2014-11-08 09:13:25 +00:00
|
|
|
* @method Phaser.ScaleManager#setGameSize
|
2014-11-08 07:24:57 +00:00
|
|
|
* @public
|
|
|
|
* @param {integer} width - _Game width_, in pixels.
|
|
|
|
* @param {integer} height - _Game height_, in pixels.
|
|
|
|
*/
|
2014-11-08 09:13:25 +00:00
|
|
|
setGameSize: function (width, height) {
|
2014-11-08 07:24:57 +00:00
|
|
|
|
|
|
|
this._gameSize.setTo(0, 0, width, height);
|
|
|
|
|
|
|
|
if (this.currentScaleMode !== Phaser.ScaleManager.RESIZE)
|
|
|
|
{
|
|
|
|
this.updateDimensions(width, height, true);
|
|
|
|
}
|
2014-11-09 01:43:28 +00:00
|
|
|
|
2014-11-08 07:24:57 +00:00
|
|
|
this.queueUpdate(true);
|
2014-11-07 21:18:56 +00:00
|
|
|
|
2014-09-01 07:19:43 +00:00
|
|
|
},
|
|
|
|
|
2014-11-09 00:38:21 +00:00
|
|
|
/**
|
|
|
|
* _Experimental_: Set a User scaling factor. This is only used in the USER_SCALE scaling mode.
|
|
|
|
*
|
|
|
|
* @method Phaser.ScaleManager#setGameSize
|
|
|
|
* @protected
|
|
|
|
* @param {number} width - Width scaling factor.
|
|
|
|
* @param {numer} height - Height scaling factor.
|
|
|
|
*/
|
|
|
|
setUserScale: function (width, height) {
|
|
|
|
|
|
|
|
this._userScaleFactor.setTo(width, height);
|
|
|
|
this.queueUpdate(true);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2014-09-01 00:02:41 +00:00
|
|
|
/**
|
2014-11-08 09:13:25 +00:00
|
|
|
* Sets the callback that will be called when the bounds of the Canvas's parent container may have changed.
|
|
|
|
*
|
|
|
|
* This callback ..
|
|
|
|
* - Will normally be invoked from `preUpdate`
|
|
|
|
* - May be invoked even though the parent container or canvas sizes have not changed
|
|
|
|
* - Unlike `onSizeChange`, it runs _before_ the canvas is guaranteed to be updated
|
|
|
|
*
|
|
|
|
* See `onSizeChange` for a better way of reacting to layout updates.
|
2014-09-01 00:02:41 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.ScaleManager#setResizeCallback
|
2014-10-31 08:41:06 +00:00
|
|
|
* @public
|
2014-09-01 00:02:41 +00:00
|
|
|
* @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-11-08 09:13:25 +00:00
|
|
|
/**
|
2014-11-09 00:38:21 +00:00
|
|
|
* Signals a resize - IF the canvas or game size differs from the last signal.
|
|
|
|
*
|
2014-11-08 09:13:25 +00:00
|
|
|
* This also triggers updates on `grid` (FlexGrid) and, if in a RESIZE mode, `game.state` (StateManager).
|
|
|
|
*
|
2014-11-09 00:38:21 +00:00
|
|
|
* @method Phaser.ScaleMager#signalSizeChange
|
2014-11-08 09:13:25 +00:00
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
signalSizeChange: function () {
|
|
|
|
|
2014-11-09 03:29:47 +00:00
|
|
|
if (!Phaser.Rectangle.sameDimensions(this, this._lastReportedCanvasSize) ||
|
2014-11-09 00:38:21 +00:00
|
|
|
!Phaser.Rectangle.sameDimensions(this.game, this._lastReportedGameSize))
|
2014-11-08 09:13:25 +00:00
|
|
|
{
|
2014-11-09 00:38:21 +00:00
|
|
|
var width = this.width;
|
|
|
|
var height = this.height;
|
|
|
|
|
|
|
|
this._lastReportedCanvasSize.setTo(0, 0, width, height);
|
|
|
|
this._lastReportedGameSize.setTo(0, 0, this.game.width, this.game.height);
|
2014-11-08 09:13:25 +00:00
|
|
|
|
|
|
|
this.grid.onResize(width, height);
|
|
|
|
|
|
|
|
this.onSizeChange.dispatch(this, width, height);
|
|
|
|
|
|
|
|
// Per StateManager#onResizeCallback, it only occurs when in RESIZE mode.
|
|
|
|
if (this.currentScaleMode === Phaser.ScaleManager.RESIZE)
|
|
|
|
{
|
|
|
|
this.game.state.resize(width, height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2014-09-01 02:07:17 +00:00
|
|
|
/**
|
2014-10-31 08:41:06 +00:00
|
|
|
* Set the min and max dimensions for the game object.
|
|
|
|
*
|
2014-11-04 23:56:23 +00:00
|
|
|
* @method Phaser.ScaleManager#setMinMax
|
2014-10-31 08:41:06 +00:00
|
|
|
* @public
|
|
|
|
* @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; only changed if specified.
|
|
|
|
* @param {number} [maxHeight] - The maximum height the game is allowed to scale up to; only changed if specified.
|
2014-11-08 09:13:25 +00:00
|
|
|
* @todo These values are only sometimes honored.
|
2014-10-31 08:41:06 +00:00
|
|
|
*/
|
2014-09-01 02:07:17 +00:00
|
|
|
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-11-08 20:01:10 +00:00
|
|
|
if (this.game.time.time < (this._lastSizeCheck + this._sizeThrottle))
|
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-11-08 09:13:25 +00:00
|
|
|
var prevThrottle = this._sizeThrottle;
|
2014-11-07 21:18:56 +00:00
|
|
|
|
|
|
|
Phaser.Canvas.getOffset(this.game.canvas, this.offset);
|
|
|
|
|
|
|
|
var prevWidth = this._parentBounds.width;
|
|
|
|
var prevHeight = this._parentBounds.height;
|
2014-11-08 07:24:57 +00:00
|
|
|
var bounds = this.getParentBounds(this._parentBounds);
|
2014-11-07 21:18:56 +00:00
|
|
|
|
|
|
|
if (bounds.width !== prevWidth || bounds.height !== prevHeight)
|
2014-10-31 08:41:06 +00:00
|
|
|
{
|
2014-11-08 09:13:25 +00:00
|
|
|
if (this.onResize)
|
|
|
|
{
|
|
|
|
this.onResize.call(this.onResizeContext, bounds.width, bounds.height);
|
|
|
|
}
|
|
|
|
|
2014-11-08 07:24:57 +00:00
|
|
|
this.setScreenSize();
|
2014-11-08 09:13:25 +00:00
|
|
|
|
|
|
|
this.signalSizeChange();
|
2014-10-31 08:41:06 +00:00
|
|
|
}
|
|
|
|
|
2014-11-07 21:18:56 +00:00
|
|
|
// Don't let an update be too eager about resetting the throttle.
|
2014-11-08 09:13:25 +00:00
|
|
|
if (this._sizeThrottle < prevThrottle)
|
2014-09-01 02:20:09 +00:00
|
|
|
{
|
2014-11-08 09:13:25 +00:00
|
|
|
this._sizeThrottle = Math.max(this._sizeThrottle, this._sizeThrottleReset);
|
2014-11-07 21:18:56 +00:00
|
|
|
}
|
2014-10-31 08:41:06 +00:00
|
|
|
|
2014-11-08 09:13:25 +00:00
|
|
|
var throttle = this._sizeThrottle * 2;
|
2014-10-31 08:41:06 +00:00
|
|
|
|
2014-11-08 09:13:25 +00:00
|
|
|
this._sizeThrottle = Phaser.Math.clamp(throttle, 10, this.trackParentInterval);
|
2014-11-08 20:01:10 +00:00
|
|
|
this._lastSizeCheck = this.game.time.time;
|
2013-09-09 11:35:20 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2014-10-31 08:41:06 +00:00
|
|
|
* Update the dimensions taking the parent scaling factor into account.
|
|
|
|
*
|
|
|
|
* @method Phaser.ScaleManager#updateDimensions
|
|
|
|
* @private
|
|
|
|
* @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.
|
|
|
|
*/
|
2014-09-01 00:02:41 +00:00
|
|
|
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;
|
2014-11-07 21:18:56 +00:00
|
|
|
this.updateScalingAndBounds();
|
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-11-08 09:13:25 +00:00
|
|
|
// Resize the renderer (which in turn resizes the Game canvas!)
|
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-11-07 21:18:56 +00:00
|
|
|
/**
|
|
|
|
* Update relevant scaling values based on the ScaleManager dimension and game dimensions,
|
|
|
|
* which should already be set. This does not change `sourceAspectRatio`.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
updateScalingAndBounds: function () {
|
|
|
|
|
|
|
|
this.scaleFactor.x = this.game.width / this.width;
|
|
|
|
this.scaleFactor.y = this.game.height / this.height;
|
|
|
|
|
|
|
|
this.scaleFactorInversed.x = this.width / this.game.width;
|
|
|
|
this.scaleFactorInversed.y = this.height / this.game.height;
|
|
|
|
|
|
|
|
this.aspectRatio = this.width / this.height;
|
|
|
|
|
|
|
|
// This can be invoked in boot pre-canvas
|
|
|
|
if (this.game.canvas)
|
|
|
|
{
|
|
|
|
Phaser.Canvas.getOffset(this.game.canvas, this.offset);
|
|
|
|
}
|
|
|
|
this.bounds.setTo(this.offset.x, this.offset.y, this.width, this.height);
|
|
|
|
|
|
|
|
// Can be invoked in boot pre-input
|
|
|
|
if (this.game.input && this.game.input.scale)
|
|
|
|
{
|
|
|
|
this.game.input.scale.setTo(this.scaleFactor.x, this.scaleFactor.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-11-04 20:43:59 +00:00
|
|
|
/**
|
2014-10-31 10:29:54 +00:00
|
|
|
* Force the game to run in only one orientation.
|
2014-09-01 02:30:02 +00:00
|
|
|
*
|
2014-02-25 14:46:48 +00:00
|
|
|
* @method Phaser.ScaleManager#forceOrientation
|
2014-10-31 08:41:06 +00:00
|
|
|
* @public
|
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
|
|
|
|
2014-11-07 21:18:56 +00:00
|
|
|
this.queueUpdate(true);
|
2014-10-31 08:41:06 +00:00
|
|
|
|
2013-11-04 20:43:59 +00:00
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2014-11-01 01:06:36 +00:00
|
|
|
* Checks if the browser is in the correct orientation for the game, dependent upon `forceLandscape` and `forcePortrait`, and updates the state.
|
2014-10-31 08:41:06 +00:00
|
|
|
*
|
|
|
|
* The appropriate event is dispatched if the orientation became valid or invalid.
|
2014-09-01 02:30:02 +00:00
|
|
|
*
|
2014-11-01 01:06:36 +00:00
|
|
|
* @method Phaser.ScaleManager#updateOrientationState
|
2014-10-31 08:41:06 +00:00
|
|
|
* @private
|
|
|
|
* @return {boolean} True if the orientation state changed (consider a refresh)
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2014-11-01 01:06:36 +00:00
|
|
|
updateOrientationState: function () {
|
2013-09-09 11:35:20 +00:00
|
|
|
|
|
|
|
// They are in the wrong orientation
|
|
|
|
if (this.incorrectOrientation)
|
|
|
|
{
|
2014-10-31 08:41:06 +00:00
|
|
|
if ((this.forceLandscape && window.innerWidth > window.innerHeight) ||
|
|
|
|
(this.forcePortrait && window.innerHeight > window.innerWidth))
|
2013-09-09 11:35:20 +00:00
|
|
|
{
|
|
|
|
// 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-10-31 08:41:06 +00:00
|
|
|
return true;
|
2013-09-09 11:35:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-10-31 08:41:06 +00:00
|
|
|
if ((this.forceLandscape && window.innerWidth < window.innerHeight) ||
|
|
|
|
(this.forcePortrait && window.innerHeight < window.innerWidth))
|
2013-09-09 11:35:20 +00:00
|
|
|
{
|
|
|
|
// 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-10-31 08:41:06 +00:00
|
|
|
return true;
|
2013-09-09 11:35:20 +00:00
|
|
|
}
|
|
|
|
}
|
2014-10-31 08:41:06 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
|
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-10-31 08:41:06 +00:00
|
|
|
* @method Phaser.ScaleManager#orientationChange
|
|
|
|
* @private
|
2013-10-03 00:21:08 +00:00
|
|
|
* @param {Event} event - The orientationchange event data.
|
2013-09-09 11:35:20 +00:00
|
|
|
*/
|
2014-10-31 08:41:06 +00:00
|
|
|
orientationChange: function (event) {
|
2013-09-09 11:35:20 +00:00
|
|
|
|
2013-11-25 04:40:04 +00:00
|
|
|
this.event = event;
|
|
|
|
|
2014-11-09 00:38:21 +00:00
|
|
|
this.orientation = window.orientation | 0;
|
2013-09-09 11:35:20 +00:00
|
|
|
|
|
|
|
if (this.isLandscape)
|
|
|
|
{
|
|
|
|
this.enterLandscape.dispatch(this.orientation, true, false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.enterPortrait.dispatch(this.orientation, false, true);
|
|
|
|
}
|
|
|
|
|
2014-11-07 21:18:56 +00:00
|
|
|
this.queueUpdate(true);
|
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.resize event handler.
|
|
|
|
*
|
2014-10-31 08:41:06 +00:00
|
|
|
* @method Phaser.ScaleManager#windowResize
|
|
|
|
* @private
|
2013-10-03 00:21:08 +00:00
|
|
|
* @param {Event} event - The resize event data.
|
2013-09-09 11:35:20 +00:00
|
|
|
*/
|
2014-10-31 08:41:06 +00:00
|
|
|
windowResize: function (event) {
|
2013-09-09 11:35:20 +00:00
|
|
|
|
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-11-08 09:13:25 +00:00
|
|
|
if (this.updateOrientationState())
|
2013-09-09 11:35:20 +00:00
|
|
|
{
|
2014-11-08 09:13:25 +00:00
|
|
|
this.queueUpdate(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.queueUpdate();
|
2013-09-09 11:35:20 +00:00
|
|
|
}
|
2014-10-10 19:35:50 +00:00
|
|
|
|
2013-09-09 11:35:20 +00:00
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2014-11-09 00:38:21 +00:00
|
|
|
* Scroll to the top - in some environments. See `compatibility.scrollTo`.
|
2014-11-07 21:18:56 +00:00
|
|
|
* @private
|
2013-09-09 11:35:20 +00:00
|
|
|
*/
|
2014-11-07 21:18:56 +00:00
|
|
|
scrollTop: function () {
|
2014-09-09 11:48:21 +00:00
|
|
|
|
2014-11-09 00:38:21 +00:00
|
|
|
var scrollTo = this.compatibility.scrollTo;
|
|
|
|
if (scrollTo)
|
2013-09-09 11:35:20 +00:00
|
|
|
{
|
2014-11-09 00:38:21 +00:00
|
|
|
window.scrollTo(scrollTo.x, scrollTo.y);
|
2013-09-09 11:35:20 +00:00
|
|
|
}
|
|
|
|
|
2014-11-07 21:18:56 +00:00
|
|
|
},
|
2013-11-24 11:04:58 +00:00
|
|
|
|
2014-11-07 21:18:56 +00:00
|
|
|
/**
|
2014-11-08 09:13:25 +00:00
|
|
|
* Request a refresh, which is not normally needed, based on the current mode settings.
|
2014-11-07 21:18:56 +00:00
|
|
|
* The refresh does not run immediately but rather is queued for subsequent game updates.
|
|
|
|
*
|
|
|
|
* @method Phaser.ScaleManager#refresh
|
2014-11-08 09:13:25 +00:00
|
|
|
* @public
|
2014-11-07 21:18:56 +00:00
|
|
|
*/
|
|
|
|
refresh: function () {
|
2013-11-24 11:04:58 +00:00
|
|
|
|
2014-11-07 21:18:56 +00:00
|
|
|
this.scrollTop();
|
|
|
|
this.queueUpdate(true);
|
2013-09-09 11:35:20 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2014-11-07 21:18:56 +00:00
|
|
|
* Set game and/or screen (game canvas) size automatically based on the scaleMode.
|
2014-11-08 09:13:25 +00:00
|
|
|
* This is used internally.
|
2014-11-07 21:18:56 +00:00
|
|
|
*
|
|
|
|
* Do not call this to "refresh" the display, but rather use `refresh`.
|
2014-11-08 09:13:25 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.ScaleManager#setScreenSize
|
2014-10-31 08:41:06 +00:00
|
|
|
* @protected
|
2014-11-08 09:13:25 +00:00
|
|
|
* @deprecated 2.1.4 - This method is _internal_ and may be made _private_ in the future.
|
2013-09-09 11:35:20 +00:00
|
|
|
*/
|
2014-11-07 21:18:56 +00:00
|
|
|
setScreenSize: function () {
|
2013-09-09 11:35:20 +00:00
|
|
|
|
2014-10-31 08:41:06 +00:00
|
|
|
var scaleMode = this.currentScaleMode;
|
|
|
|
|
|
|
|
if (scaleMode === Phaser.ScaleManager.RESIZE)
|
2014-09-09 11:48:21 +00:00
|
|
|
{
|
2014-11-07 21:18:56 +00:00
|
|
|
this.reflowGame();
|
2014-09-09 11:48:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-11-07 21:18:56 +00:00
|
|
|
this.scrollTop();
|
|
|
|
|
2014-11-09 00:38:21 +00:00
|
|
|
if (this.compatibility.forceMinimumDocumentHeight)
|
|
|
|
{
|
|
|
|
// (This came from older code, by why is it here?)
|
|
|
|
// Set minimum height of content to new window height
|
|
|
|
document.documentElement.style.minHeight = window.innerHeight + 'px';
|
|
|
|
}
|
2014-11-08 07:24:57 +00:00
|
|
|
|
2014-11-07 21:18:56 +00:00
|
|
|
if (this.incorrectOrientation)
|
2013-09-10 15:46:39 +00:00
|
|
|
{
|
2014-11-07 21:18:56 +00:00
|
|
|
this.setMaximum();
|
2013-09-10 15:46:39 +00:00
|
|
|
}
|
2014-11-07 21:18:56 +00:00
|
|
|
else
|
2013-09-09 11:35:20 +00:00
|
|
|
{
|
2014-11-07 21:18:56 +00:00
|
|
|
if (scaleMode === Phaser.ScaleManager.EXACT_FIT)
|
2013-09-09 11:35:20 +00:00
|
|
|
{
|
2014-11-07 21:18:56 +00:00
|
|
|
this.setExactFit();
|
2013-09-09 11:35:20 +00:00
|
|
|
}
|
2014-11-07 21:18:56 +00:00
|
|
|
else if (scaleMode === Phaser.ScaleManager.SHOW_ALL)
|
2013-09-09 11:35:20 +00:00
|
|
|
{
|
2014-11-09 00:38:21 +00:00
|
|
|
if (!this.isFullScreen && !this.parentIsWindow &&
|
|
|
|
this.compatibility.showAllCanExpand)
|
2014-11-08 07:24:57 +00:00
|
|
|
{
|
|
|
|
// Try to expand parent out, but choosing maximizing dimensions.
|
|
|
|
// Then select minimize dimensions which should then honor parent
|
|
|
|
// maximum bound applications.
|
|
|
|
this.setShowAll(true);
|
|
|
|
this.resetCanvas();
|
|
|
|
this.setShowAll();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.setShowAll();
|
|
|
|
}
|
2013-09-09 11:35:20 +00:00
|
|
|
}
|
2014-11-07 21:18:56 +00:00
|
|
|
else if (scaleMode === Phaser.ScaleManager.NO_SCALE)
|
2013-09-10 15:46:39 +00:00
|
|
|
{
|
2014-11-07 21:18:56 +00:00
|
|
|
this.width = this.game.width;
|
|
|
|
this.height = this.game.height;
|
2013-09-09 11:35:20 +00:00
|
|
|
}
|
2014-11-09 00:38:21 +00:00
|
|
|
else if (scaleMode === Phaser.ScaleManager.USER_SCALE)
|
|
|
|
{
|
|
|
|
this.width = this.game.width * this._userScaleFactor.x;
|
|
|
|
this.height = this.game.height * this._userScaleFactor.y;
|
|
|
|
}
|
2014-11-07 21:18:56 +00:00
|
|
|
}
|
2014-10-31 08:41:06 +00:00
|
|
|
|
2014-11-07 21:18:56 +00:00
|
|
|
if (this.updateOrientationState())
|
|
|
|
{
|
|
|
|
this.queueUpdate(true);
|
2014-10-31 08:41:06 +00:00
|
|
|
}
|
|
|
|
|
2014-11-07 21:18:56 +00:00
|
|
|
this.reflowCanvas();
|
|
|
|
|
2014-10-31 08:41:06 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the bounds of the parent.
|
2014-10-31 10:29:54 +00:00
|
|
|
*
|
|
|
|
* If fullscreen or without parent, this is the bounds of the screen itself.
|
|
|
|
*
|
2014-11-07 21:18:56 +00:00
|
|
|
* The values are rounded to the nearest pixel.
|
|
|
|
*
|
2014-10-31 08:41:06 +00:00
|
|
|
* @method Phaser.ScaleManager#getParentBounds
|
|
|
|
* @protected
|
|
|
|
* @param {Phaser.Rectangle} [target=(new Rectangle)] - The rectangle to update; a new one is created as needed.
|
|
|
|
*/
|
2014-11-08 13:29:12 +00:00
|
|
|
getParentBounds: function (target) {
|
2014-10-31 08:41:06 +00:00
|
|
|
|
|
|
|
var bounds = target || new Phaser.Rectangle();
|
2014-11-07 21:18:56 +00:00
|
|
|
var parentNode = this.game.canvas && this.game.canvas.parentNode;
|
|
|
|
|
2014-11-08 07:24:57 +00:00
|
|
|
if (this.isFullScreen && !this._createdFullScreenTarget)
|
2014-10-31 08:41:06 +00:00
|
|
|
{
|
2014-11-07 21:18:56 +00:00
|
|
|
bounds.setTo(0, 0, Math.round(window.outerWidth), Math.round(window.outerHeight));
|
|
|
|
}
|
|
|
|
else if (this.parentIsWindow || !parentNode)
|
|
|
|
{
|
|
|
|
bounds.setTo(0, 0, Math.round(window.innerWidth), Math.round(window.innerHeight));
|
2014-10-31 08:41:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-11-07 21:18:56 +00:00
|
|
|
var clientRect = parentNode.getBoundingClientRect();
|
|
|
|
|
2014-11-08 13:21:13 +00:00
|
|
|
bounds.setTo(clientRect.left, clientRect.top, clientRect.width, clientRect.height);
|
2014-11-08 09:13:25 +00:00
|
|
|
|
2014-11-08 13:21:13 +00:00
|
|
|
var wc = this.windowConstraints;
|
|
|
|
if (wc.right)
|
|
|
|
{
|
|
|
|
bounds.right = Math.min(bounds.right, window.innerWidth);
|
|
|
|
}
|
|
|
|
if (wc.bottom)
|
|
|
|
{
|
|
|
|
bounds.bottom = Math.min(bounds.bottom, window.innerHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
bounds.setTo(
|
|
|
|
Math.round(bounds.x), Math.round(bounds.y),
|
|
|
|
Math.round(bounds.width), Math.round(bounds.height));
|
2014-10-31 08:41:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return bounds;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-10-31 10:29:54 +00:00
|
|
|
* Update the canvas position/margins - for alignment within the parent container.
|
2014-10-31 08:41:06 +00:00
|
|
|
*
|
2014-11-07 21:18:56 +00:00
|
|
|
* The canvas margins _must_ be reset/cleared prior to invoking this.
|
|
|
|
*
|
2014-11-01 01:06:36 +00:00
|
|
|
* @method Phaser.ScaleManager#alignCanvas
|
2014-10-31 08:41:06 +00:00
|
|
|
* @private
|
2014-11-07 21:18:56 +00:00
|
|
|
* @param {boolean} horizontal - Align horizontally?
|
|
|
|
* @param {boolean} vertical - Align vertically?
|
2014-10-31 08:41:06 +00:00
|
|
|
*/
|
2014-11-07 21:18:56 +00:00
|
|
|
alignCanvas: function (horizontal, vertical) {
|
2014-10-31 08:41:06 +00:00
|
|
|
|
|
|
|
var parentBounds = this.getParentBounds();
|
2014-11-07 21:18:56 +00:00
|
|
|
var canvas = this.game.canvas;
|
2014-11-08 09:13:25 +00:00
|
|
|
var margin = this.margin;
|
2014-10-31 08:41:06 +00:00
|
|
|
|
2014-11-07 21:18:56 +00:00
|
|
|
if (horizontal)
|
2014-10-31 08:41:06 +00:00
|
|
|
{
|
2014-11-09 00:38:21 +00:00
|
|
|
margin.left = margin.right = 0;
|
2014-11-08 09:13:25 +00:00
|
|
|
|
2014-11-07 21:18:56 +00:00
|
|
|
var canvasBounds = canvas.getBoundingClientRect();
|
2014-11-09 00:38:21 +00:00
|
|
|
|
2014-10-31 08:41:06 +00:00
|
|
|
if (this.width < parentBounds.width && !this.incorrectOrientation)
|
|
|
|
{
|
2014-11-07 21:18:56 +00:00
|
|
|
var currentEdge = canvasBounds.left - parentBounds.x;
|
2014-10-31 08:41:06 +00:00
|
|
|
var targetEdge = (parentBounds.width / 2) - (this.width / 2);
|
|
|
|
|
2014-11-07 21:18:56 +00:00
|
|
|
targetEdge = Math.max(targetEdge, 0);
|
|
|
|
|
2014-11-09 00:38:21 +00:00
|
|
|
var offset = targetEdge - currentEdge;
|
|
|
|
|
|
|
|
margin.left = Math.round(offset);
|
2014-11-07 21:18:56 +00:00
|
|
|
}
|
|
|
|
|
2014-11-09 00:38:21 +00:00
|
|
|
canvas.style.marginLeft = margin.left + 'px';
|
|
|
|
if (margin.left !== 0)
|
2014-11-07 21:18:56 +00:00
|
|
|
{
|
2014-11-09 00:38:21 +00:00
|
|
|
margin.right = -(parentBounds.width - canvasBounds.width - margin.left);
|
|
|
|
canvas.style.marginRight = margin.right + 'px';
|
2013-09-09 11:35:20 +00:00
|
|
|
}
|
2014-10-31 08:41:06 +00:00
|
|
|
}
|
|
|
|
|
2014-11-07 21:18:56 +00:00
|
|
|
if (vertical)
|
2014-10-31 08:41:06 +00:00
|
|
|
{
|
2014-11-09 00:38:21 +00:00
|
|
|
margin.top = margin.bottom = 0;
|
2014-11-08 09:13:25 +00:00
|
|
|
|
|
|
|
var canvasBounds = canvas.getBoundingClientRect();
|
2014-11-09 00:38:21 +00:00
|
|
|
|
2014-10-31 08:41:06 +00:00
|
|
|
if (this.height < parentBounds.height && !this.incorrectOrientation)
|
|
|
|
{
|
2014-11-07 21:18:56 +00:00
|
|
|
var currentEdge = canvasBounds.top - parentBounds.y;
|
2014-10-31 08:41:06 +00:00
|
|
|
var targetEdge = (parentBounds.height / 2) - (this.height / 2);
|
2013-09-09 11:35:20 +00:00
|
|
|
|
2014-11-07 21:18:56 +00:00
|
|
|
targetEdge = Math.max(targetEdge, 0);
|
|
|
|
|
2014-11-09 00:38:21 +00:00
|
|
|
var offset = targetEdge - currentEdge;
|
|
|
|
margin.top = Math.round(offset);
|
2014-11-07 21:18:56 +00:00
|
|
|
}
|
|
|
|
|
2014-11-09 00:38:21 +00:00
|
|
|
canvas.style.marginTop = margin.top + 'px';
|
|
|
|
if (margin.top !== 0)
|
2014-11-07 21:18:56 +00:00
|
|
|
{
|
2014-11-09 00:38:21 +00:00
|
|
|
margin.bottom = -(parentBounds.height - canvasBounds.height - margin.top);
|
|
|
|
canvas.style.marginBottom = margin.bottom + 'px';
|
2014-10-31 08:41:06 +00:00
|
|
|
}
|
2013-09-09 11:35:20 +00:00
|
|
|
}
|
|
|
|
|
2014-11-09 00:38:21 +00:00
|
|
|
// Silly backwards compatibility..
|
|
|
|
margin.x = margin.left;
|
|
|
|
margin.y = margin.top;
|
|
|
|
|
2014-11-07 21:18:56 +00:00
|
|
|
},
|
2014-10-31 08:41:06 +00:00
|
|
|
|
2014-11-07 21:18:56 +00:00
|
|
|
/**
|
|
|
|
* Updates the game dimensions and canvas based on internal state.
|
|
|
|
*
|
|
|
|
* The canvas margins may always be adjusted, even alignment is not in effect.
|
|
|
|
*
|
|
|
|
* @method Phaser.ScaleManager#reflowGame
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
reflowGame: function ()
|
|
|
|
{
|
2014-11-08 07:24:57 +00:00
|
|
|
|
|
|
|
this.resetCanvas('', '');
|
|
|
|
|
|
|
|
var bounds = this.getParentBounds();
|
2014-11-07 21:18:56 +00:00
|
|
|
this.updateDimensions(bounds.width, bounds.height, true);
|
2014-11-08 07:24:57 +00:00
|
|
|
|
2013-09-09 11:35:20 +00:00
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2014-10-31 08:41:06 +00:00
|
|
|
* Updates the size/position of the canvas based on internal state.
|
2014-11-07 21:18:56 +00:00
|
|
|
*
|
|
|
|
* The canvas margins may always be adjusted, even alignment is not in effect.
|
2014-09-01 00:02:41 +00:00
|
|
|
*
|
2014-11-01 01:06:36 +00:00
|
|
|
* @method Phaser.ScaleManager#reflowCanvas
|
2014-10-31 08:41:06 +00:00
|
|
|
* @private
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2014-11-01 01:06:36 +00:00
|
|
|
reflowCanvas: function () {
|
2014-10-31 08:41:06 +00:00
|
|
|
|
2014-04-27 09:17:37 +00:00
|
|
|
if (!this.incorrectOrientation)
|
2013-09-09 11:35:20 +00:00
|
|
|
{
|
2014-11-08 07:24:57 +00:00
|
|
|
this.width = Phaser.Math.clamp(this.width, this.minWidth || 0, this.maxWidth || this.width);
|
|
|
|
this.height = Phaser.Math.clamp(this.height, this.minHeight || 0, this.maxHeight || this.height);
|
2013-09-09 11:35:20 +00:00
|
|
|
}
|
|
|
|
|
2014-11-08 07:24:57 +00:00
|
|
|
this.resetCanvas();
|
2014-03-23 07:59:28 +00:00
|
|
|
|
2014-11-09 00:38:21 +00:00
|
|
|
if (!this.compatibility.noMargins)
|
2014-11-07 21:18:56 +00:00
|
|
|
{
|
2014-11-08 09:13:25 +00:00
|
|
|
if (this.isFullScreen && this._createdFullScreenTarget)
|
|
|
|
{
|
|
|
|
this.alignCanvas(true, true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.alignCanvas(this.pageAlignHorizontally, this.pageAlignVertically);
|
|
|
|
}
|
2013-09-09 11:35:20 +00:00
|
|
|
}
|
|
|
|
|
2014-11-07 21:18:56 +00:00
|
|
|
this.updateScalingAndBounds();
|
2013-09-10 15:46:39 +00:00
|
|
|
|
2014-11-07 21:18:56 +00:00
|
|
|
},
|
2013-11-24 11:04:58 +00:00
|
|
|
|
2014-11-08 07:24:57 +00:00
|
|
|
/**
|
|
|
|
* "Reset" the game canvas as set the specified styles directly.
|
|
|
|
* @method Phaser.ScaleManager#resetCanvas
|
|
|
|
* @private
|
|
|
|
* @param {string} [cssWidth=(current width)] - The css width to set.
|
|
|
|
* @param {string} [cssHeight=(current height)] - The css height to set.
|
|
|
|
*/
|
|
|
|
resetCanvas: function (cssWidth, cssHeight) {
|
|
|
|
|
|
|
|
if (typeof cssWidth === 'undefined') { cssWidth = this.width + 'px'; }
|
|
|
|
if (typeof cssHeight === 'undefined') { cssHeight = this.height + 'px'; }
|
|
|
|
|
|
|
|
var canvas = this.game.canvas;
|
2014-11-09 00:38:21 +00:00
|
|
|
if (!this.compatibility.noMargins)
|
2014-11-08 09:13:25 +00:00
|
|
|
{
|
|
|
|
canvas.style.marginLeft = '';
|
|
|
|
canvas.style.marginTop = '';
|
|
|
|
canvas.style.marginRight = '';
|
|
|
|
canvas.style.marginBottom = '';
|
|
|
|
}
|
2014-11-08 07:24:57 +00:00
|
|
|
canvas.style.width = cssWidth;
|
|
|
|
canvas.style.height = cssHeight;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2014-11-07 21:18:56 +00:00
|
|
|
/**
|
|
|
|
* Queues/marks a size/bounds check as needing to occur (from `preUpdate`).
|
2014-11-08 07:24:57 +00:00
|
|
|
* @method Phaser.ScaleManager#queueUpdate
|
2014-11-07 21:18:56 +00:00
|
|
|
* @private
|
|
|
|
* @param {boolean|undefined} force - If true updates the parent bounds to ensure the check is dirty; if false updates current bounds; if not specified does not update bounds.
|
|
|
|
*/
|
|
|
|
queueUpdate: function (force) {
|
|
|
|
if (force === true)
|
2014-10-31 08:41:06 +00:00
|
|
|
{
|
2014-11-07 21:18:56 +00:00
|
|
|
this._parentBounds.width = 0;
|
|
|
|
this._parentBounds.height = 0;
|
|
|
|
}
|
|
|
|
else if (force === false)
|
|
|
|
{
|
2014-11-08 07:24:57 +00:00
|
|
|
this.getParentBounds(this._parentBounds);
|
2014-10-31 08:41:06 +00:00
|
|
|
}
|
2013-11-04 20:43:59 +00:00
|
|
|
|
2014-11-08 09:13:25 +00:00
|
|
|
this._sizeThrottle = 0;
|
2013-09-09 11:35:20 +00:00
|
|
|
},
|
|
|
|
|
2014-10-31 10:29:54 +00:00
|
|
|
/**
|
|
|
|
* Reset internal data/state.
|
|
|
|
*
|
|
|
|
* @method Phaser.ScaleManager#reset
|
|
|
|
* @private
|
|
|
|
*/
|
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-10-31 08:41:06 +00:00
|
|
|
* Updates the width/height to that of the window.
|
2014-09-01 00:02:41 +00:00
|
|
|
*
|
2014-11-01 01:06:36 +00:00
|
|
|
* @method Phaser.ScaleManager#setMaximum
|
2014-10-31 08:41:06 +00:00
|
|
|
* @private
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2014-11-01 01:06:36 +00:00
|
|
|
setMaximum: function () {
|
2013-09-09 11:35:20 +00:00
|
|
|
|
|
|
|
this.width = window.innerWidth;
|
|
|
|
this.height = window.innerHeight;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2014-10-31 10:29:54 +00:00
|
|
|
* Updates the width/height such that the game is scaled proportionally.
|
2014-09-01 00:02:41 +00:00
|
|
|
*
|
2014-02-25 14:46:48 +00:00
|
|
|
* @method Phaser.ScaleManager#setShowAll
|
2014-10-31 08:41:06 +00:00
|
|
|
* @private
|
2014-11-08 07:24:57 +00:00
|
|
|
* @param {boolean} expanding - If true then the maximizing dimension is chosen.
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2014-11-08 07:24:57 +00:00
|
|
|
setShowAll: function (expanding) {
|
2013-09-09 11:35:20 +00:00
|
|
|
|
2014-10-31 08:41:06 +00:00
|
|
|
var bounds = this.getParentBounds();
|
|
|
|
var width = bounds.width;
|
|
|
|
var height = bounds.height;
|
|
|
|
|
2014-11-08 07:24:57 +00:00
|
|
|
var multiplier;
|
|
|
|
if (expanding)
|
|
|
|
{
|
|
|
|
multiplier = Math.max((height / this.game.height), (width / this.game.width));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
multiplier = Math.min((height / this.game.height), (width / 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
|
|
|
/**
|
2014-10-31 10:29:54 +00:00
|
|
|
* Updates the width/height such that the game is stretched to the available size.
|
2014-11-09 00:38:21 +00:00
|
|
|
* Honors `maxWidth` and `maxHeight` when _not_ in fullscreen.
|
2014-10-31 08:41:06 +00:00
|
|
|
*
|
2014-02-25 14:46:48 +00:00
|
|
|
* @method Phaser.ScaleManager#setExactFit
|
2014-10-31 08:41:06 +00:00
|
|
|
* @private
|
2013-10-01 12:54:29 +00:00
|
|
|
*/
|
2013-09-09 11:35:20 +00:00
|
|
|
setExactFit: function () {
|
|
|
|
|
2014-11-07 21:18:56 +00:00
|
|
|
var bounds = this.getParentBounds();
|
|
|
|
|
2014-11-08 07:24:57 +00:00
|
|
|
this.width = bounds.width;
|
|
|
|
this.height = bounds.height;
|
|
|
|
|
2014-11-07 21:18:56 +00:00
|
|
|
if (this.isFullScreen)
|
|
|
|
{
|
|
|
|
// Max/min not honored fullscreen
|
2014-10-31 08:41:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-11-08 07:24:57 +00:00
|
|
|
if (this.maxWidth)
|
2013-09-09 11:35:20 +00:00
|
|
|
{
|
2014-11-08 07:24:57 +00:00
|
|
|
this.width = Math.min(this.width, this.maxWidth);
|
2013-09-09 11:35:20 +00:00
|
|
|
}
|
|
|
|
|
2014-11-08 07:24:57 +00:00
|
|
|
if (this.maxHeight)
|
2013-09-09 11:35:20 +00:00
|
|
|
{
|
2014-11-08 07:24:57 +00:00
|
|
|
this.height = Math.min(this.height, this.maxHeight);
|
2013-09-09 11:35:20 +00:00
|
|
|
}
|
|
|
|
|
2014-08-28 02:31:47 +00:00
|
|
|
},
|
|
|
|
|
2014-09-01 00:02:41 +00:00
|
|
|
/**
|
2014-11-09 00:38:21 +00:00
|
|
|
* Start the browser's fullscreen mode - this _must_ be called from a user input Pointer or Mouse event.
|
2014-10-31 08:41:06 +00:00
|
|
|
*
|
2014-11-09 00:38:21 +00:00
|
|
|
* The Fullscreen API must be supported by the browser for this to work. It is not the same as setting the game size to fill the browser window.
|
|
|
|
* See `compatibility.supportsFullScreen` to check if the current device appears to support fullscreen mode.
|
2014-10-31 22:31:03 +00:00
|
|
|
*
|
2014-11-07 21:18:56 +00:00
|
|
|
* The `fullScreenFailed` signal will be dispatched if the fullscreen change request failed or the game does not support the Fullscreen API.
|
2014-11-01 08:23:14 +00:00
|
|
|
*
|
2014-09-01 00:02:41 +00:00
|
|
|
* @method Phaser.ScaleManager#startFullScreen
|
2014-10-31 08:41:06 +00:00
|
|
|
* @public
|
2014-11-09 00:38:21 +00:00
|
|
|
* @param {boolean} [antialias] - Changes the anti-alias feature of the canvas before jumping in to fullscreen (false = retain pixel art, true = smooth art). If not specified then no change is made. Only works in CANVAS mode.
|
2014-11-01 08:23:14 +00:00
|
|
|
* @param {boolean} [allowTrampoline=undefined] - Internal argument. If false click trampolining is suppressed.
|
2014-10-31 10:29:54 +00:00
|
|
|
* @return {boolean} Returns true if the device supports fullscreen mode and fullscreen mode was attempted to be started. (It might not actually start, wait for the signals.)
|
2014-09-01 00:02:41 +00:00
|
|
|
*/
|
2014-11-01 08:23:14 +00:00
|
|
|
startFullScreen: function (antialias, allowTrampoline) {
|
2014-09-01 00:02:41 +00:00
|
|
|
|
2014-10-31 22:31:03 +00:00
|
|
|
if (this.isFullScreen)
|
2014-09-01 00:02:41 +00:00
|
|
|
{
|
2014-10-31 08:41:06 +00:00
|
|
|
return false;
|
2014-09-01 00:02:41 +00:00
|
|
|
}
|
|
|
|
|
2014-11-09 00:38:21 +00:00
|
|
|
if (!this.compatibility.supportsFullScreen)
|
2014-10-31 22:31:03 +00:00
|
|
|
{
|
2014-11-01 08:23:14 +00:00
|
|
|
// Error is called in timeout to emulate the real fullscreenerror event better
|
2014-11-01 02:41:55 +00:00
|
|
|
var _this = this;
|
|
|
|
setTimeout(function () {
|
|
|
|
_this.fullScreenError();
|
2014-11-07 21:18:56 +00:00
|
|
|
}, 10);
|
2014-11-01 01:06:36 +00:00
|
|
|
return;
|
2014-10-31 22:31:03 +00:00
|
|
|
}
|
|
|
|
|
2014-11-01 08:23:14 +00:00
|
|
|
// IE11 clicks trigger MSPointer which is not the mousePointer
|
|
|
|
var input = this.game.input;
|
|
|
|
if (input.activePointer !== input.mousePointer &&
|
2014-11-07 21:18:56 +00:00
|
|
|
(allowTrampoline || allowTrampoline !== false))
|
2014-11-01 08:23:14 +00:00
|
|
|
{
|
|
|
|
input.activePointer.addClickTrampoline(
|
|
|
|
"startFullScreen", this.startFullScreen, this, [antialias, false]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-01 00:02:41 +00:00
|
|
|
if (typeof antialias !== 'undefined' && this.game.renderType === Phaser.CANVAS)
|
|
|
|
{
|
|
|
|
this.game.stage.smoothed = antialias;
|
|
|
|
}
|
|
|
|
|
2014-11-07 21:18:56 +00:00
|
|
|
var fsTarget = this.fullScreenTarget;
|
|
|
|
|
|
|
|
if (!fsTarget)
|
|
|
|
{
|
|
|
|
this.cleanupCreatedTarget();
|
|
|
|
|
|
|
|
this._createdFullScreenTarget = this.createFullScreenTarget();
|
|
|
|
fsTarget = this._createdFullScreenTarget;
|
|
|
|
|
|
|
|
// Move the game canvas inside of the target and add the target to the DOM
|
|
|
|
// (The target has to be added for the Fullscreen API to work.)
|
2014-11-08 09:13:25 +00:00
|
|
|
var canvas = this.game.canvas;
|
|
|
|
var parent = canvas.parentNode;
|
|
|
|
parent.insertBefore(fsTarget, canvas);
|
|
|
|
fsTarget.appendChild(canvas);
|
2014-11-07 21:18:56 +00:00
|
|
|
}
|
|
|
|
|
2014-09-01 00:02:41 +00:00
|
|
|
if (this.game.device.fullscreenKeyboard)
|
|
|
|
{
|
2014-11-07 21:18:56 +00:00
|
|
|
fsTarget[this.game.device.requestFullscreen](Element.ALLOW_KEYBOARD_INPUT);
|
2014-09-01 00:02:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-11-07 21:18:56 +00:00
|
|
|
fsTarget[this.game.device.requestFullscreen]();
|
2014-09-01 00:02:41 +00:00
|
|
|
}
|
|
|
|
|
2014-10-31 08:41:06 +00:00
|
|
|
return true;
|
|
|
|
|
2014-09-01 00:02:41 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-11-09 00:38:21 +00:00
|
|
|
* Stops fullscreen mode, if active.
|
2014-10-31 08:41:06 +00:00
|
|
|
*
|
2014-09-01 00:02:41 +00:00
|
|
|
* @method Phaser.ScaleManager#stopFullScreen
|
2014-10-31 08:41:06 +00:00
|
|
|
* @public
|
2014-10-31 10:29:54 +00:00
|
|
|
* @return {boolean} Returns true if the browser supports fullscreen mode and fullscreen mode will be exited.
|
2014-09-01 00:02:41 +00:00
|
|
|
*/
|
|
|
|
stopFullScreen: function () {
|
|
|
|
|
2014-11-09 00:38:21 +00:00
|
|
|
if (!this.isFullScreen || !this.compatibility.supportsFullScreen)
|
2014-10-31 08:41:06 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-09-01 00:02:41 +00:00
|
|
|
document[this.game.device.cancelFullscreen]();
|
|
|
|
|
2014-10-31 08:41:06 +00:00
|
|
|
return true;
|
|
|
|
|
2014-09-01 00:02:41 +00:00
|
|
|
},
|
|
|
|
|
2014-11-07 21:18:56 +00:00
|
|
|
/**
|
2014-11-09 00:38:21 +00:00
|
|
|
* Cleans up the previous fullscreen target, if such was automatically created.
|
2014-11-07 21:18:56 +00:00
|
|
|
* This ensures the canvas is restored to its former parent, assuming the target didn't move.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
cleanupCreatedTarget: function () {
|
|
|
|
|
|
|
|
var fsTarget = this._createdFullScreenTarget;
|
|
|
|
if (fsTarget && fsTarget.parentNode)
|
|
|
|
{
|
|
|
|
// Make sure to cleanup synthetic target for sure;
|
|
|
|
// swap the canvas back to the parent.
|
|
|
|
var parent = fsTarget.parentNode;
|
|
|
|
parent.insertBefore(this.game.canvas, fsTarget);
|
|
|
|
parent.removeChild(fsTarget);
|
|
|
|
}
|
|
|
|
|
2014-11-09 00:38:21 +00:00
|
|
|
this._createdFullScreenTarget = null;
|
|
|
|
|
2014-11-07 21:18:56 +00:00
|
|
|
},
|
|
|
|
|
2014-09-01 00:02:41 +00:00
|
|
|
/**
|
2014-10-31 08:41:06 +00:00
|
|
|
* Used to prepare/restore extra fullscreen mode settings.
|
2014-11-07 21:18:56 +00:00
|
|
|
* (This does move any elements within the DOM tree.)
|
2014-10-31 08:41:06 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.ScaleManager#prepScreenMode
|
|
|
|
* @private
|
2014-11-07 21:18:56 +00:00
|
|
|
* @param {boolean} enteringFullscreen - True if _entering_ fullscreen, false if _leaving_.
|
2014-09-01 00:02:41 +00:00
|
|
|
*/
|
2014-11-07 21:18:56 +00:00
|
|
|
prepScreenMode: function (enteringFullscreen) {
|
2014-09-01 00:02:41 +00:00
|
|
|
|
2014-11-07 21:18:56 +00:00
|
|
|
var createdTarget = !!this._createdFullScreenTarget;
|
|
|
|
var fsTarget = this._createdFullScreenTarget || this.fullScreenTarget;
|
2014-09-01 00:02:41 +00:00
|
|
|
|
2014-11-07 21:18:56 +00:00
|
|
|
if (enteringFullscreen)
|
2014-09-01 00:02:41 +00:00
|
|
|
{
|
2014-11-08 09:13:25 +00:00
|
|
|
if (createdTarget || this.fullScreenScaleMode === Phaser.ScaleManager.EXACT_FIT)
|
2014-10-31 08:41:06 +00:00
|
|
|
{
|
2014-11-07 21:18:56 +00:00
|
|
|
// Resize target, as long as it's not the canvas
|
|
|
|
if (fsTarget !== this.game.canvas)
|
2014-10-31 08:41:06 +00:00
|
|
|
{
|
2014-11-09 00:38:21 +00:00
|
|
|
this._fullScreenRestore = {
|
|
|
|
targetWidth: fsTarget.style.width,
|
|
|
|
targetHeight: fsTarget.style.height
|
2014-11-07 21:18:56 +00:00
|
|
|
};
|
|
|
|
|
2014-11-09 00:38:21 +00:00
|
|
|
fsTarget.style.width = '100%';
|
|
|
|
fsTarget.style.height = '100%';
|
2014-10-31 08:41:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-11-07 21:18:56 +00:00
|
|
|
// Have restore information
|
|
|
|
if (this._fullScreenRestore)
|
2014-10-31 08:41:06 +00:00
|
|
|
{
|
2014-11-09 00:38:21 +00:00
|
|
|
fsTarget.style.width = this._fullScreenRestore.targetWidth;
|
|
|
|
fsTarget.style.height = this._fullScreenRestore.targetHeight;
|
2014-09-01 00:02:41 +00:00
|
|
|
|
2014-11-07 21:18:56 +00:00
|
|
|
this._fullScreenRestore = null;
|
|
|
|
}
|
2014-10-31 08:41:06 +00:00
|
|
|
|
2014-11-09 00:38:21 +00:00
|
|
|
// Always reset to game size
|
2014-11-08 07:24:57 +00:00
|
|
|
this.updateDimensions(this._gameSize.width, this._gameSize.height, true);
|
|
|
|
this.resetCanvas();
|
2014-10-31 08:41:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-11-09 00:38:21 +00:00
|
|
|
* Called automatically when the browser enters of leaves fullscreen mode.
|
2014-10-31 08:41:06 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.ScaleManager#fullScreenChange
|
|
|
|
* @protected
|
|
|
|
* @param {Event} [event=undefined] - The fullscreenchange event
|
|
|
|
*/
|
|
|
|
fullScreenChange: function (event) {
|
|
|
|
|
|
|
|
this.event = event;
|
|
|
|
|
|
|
|
if (this.isFullScreen)
|
|
|
|
{
|
|
|
|
this.prepScreenMode(true);
|
|
|
|
|
2014-11-07 21:18:56 +00:00
|
|
|
this.setScreenSize();
|
|
|
|
this.queueUpdate(true);
|
2014-09-01 00:02:41 +00:00
|
|
|
|
|
|
|
this.enterFullScreen.dispatch(this.width, this.height);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-10-31 08:41:06 +00:00
|
|
|
this.prepScreenMode(false);
|
2014-09-01 00:02:41 +00:00
|
|
|
|
2014-11-07 21:18:56 +00:00
|
|
|
this.cleanupCreatedTarget();
|
|
|
|
|
|
|
|
this.setScreenSize();
|
|
|
|
this.queueUpdate(true);
|
2014-09-01 00:02:41 +00:00
|
|
|
|
|
|
|
this.leaveFullScreen.dispatch(this.width, this.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2014-08-28 02:31:47 +00:00
|
|
|
/**
|
2014-10-31 22:31:03 +00:00
|
|
|
* Called automatically when the browser fullscreen request fails;
|
|
|
|
* or called when a fullscreen request is made on a device for which it is not supported.
|
|
|
|
*
|
|
|
|
* @method Phaser.ScaleManager#fullScreenError
|
|
|
|
* @protected
|
|
|
|
* @param {Event} [event=undefined] - The fullscreenerror event; undefined if invoked on a device that does not support the Fullscreen API.
|
|
|
|
*/
|
|
|
|
fullScreenError: function (event) {
|
|
|
|
|
|
|
|
this.event = event;
|
|
|
|
|
2014-11-07 21:18:56 +00:00
|
|
|
this.cleanupCreatedTarget();
|
|
|
|
|
2014-11-09 00:38:21 +00:00
|
|
|
console.warn('Phaser.ScaleManager: requestFullscreen failed or device does not support the Fullscreen API');
|
2014-11-08 13:24:38 +00:00
|
|
|
|
2014-11-01 02:41:55 +00:00
|
|
|
this.fullScreenFailed.dispatch();
|
2014-10-31 22:31:03 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2014-11-08 13:24:38 +00:00
|
|
|
/**
|
|
|
|
* A cross-browser element.getBoundingClientRect method with optional cushion.
|
|
|
|
*
|
|
|
|
* Returns a plain object containing the properties `top/bottom/left/right/width/height` with respect to the top-left corner of the current viewport.
|
|
|
|
* Its properties match the native rectangle.
|
|
|
|
* The cushion parameter is an amount of pixels (+/-) to cushion the element.
|
|
|
|
* It adjusts the measurements such that it is possible to detect when an element is near the viewport.
|
|
|
|
*
|
|
|
|
* @method Phaser.ScaleManager#elementBounds
|
|
|
|
* @public
|
|
|
|
* @param {Element|Object} element - The element or stack (uses first item) to get the bounds for. If none given it defaults to the Phaser game canvas.
|
|
|
|
* @param {number} [cushion] - A +/- pixel adjustment amount.
|
|
|
|
* @return {Object|boolean} A plain object containing the properties `top/bottom/left/right/width/height` or `false` if a non-valid element is given.
|
|
|
|
*/
|
|
|
|
elementBounds: function (element, cushion) {
|
|
|
|
|
|
|
|
if (typeof element === 'undefined') { element = this.game.canvas; }
|
|
|
|
if (typeof cushion === 'undefined') { cushion = 0; }
|
|
|
|
|
|
|
|
element = element && !element.nodeType ? element[0] : element;
|
|
|
|
|
|
|
|
if (!element || element.nodeType !== 1)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return this.calibrate(element.getBoundingClientRect(), cushion);
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calibrates element coordinates for `inViewport` checks.
|
|
|
|
*
|
|
|
|
* @method Phaser.ScaleManager#calibrate
|
|
|
|
* @private
|
|
|
|
* @param {Object} coords -An object containing the following properties: `{top: number, right: number, bottom: number, left: number}`
|
|
|
|
* @param {number} [cushion] - A value to adjust the coordinates by.
|
|
|
|
* @return {Object} The calibrated element coordinates
|
|
|
|
*/
|
|
|
|
calibrate: function (coords, cushion) {
|
|
|
|
|
|
|
|
cushion = +cushion || 0;
|
|
|
|
|
|
|
|
var output = { width: 0, height: 0, left: 0, right: 0, top: 0, bottom: 0 };
|
|
|
|
|
|
|
|
output.width = (output.right = coords.right + cushion) - (output.left = coords.left - cushion);
|
|
|
|
output.height = (output.bottom = coords.bottom + cushion) - (output.top = coords.top - cushion);
|
|
|
|
|
|
|
|
return output;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the viewport aspect ratio (or the aspect ratio of an object or element)
|
|
|
|
* @link http://w3.org/TR/css3-mediaqueries/#orientation
|
|
|
|
*
|
|
|
|
* @method Phaser.ScaleManager#aspect
|
|
|
|
* @public
|
|
|
|
* @param {(Element|Object)=} [object] - Optional object. Must have public `width` and `height` properties or methods.
|
|
|
|
* @return {number} The aspect ratio.
|
|
|
|
*/
|
|
|
|
aspect: function (object) {
|
|
|
|
|
|
|
|
object = null == object ? this.viewport() : 1 === object.nodeType ? this.elementBounds(object) : object;
|
|
|
|
|
|
|
|
var w = object['width'];
|
|
|
|
var h = object['height'];
|
|
|
|
|
|
|
|
if (typeof w === 'function')
|
|
|
|
{
|
|
|
|
w = w.call(object);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof h === 'function')
|
|
|
|
{
|
|
|
|
h = h.call(object);
|
|
|
|
}
|
|
|
|
|
|
|
|
return w / h;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests if the given DOM element is within the viewport.
|
|
|
|
*
|
|
|
|
* The optional cushion parameter allows you to specify a distance.
|
|
|
|
*
|
|
|
|
* inViewport(element, 100) is `true` if the element is in the viewport or 100px near it.
|
|
|
|
* inViewport(element, -100) is `true` if the element is in the viewport or at least 100px near it.
|
|
|
|
*
|
|
|
|
* @method Phaser.ScaleManager#inViewport
|
|
|
|
* @public
|
|
|
|
* @param {Element|Object} [element] - The DOM element to check. If no element is given it defaults to the Phaser game canvas.
|
|
|
|
* @param {number} [cushion] - The cushion allows you to specify a distance within which the element must be within the viewport.
|
|
|
|
* @return {boolean} True if the element is within the viewport, or within `cushion` distance from it.
|
|
|
|
*/
|
|
|
|
inViewport: function (element, cushion) {
|
|
|
|
|
|
|
|
if (typeof element === 'undefined') { element = this.game.canvas; }
|
|
|
|
|
|
|
|
var r = this.elementBounds(element, cushion);
|
|
|
|
|
|
|
|
return !!r && r.bottom >= 0 && r.right >= 0 && r.top <= this.viewportH() && r.left <= this.viewportW();
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Takes a Sprite or Image object and scales it to fit the given dimensions.
|
|
|
|
* Scaling happens proportionally without distortion to the sprites texture.
|
|
|
|
* The letterBox parameter controls if scaling will produce a letter-box effect or zoom the
|
|
|
|
* sprite until it fills the given values. Note that with letterBox set to false the scaled sprite may spill out over either
|
|
|
|
* the horizontal or vertical sides of the target dimensions. If you wish to stop this you can crop the Sprite.
|
|
|
|
*
|
|
|
|
* @method Phaser.ScaleManager#scaleSprite
|
|
|
|
* @public
|
|
|
|
* @param {Phaser.Sprite|Phaser.Image} sprite - The sprite we want to scale.
|
|
|
|
* @param {integer} [width] - The target width that we want to fit the sprite in to. If not given it defaults to ScaleManager.width.
|
|
|
|
* @param {integer} [height] - The target height that we want to fit the sprite in to. If not given it defaults to ScaleManager.height.
|
|
|
|
* @param {boolean} [letterBox=false] - True if we want the `fitted` mode. Otherwise, the function uses the `zoom` mode.
|
|
|
|
* @return {Phaser.Sprite|Phaser.Image} The scaled sprite.
|
|
|
|
*/
|
|
|
|
scaleSprite: function (sprite, width, height, letterBox) {
|
|
|
|
|
|
|
|
if (typeof width === 'undefined') { width = this.width; }
|
|
|
|
if (typeof height === 'undefined') { height = this.height; }
|
2014-11-08 14:04:17 +00:00
|
|
|
if (typeof letterBox === 'undefined') { letterBox = false; }
|
2014-11-08 13:24:38 +00:00
|
|
|
|
|
|
|
sprite.scale.set(1);
|
|
|
|
|
|
|
|
if ((sprite.width <= 0) || (sprite.height <= 0) || (width <= 0) || (height <= 0))
|
|
|
|
{
|
|
|
|
return sprite;
|
|
|
|
}
|
|
|
|
|
|
|
|
var scaleX1 = width;
|
|
|
|
var scaleY1 = (sprite.height * width) / sprite.width;
|
|
|
|
|
|
|
|
var scaleX2 = (sprite.width * height) / sprite.height;
|
|
|
|
var scaleY2 = height;
|
|
|
|
|
|
|
|
var scaleOnWidth = (scaleX2 > width);
|
|
|
|
|
|
|
|
if (scaleOnWidth)
|
|
|
|
{
|
|
|
|
scaleOnWidth = letterBox;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
scaleOnWidth = !letterBox;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (scaleOnWidth)
|
|
|
|
{
|
|
|
|
sprite.width = Math.floor(scaleX1);
|
|
|
|
sprite.height = Math.floor(scaleY1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sprite.width = Math.floor(scaleX2);
|
|
|
|
sprite.height = Math.floor(scaleY2);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enable at some point?
|
|
|
|
// sprite.x = Math.floor((width - sprite.width) / 2);
|
|
|
|
// sprite.y = Math.floor((height - sprite.height) / 2);
|
|
|
|
|
|
|
|
return sprite;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2014-10-31 22:31:03 +00:00
|
|
|
/**
|
|
|
|
* Destroys the ScaleManager and removes any event listeners.
|
|
|
|
* This should probably only be called when the game is destroyed.
|
|
|
|
*
|
|
|
|
* @method destroy
|
|
|
|
* @protected
|
|
|
|
*/
|
2014-08-28 02:31:47 +00:00
|
|
|
destroy: function () {
|
|
|
|
|
2014-10-31 08:41:06 +00:00
|
|
|
window.removeEventListener('orientationchange', this._orientationChange, false);
|
|
|
|
window.removeEventListener('resize', this._windowResize, false);
|
2014-08-28 02:31:47 +00:00
|
|
|
|
2014-11-09 00:38:21 +00:00
|
|
|
if (this.compatibility.supportsFullScreen)
|
2014-08-28 02:31:47 +00:00
|
|
|
{
|
2014-08-28 20:54:09 +00:00
|
|
|
document.removeEventListener('webkitfullscreenchange', this._fullScreenChange, false);
|
|
|
|
document.removeEventListener('mozfullscreenchange', this._fullScreenChange, false);
|
2014-10-31 22:31:03 +00:00
|
|
|
document.removeEventListener('MSFullscreenChange', this._fullScreenChange, false);
|
2014-08-28 20:54:09 +00:00
|
|
|
document.removeEventListener('fullscreenchange', this._fullScreenChange, false);
|
2014-10-31 22:31:03 +00:00
|
|
|
|
|
|
|
document.removeEventListener('webkitfullscreenerror', this._fullScreenError, false);
|
|
|
|
document.removeEventListener('mozfullscreenerror', this._fullScreenError, false);
|
|
|
|
document.removeEventListener('MSFullscreenError', this._fullScreenError, false);
|
|
|
|
document.removeEventListener('fullscreenerror', this._fullScreenError, 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-11-01 01:06:36 +00:00
|
|
|
/**
|
|
|
|
* window.resize event handler.
|
|
|
|
* @method checkResize
|
|
|
|
* @memberof Phaser.ScaleManager
|
|
|
|
* @protected
|
|
|
|
* @deprecated 2.1.4 - Internal. _Do not use_
|
|
|
|
*/
|
|
|
|
Phaser.ScaleManager.prototype.checkResize = Phaser.ScaleManager.prototype.windowResize;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* window.orientationchange event handler.
|
|
|
|
* @method checkOrientation
|
|
|
|
* @memberof Phaser.ScaleManager
|
|
|
|
* @protected
|
|
|
|
* @deprecated 2.1.4 - Internal. _Do not use_
|
|
|
|
*/
|
|
|
|
Phaser.ScaleManager.prototype.checkOrientation = Phaser.ScaleManager.prototype.orientationChange;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the size/position of the canvas based on internal state.
|
|
|
|
* @method setSize
|
|
|
|
* @memberof Phaser.ScaleManager
|
|
|
|
* @protected
|
|
|
|
* @deprecated 2.1.4 - Internal. Use `refresh` if needed.
|
|
|
|
*/
|
|
|
|
Phaser.ScaleManager.prototype.setSize = Phaser.ScaleManager.prototype.reflowCanvas;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the browser is in the correct orientation for the game, dependent upon `forceLandscape` and `forcePortrait`, and updates the state.
|
|
|
|
*
|
|
|
|
* The appropriate event is dispatched if the orientation became valid or invalid.
|
|
|
|
*
|
|
|
|
* @method checkOrientationState
|
|
|
|
* @memberof Phaser.ScaleManager
|
|
|
|
* @protected
|
|
|
|
* @return {boolean} True if the orientation state changed (consider a refresh)
|
|
|
|
* @deprecated 2.1.4 - This is only for backward compatibility of user code.
|
|
|
|
*/
|
|
|
|
Phaser.ScaleManager.prototype.checkOrientationState = function () {
|
|
|
|
|
2014-11-08 09:13:25 +00:00
|
|
|
var orientationChanged = this.updateOrientationState();
|
|
|
|
if (orientationChanged)
|
2014-11-01 01:06:36 +00:00
|
|
|
{
|
|
|
|
this.refresh();
|
|
|
|
}
|
2014-11-08 09:13:25 +00:00
|
|
|
return orientationChanged;
|
2014-11-01 01:06:36 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2014-08-31 10:09:27 +00:00
|
|
|
/**
|
2014-10-31 08:41:06 +00:00
|
|
|
* The scaling method used by the ScaleManager.
|
|
|
|
*
|
2014-11-09 03:29:47 +00:00
|
|
|
* See {@link Phaser.ScaleManager.NO_SCALE}, {@link Phaser.ScaleManager.EXACT_FIT}, {@link Phaser.ScaleManager.SHOW_ALL}, {@link Phaser.ScaleManager.RESIZE}, {@link Phaser.ScaleManager.USER_SCALE}
|
2014-11-09 00:38:21 +00:00
|
|
|
*
|
2014-08-31 10:09:27 +00:00
|
|
|
* @name Phaser.ScaleManager#scaleMode
|
2014-10-31 08:41:06 +00:00
|
|
|
* @property {number} scaleMode
|
2014-08-31 10:09:27 +00:00
|
|
|
*/
|
|
|
|
Object.defineProperty(Phaser.ScaleManager.prototype, "scaleMode", {
|
|
|
|
|
|
|
|
get: function () {
|
|
|
|
|
|
|
|
return this._scaleMode;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value) {
|
|
|
|
|
|
|
|
if (value !== this._scaleMode)
|
|
|
|
{
|
2014-11-07 21:18:56 +00:00
|
|
|
if (!this.isFullScreen)
|
2014-10-31 08:41:06 +00:00
|
|
|
{
|
2014-11-08 07:24:57 +00:00
|
|
|
this.updateDimensions(this._gameSize.width, this._gameSize.height, true);
|
2014-11-07 21:18:56 +00:00
|
|
|
this.queueUpdate(true);
|
2014-10-31 08:41:06 +00:00
|
|
|
}
|
2014-11-07 21:18:56 +00:00
|
|
|
|
|
|
|
this._scaleMode = value;
|
2014-10-31 08:41:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return this._scaleMode;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
2014-11-09 00:38:21 +00:00
|
|
|
* The scaling method used by the ScaleManager when in fullscreen.
|
2014-10-31 08:41:06 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.ScaleManager#fullScreenScaleMode
|
|
|
|
* @property {number} fullScreenScaleMode
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
Object.defineProperty(Phaser.ScaleManager.prototype, "fullScreenScaleMode", {
|
|
|
|
|
|
|
|
get: function () {
|
|
|
|
|
|
|
|
return this._fullScreenScaleMode;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value) {
|
|
|
|
|
|
|
|
if (value !== this._fullScreenScaleMode)
|
|
|
|
{
|
|
|
|
// If in fullscreen then need a wee bit more work
|
|
|
|
if (this.isFullScreen)
|
|
|
|
{
|
|
|
|
this.prepScreenMode(false);
|
|
|
|
this._fullScreenScaleMode = value;
|
|
|
|
this.prepScreenMode(true);
|
2014-11-07 21:18:56 +00:00
|
|
|
|
|
|
|
this.queueUpdate(true);
|
2014-10-31 08:41:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this._fullScreenScaleMode = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return this._fullScreenScaleMode;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the current scale mode - for normal or fullscreen operation.
|
|
|
|
*
|
|
|
|
* @name Phaser.ScaleManager#currentScaleMode
|
|
|
|
* @property {number} currentScaleMode
|
|
|
|
* @protected
|
|
|
|
* @readonly
|
|
|
|
*/
|
|
|
|
Object.defineProperty(Phaser.ScaleManager.prototype, "currentScaleMode", {
|
|
|
|
|
|
|
|
get: function () {
|
|
|
|
|
|
|
|
return this.isFullScreen ? this._fullScreenScaleMode : this._scaleMode;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If true then the game canvas will be horizontally-aligned _in the parent container_.
|
|
|
|
*
|
|
|
|
* To align across the page the game canvas should be added directly to page;
|
|
|
|
* or the parent container should itself be aligned.
|
|
|
|
*
|
|
|
|
* This is not applicable for the `RESIZE` scaling mode.
|
|
|
|
*
|
|
|
|
* @name Phaser.ScaleManager#pageAlignHorizontally
|
|
|
|
* @property {boolean} pageAlignHorizontally
|
|
|
|
* @default false
|
|
|
|
*/
|
|
|
|
Object.defineProperty(Phaser.ScaleManager.prototype, "pageAlignHorizontally", {
|
|
|
|
|
|
|
|
get: function () {
|
|
|
|
|
|
|
|
return this._pageAlignHorizontally;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value) {
|
|
|
|
|
|
|
|
if (value !== this._pageAlignHorizontally)
|
|
|
|
{
|
|
|
|
this._pageAlignHorizontally = value;
|
2014-11-07 21:18:56 +00:00
|
|
|
this.queueUpdate(true);
|
2014-10-31 08:41:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If true then the game canvas will be vertically-aligned _in the parent container_.
|
|
|
|
*
|
|
|
|
* To align across the page the game canvas should be added directly to page;
|
|
|
|
* or the parent container should itself be aligned.
|
|
|
|
*
|
|
|
|
* This is not applicable for the `RESIZE` scaling mode.
|
|
|
|
*
|
|
|
|
* @name Phaser.ScaleManager#pageAlignVertically
|
|
|
|
* @property {boolean} pageAlignVertically
|
|
|
|
* @default false
|
|
|
|
*/
|
|
|
|
Object.defineProperty(Phaser.ScaleManager.prototype, "pageAlignVertically", {
|
|
|
|
|
|
|
|
get: function () {
|
|
|
|
|
|
|
|
return this._pageAlignVertically;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
set: function (value) {
|
|
|
|
|
|
|
|
if (value !== this._pageAlignVertically)
|
|
|
|
{
|
|
|
|
this._pageAlignVertically = value;
|
2014-11-07 21:18:56 +00:00
|
|
|
this.queueUpdate(true);
|
2014-08-31 10:09:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2013-10-01 12:54:29 +00:00
|
|
|
/**
|
2014-11-09 00:38:21 +00:00
|
|
|
* Returns true if the browser is in fullscreen mode, otherwise false.
|
2014-02-25 14:46:48 +00:00
|
|
|
* @name Phaser.ScaleManager#isFullScreen
|
2014-10-31 08:41:06 +00:00
|
|
|
* @property {boolean} isFullScreen
|
2013-10-03 00:21:08 +00:00
|
|
|
* @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-10-31 08:41:06 +00:00
|
|
|
return !!(document['fullscreenElement'] ||
|
2014-10-31 22:31:03 +00:00
|
|
|
document['webkitFullscreenElement'] ||
|
2014-11-01 01:06:36 +00:00
|
|
|
document['mozFullScreenElement'] ||
|
2014-10-31 22:31:03 +00:00
|
|
|
document['msFullscreenElement']);
|
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-11-07 21:18:56 +00:00
|
|
|
* Returns true if the browser dimensions match a portrait display.
|
2014-02-25 14:46:48 +00:00
|
|
|
* @name Phaser.ScaleManager#isPortrait
|
2014-11-07 21:18:56 +00:00
|
|
|
* @property {boolean} isPortrait
|
2013-10-03 00:21:08 +00:00
|
|
|
* @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-11-07 21:18:56 +00:00
|
|
|
* Returns true if the browser dimensions match a landscape display.
|
2014-02-25 14:46:48 +00:00
|
|
|
* @name Phaser.ScaleManager#isLandscape
|
2014-11-07 21:18:56 +00:00
|
|
|
* @property {boolean} isLandscape
|
2013-10-03 00:21:08 +00:00
|
|
|
* @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
|
|
|
|
|
|
|
});
|
2014-11-08 13:24:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A cross-browser window.scrollX.
|
|
|
|
*
|
|
|
|
* @name Phaser.ScaleManager#scrollX
|
|
|
|
* @property {number} scrollX
|
2014-11-09 03:29:47 +00:00
|
|
|
* @readonly
|
2014-11-08 13:24:38 +00:00
|
|
|
*/
|
|
|
|
Object.defineProperty(Phaser.ScaleManager.prototype, "scrollX", {
|
|
|
|
|
|
|
|
get: function () {
|
|
|
|
return window.pageXOffset || document.documentElement.scrollLeft;
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A cross-browser window.scrollY.
|
|
|
|
*
|
|
|
|
* @name Phaser.ScaleManager#scrollY
|
|
|
|
* @property {number} scrollY
|
2014-11-09 03:29:47 +00:00
|
|
|
* @readonly
|
2014-11-08 13:24:38 +00:00
|
|
|
*/
|
|
|
|
Object.defineProperty(Phaser.ScaleManager.prototype, "scrollY", {
|
|
|
|
|
|
|
|
get: function () {
|
|
|
|
return window.pageYOffset || document.documentElement.scrollTop;
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the viewport width in pixels.
|
|
|
|
*
|
|
|
|
* @name Phaser.ScaleManager#viewportWidth
|
|
|
|
* @property {number} viewportWidth
|
2014-11-09 03:29:47 +00:00
|
|
|
* @readonly
|
2014-11-08 13:24:38 +00:00
|
|
|
*/
|
|
|
|
Object.defineProperty(Phaser.ScaleManager.prototype, "viewportWidth", {
|
|
|
|
|
|
|
|
get: function () {
|
|
|
|
|
|
|
|
var a = document.documentElement.clientWidth;
|
|
|
|
var b = window.innerWidth;
|
|
|
|
|
|
|
|
return a < b ? b : a;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the viewport height in pixels.
|
|
|
|
*
|
|
|
|
* @name Phaser.ScaleManager#viewportHeight
|
|
|
|
* @property {number} viewportHeight
|
2014-11-09 03:29:47 +00:00
|
|
|
* @readonly
|
2014-11-08 13:24:38 +00:00
|
|
|
*/
|
|
|
|
Object.defineProperty(Phaser.ScaleManager.prototype, "viewportHeight", {
|
|
|
|
|
|
|
|
get: function () {
|
|
|
|
|
|
|
|
var a = document.documentElement.clientHeight;
|
|
|
|
var b = window.innerHeight;
|
|
|
|
|
|
|
|
return a < b ? b : a;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the document width in pixels.
|
|
|
|
*
|
|
|
|
* @name Phaser.ScaleManager#documentWidth
|
|
|
|
* @property {number} documentWidth
|
2014-11-09 03:29:47 +00:00
|
|
|
* @readonly
|
2014-11-08 13:24:38 +00:00
|
|
|
*/
|
|
|
|
Object.defineProperty(Phaser.ScaleManager.prototype, "documentWidth", {
|
|
|
|
|
|
|
|
get: function () {
|
|
|
|
|
|
|
|
var d = document.documentElement;
|
|
|
|
return Math.max(d.clientWidth, d.offsetWidth, d.scrollWidth);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the document height in pixels.
|
|
|
|
*
|
|
|
|
* @name Phaser.ScaleManager#documentHeight
|
|
|
|
* @property {number} documentHeight
|
2014-11-09 03:29:47 +00:00
|
|
|
* @readonly
|
2014-11-08 13:24:38 +00:00
|
|
|
*/
|
|
|
|
Object.defineProperty(Phaser.ScaleManager.prototype, "documentHeight", {
|
|
|
|
|
|
|
|
get: function () {
|
|
|
|
|
|
|
|
var d = document.documentElement;
|
|
|
|
return Math.max(d.clientHeight, d.offsetHeight, d.scrollHeight);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|