diff --git a/README.md b/README.md index 076fa033..65fe4284 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,11 @@ Significant API changes: * Phaser.Stage now extends PIXI.Stage, rather than containing a _stage object. * If you set Sprite.exists to false it will also set Sprite.visible to false and remove its body from the physics world (if it has one). * If you set Sprite.exists to true it will also set Sprite.visible to true and add its body back into the physics world (if it has one). +* Stage.scale has been moved to Game.scale. The same game scaling properties exist as before, but now accessed via Game.scale instead. +* Stage.aspectRatio has been moved to StageScaleMode.sourceAspectRatio (so now game.scale.sourceAspectRatio) +* Stage.scaleMode has been moved to StageScaleMode.scaleMode (so now game.scale.scaleMode) +* Stage.fullScreenScaleMode has been moved to StageScaleMode.fullScreenScaleMode (so now game.scale.fullScreenScaleMode) +* Stage.canvas has been removed. It was only ever an alias for Game.canvas anyway, so access it via that instead. New features: diff --git a/src/core/Game.js b/src/core/Game.js index a23c6c20..4ccdfe8e 100644 --- a/src/core/Game.js +++ b/src/core/Game.js @@ -108,13 +108,11 @@ Phaser.Game = function (width, height, renderer, parent, state, transparent, ant /** * @property {Phaser.RequestAnimationFrame} raf - Automatically handles the core game loop via requestAnimationFrame or setTimeout - * @default */ this.raf = null; /** * @property {Phaser.GameObjectFactory} add - Reference to the GameObject Factory. - * @default */ this.add = null; @@ -138,92 +136,81 @@ Phaser.Game = function (width, height, renderer, parent, state, transparent, ant /** * @property {Phaser.Math} math - Reference to the math helper. - * @default */ this.math = null; /** * @property {Phaser.Net} net - Reference to the network class. - * @default */ this.net = null; + /** + * @property {Phaser.StageScaleMode} scale - The game scale manager. + */ + this.scale = null; + /** * @property {Phaser.SoundManager} sound - Reference to the sound manager. - * @default */ this.sound = null; /** * @property {Phaser.Stage} stage - Reference to the stage. - * @default */ this.stage = null; /** * @property {Phaser.TimeManager} time - Reference to game clock. - * @default */ this.time = null; /** * @property {Phaser.TweenManager} tweens - Reference to the tween manager. - * @default */ this.tweens = null; /** * @property {Phaser.World} world - Reference to the world. - * @default */ this.world = null; /** - * // {Phaser.Physics.Arcade.ArcadePhysics} physics - Reference to the physics manager. * @property {Phaser.Physics.World} physics - Reference to the physics world. - * @default */ this.physics = null; /** * @property {Phaser.RandomDataGenerator} rnd - Instance of repeatable random data generator helper. - * @default */ this.rnd = null; /** * @property {Phaser.Device} device - Contains device information and capabilities. - * @default */ this.device = null; /** * @property {Phaser.Physics.PhysicsManager} camera - A handy reference to world.camera. - * @default */ this.camera = null; - /** - * @property {HTMLCanvasElement} canvas - A handy reference to renderer.view. - * @default + /** + * @property {HTMLCanvasElement} canvas - A handy reference to renderer.view, the canvas that the game is being rendered in to. */ this.canvas = null; /** - * @property {Context} context - A handy reference to renderer.context (only set for CANVAS games) - * @default + * @property {Context} context - A handy reference to renderer.context (only set for CANVAS games, not WebGL) */ this.context = null; /** * @property {Phaser.Utils.Debug} debug - A set of useful debug utilitie. - * @default */ this.debug = null; /** * @property {Phaser.Particles} particles - The Particle Manager. - * @default */ this.particles = null; @@ -436,6 +423,7 @@ Phaser.Game.prototype = { this.rnd = new Phaser.RandomDataGenerator([(Date.now() * Math.random()).toString()]); this.stage = new Phaser.Stage(this, this.width, this.height); + this.scale = new Phaser.StageScaleMode(this, this.width, this.height); this.setUpRenderer(); diff --git a/src/core/Stage.js b/src/core/Stage.js index f834449b..cce76b0c 100644 --- a/src/core/Stage.js +++ b/src/core/Stage.js @@ -33,44 +33,11 @@ Phaser.Stage = function (game, width, height) { */ this.offset = new Phaser.Point(); - /** - * @property {HTMLCanvasElement} canvas - Reference to the newly created `canvas` element. - */ - this.canvas = null; - - /** - * @property {PIXI.Stage} _stage - The Pixi Stage which is hooked to the renderer. - * @private - */ - // this._stage = new PIXI.Stage(0x000000, false); - // this._stage.name = '_stage_root'; - // this._stage.interactive = false; - PIXI.Stage.call(this, 0x000000, false); this.name = '_stage_root'; this.interactive = false; - /** - * @property {number} scaleMode - The current scaleMode. - */ - this.scaleMode = Phaser.StageScaleMode.NO_SCALE; - - /* - * @property {number} fullScreenScaleMode - Scale mode to be used in fullScreen - */ - this.fullScreenScaleMode = Phaser.StageScaleMode.NO_SCALE; - - /** - * @property {Phaser.StageScaleMode} scale - The scale of the current running game. - */ - // this.scale = new Phaser.StageScaleMode(this.game, width, height); - - /** - * @property {number} aspectRatio - Aspect ratio. - */ - this.aspectRatio = width / height; - /** * @property {boolean} disableVisibilityChange - By default if the browser tab loses focus the game will pause. You can stop that behaviour by setting this property to true. * @default diff --git a/src/input/Pointer.js b/src/input/Pointer.js index e2b2b499..20ec3e86 100644 --- a/src/input/Pointer.js +++ b/src/input/Pointer.js @@ -207,7 +207,7 @@ Phaser.Pointer.prototype = { } // Fix to stop rogue browser plugins from blocking the visibility state event - if (this.game.stage.disableVisibilityChange === false && this.game.paused && this.game.stage.scale.incorrectOrientation === false) + if (this.game.stage.disableVisibilityChange === false && this.game.paused && this.game.scale.incorrectOrientation === false) { this.game.paused = false; return this; diff --git a/src/system/StageScaleMode.js b/src/system/StageScaleMode.js index 9fe8b7be..ab1f7ebf 100644 --- a/src/system/StageScaleMode.js +++ b/src/system/StageScaleMode.js @@ -32,37 +32,24 @@ Phaser.StageScaleMode = function (game, width, height) { /** * @property {number} minWidth - Minimum width the canvas should be scaled to (in pixels). - * @default */ this.minWidth = null; /** - * @property {number} maxWidth - Maximum width the canvas should be scaled to (in pixels). - * If null it will scale to whatever width the browser can handle. - * @default + * @property {number} maxWidth - Maximum width the canvas should be scaled to (in pixels). If null it will scale to whatever width the browser can handle. */ this.maxWidth = null; /** * @property {number} minHeight - Minimum height the canvas should be scaled to (in pixels). - * @default */ this.minHeight = null; /** - * @property {number} maxHeight - Maximum height the canvas should be scaled to (in pixels). - * If null it will scale to whatever height the browser can handle. - * @default + * @property {number} maxHeight - Maximum height the canvas should be scaled to (in pixels). If null it will scale to whatever height the browser can handle. */ this.maxHeight = null; - /** - * @property {number} _startHeight - Stage height when starting the game. - * @default - * @private - */ - this._startHeight = 0; - /** * @property {boolean} forceLandscape - If the game should be forced to use Landscape mode, this is set to true by Game.Stage * @default @@ -97,20 +84,6 @@ Phaser.StageScaleMode = function (game, width, height) { */ this.pageAlignVertically = false; - /** - * @property {number} _width - Cached stage width for full screen mode. - * @default - * @private - */ - this._width = 0; - - /** - * @property {number} _height - Cached stage height for full screen mode. - * @default - * @private - */ - this._height = 0; - /** * @property {number} maxIterations - The maximum number of times it will try to resize the canvas to fill the browser. * @default @@ -119,7 +92,6 @@ Phaser.StageScaleMode = function (game, width, height) { /** * @property {PIXI.Sprite} orientationSprite - The Sprite that is optionally displayed if the browser enters an unsupported orientation. - * @default */ this.orientationSprite = null; @@ -148,6 +120,11 @@ Phaser.StageScaleMode = function (game, width, height) { */ this.hasResized = new Phaser.Signal(); + /** + * @property {number} orientation - The orientation value of the game (as defined by window.orientation if set). 90 = landscape. 0 = portrait. + */ + this.orientation = 0; + if (window['orientation']) { this.orientation = window['orientation']; @@ -158,10 +135,6 @@ Phaser.StageScaleMode = function (game, width, height) { { this.orientation = 90; } - else - { - this.orientation = 0; - } } /** @@ -183,16 +156,50 @@ Phaser.StageScaleMode = function (game, width, height) { this.margin = new Phaser.Point(0, 0); /** - * @property {number} aspectRatio - Aspect ratio. - * @default + * @property {number} aspectRatio - The aspect ratio of the scaled game. + * @readonly */ this.aspectRatio = 0; + /** + * @property {number} sourceAspectRatio - The aspect ratio (width / height) of the original game dimensions. + * @readonly + */ + this.sourceAspectRatio = width / height; + /** * @property {any} event- The native browser events from full screen API changes. */ this.event = null; + /** + * @property {number} scaleMode - The current scaleMode. + */ + this.scaleMode = Phaser.StageScaleMode.NO_SCALE; + + /* + * @property {number} fullScreenScaleMode - Scale mode to be used in fullScreen + */ + this.fullScreenScaleMode = Phaser.StageScaleMode.NO_SCALE; + + /** + * @property {number} _startHeight - Internal cache var. Stage height when starting the game. + * @private + */ + this._startHeight = 0; + + /** + * @property {number} _width - Cached stage width for full screen mode. + * @private + */ + this._width = 0; + + /** + * @property {number} _height - Cached stage height for full screen mode. + * @private + */ + this._height = 0; + var _this = this; window.addEventListener('orientationchange', function (event) { @@ -311,7 +318,7 @@ Phaser.StageScaleMode.prototype = { if (this.isFullScreen) { - if (this.game.stage.fullScreenScaleMode === Phaser.StageScaleMode.EXACT_FIT) + if (this.fullScreenScaleMode === Phaser.StageScaleMode.EXACT_FIT) { this.game.stage.canvas.style['width'] = '100%'; this.game.stage.canvas.style['height'] = '100%'; @@ -324,10 +331,10 @@ Phaser.StageScaleMode.prototype = { this.scaleFactor.x = this.game.width / this.width; this.scaleFactor.y = this.game.height / this.height; } - else if (this.game.stage.fullScreenScaleMode === Phaser.StageScaleMode.SHOW_ALL) + else if (this.fullScreenScaleMode === Phaser.StageScaleMode.SHOW_ALL) { - this.game.stage.scale.setShowAll(); - this.game.stage.scale.refresh(); + this.setShowAll(); + this.refresh(); } } else @@ -458,7 +465,7 @@ Phaser.StageScaleMode.prototype = { this.enterPortrait.dispatch(this.orientation, false, true); } - if (this.game.stage.scaleMode !== Phaser.StageScaleMode.NO_SCALE) + if (this.scaleMode !== Phaser.StageScaleMode.NO_SCALE) { this.refresh(); } @@ -492,7 +499,7 @@ Phaser.StageScaleMode.prototype = { this.enterPortrait.dispatch(this.orientation, false, true); } - if (this.game.stage.scaleMode !== Phaser.StageScaleMode.NO_SCALE) + if (this.scaleMode !== Phaser.StageScaleMode.NO_SCALE) { this.refresh(); } @@ -571,22 +578,22 @@ Phaser.StageScaleMode.prototype = { } else if (!this.isFullScreen) { - if (this.game.stage.scaleMode == Phaser.StageScaleMode.EXACT_FIT) + if (this.scaleMode == Phaser.StageScaleMode.EXACT_FIT) { this.setExactFit(); } - else if (this.game.stage.scaleMode == Phaser.StageScaleMode.SHOW_ALL) + else if (this.scaleMode == Phaser.StageScaleMode.SHOW_ALL) { this.setShowAll(); } } else { - if (this.game.stage.fullScreenScaleMode == Phaser.StageScaleMode.EXACT_FIT) + if (this.fullScreenScaleMode == Phaser.StageScaleMode.EXACT_FIT) { this.setExactFit(); } - else if (this.game.stage.fullScreenScaleMode == Phaser.StageScaleMode.SHOW_ALL) + else if (this.fullScreenScaleMode == Phaser.StageScaleMode.SHOW_ALL) { this.setShowAll(); }