Skip to content

Commit 2cc8e57

Browse files
committed
Fixed issue with the ScaleManager.
1 parent b389b73 commit 2cc8e57

2 files changed

Lines changed: 62 additions & 45 deletions

File tree

src/core/Game.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,6 @@ Phaser.Game.prototype = {
448448
this.math = Phaser.Math;
449449

450450
this.scale = new Phaser.ScaleManager(this, this._width, this._height);
451-
452-
// this.stage = new Phaser.Stage(this, this.width, this.height);
453451
this.stage = new Phaser.Stage(this);
454452

455453
this.setUpRenderer();
@@ -473,6 +471,7 @@ Phaser.Game.prototype = {
473471
this.time.boot();
474472
this.stage.boot();
475473
this.world.boot();
474+
this.scale.boot();
476475
this.input.boot();
477476
this.sound.boot();
478477
this.state.boot();

src/core/ScaleManager.js

Lines changed: 61 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
* @class Phaser.ScaleManager
1111
* @constructor
1212
* @param {Phaser.Game} game - A reference to the currently running game.
13-
* @param {number} width - The native width of the game.
14-
* @param {number} height - The native height of the game.
13+
* @param {number|string} width - The width of the game.
14+
* @param {number|string} height - The height of the game.
1515
*/
1616
Phaser.ScaleManager = function (game, width, height) {
1717

@@ -21,12 +21,12 @@ Phaser.ScaleManager = function (game, width, height) {
2121
this.game = game;
2222

2323
/**
24-
* @property {number} width - Width of the stage after calculation.
24+
* @property {number} width - Width of the game after calculation.
2525
*/
2626
this.width = 0;
2727

2828
/**
29-
* @property {number} height - Height of the stage after calculation.
29+
* @property {number} height - Height of the game after calculation.
3030
*/
3131
this.height = 0;
3232

@@ -218,7 +218,7 @@ Phaser.ScaleManager = function (game, width, height) {
218218
* @property {number} trackParentInterval - The interval (in ms) upon which the ScaleManager checks if the parent has changed dimensions. Only applies if scaleMode = RESIZE and the game is contained within another html element.
219219
* @default
220220
*/
221-
this.trackParentInterval = 50;
221+
this.trackParentInterval = 2000;
222222

223223
/**
224224
* @property {function} onResize - The callback that will be called each time a window.resize event happens or if set, the parent container resizes.
@@ -239,13 +239,13 @@ Phaser.ScaleManager = function (game, width, height) {
239239
this._scaleMode = Phaser.ScaleManager.NO_SCALE;
240240

241241
/**
242-
* @property {number} _width - Cached stage width for full screen mode.
242+
* @property {number} _width - Cached game width for full screen mode.
243243
* @private
244244
*/
245245
this._width = 0;
246246

247247
/**
248-
* @property {number} _height - Cached stage height for full screen mode.
248+
* @property {number} _height - Cached game height for full screen mode.
249249
* @private
250250
*/
251251
this._height = 0;
@@ -273,31 +273,7 @@ Phaser.ScaleManager = function (game, width, height) {
273273
this.parseConfig(game.config);
274274
}
275275

276-
var _this = this;
277-
278-
this._checkOrientation = function(event) {
279-
return _this.checkOrientation(event);
280-
};
281-
282-
this._checkResize = function(event) {
283-
return _this.checkResize(event);
284-
};
285-
286-
this._fullScreenChange = function(event) {
287-
return _this.fullScreenChange(event);
288-
};
289-
290-
window.addEventListener('orientationchange', this._checkOrientation, false);
291-
window.addEventListener('resize', this._checkResize, false);
292-
293-
if (!this.game.device.cocoonJS)
294-
{
295-
document.addEventListener('webkitfullscreenchange', this._fullScreenChange, false);
296-
document.addEventListener('mozfullscreenchange', this._fullScreenChange, false);
297-
document.addEventListener('fullscreenchange', this._fullScreenChange, false);
298-
}
299-
300-
this.boot(width, height);
276+
this.setupScale(width, height);
301277

302278
};
303279

@@ -355,11 +331,11 @@ Phaser.ScaleManager.prototype = {
355331
/**
356332
* Calculates and sets the game dimensions based on the given width and height.
357333
*
358-
* @method Phaser.ScaleManager#boot
334+
* @method Phaser.ScaleManager#setupScale
359335
* @param {number|string} width - The width of the game.
360336
* @param {number|string} height - The height of the game.
361337
*/
362-
boot: function (width, height) {
338+
setupScale: function (width, height) {
363339

364340
var target;
365341
var rect = new Phaser.Rectangle();
@@ -393,8 +369,12 @@ Phaser.ScaleManager.prototype = {
393369
this.parentNode = target;
394370
this.parentIsWindow = false;
395371

396-
rect.width = target.getBoundingClientRect().width;
397-
rect.height = target.getBoundingClientRect().height;
372+
this._parentBounds = this.parentNode.getBoundingClientRect();
373+
374+
rect.width = this._parentBounds.width;
375+
rect.height = this._parentBounds.height;
376+
377+
this.offset.set(this._parentBounds.left, this._parentBounds.top);
398378
}
399379

400380
var newWidth = 0;
@@ -426,6 +406,45 @@ Phaser.ScaleManager.prototype = {
426406

427407
},
428408

409+
/**
410+
* Calculates and sets the game dimensions based on the given width and height.
411+
*
412+
* @method Phaser.ScaleManager#boot
413+
*/
414+
boot: function () {
415+
416+
var _this = this;
417+
418+
this._checkOrientation = function(event) {
419+
return _this.checkOrientation(event);
420+
};
421+
422+
this._checkResize = function(event) {
423+
return _this.checkResize(event);
424+
};
425+
426+
this._fullScreenChange = function(event) {
427+
return _this.fullScreenChange(event);
428+
};
429+
430+
window.addEventListener('orientationchange', this._checkOrientation, false);
431+
window.addEventListener('resize', this._checkResize, false);
432+
433+
if (!this.game.device.cocoonJS)
434+
{
435+
document.addEventListener('webkitfullscreenchange', this._fullScreenChange, false);
436+
document.addEventListener('mozfullscreenchange', this._fullScreenChange, false);
437+
document.addEventListener('fullscreenchange', this._fullScreenChange, false);
438+
}
439+
440+
this.updateDimensions(this.width, this.height, true);
441+
442+
Phaser.Canvas.getOffset(this.game.canvas, this.offset);
443+
444+
this.bounds.setTo(this.offset.x, this.offset.y, this.width, this.height);
445+
446+
},
447+
429448
/**
430449
* Sets the callback that will be called when the window resize event occurs, or if set the parent container changes dimensions.
431450
* Use this to handle responsive game layout options.
@@ -483,13 +502,13 @@ Phaser.ScaleManager.prototype = {
483502

484503
if (!this.parentIsWindow)
485504
{
486-
this._parentBounds = this.parentNode.getBoundingClientRect();
487-
488-
// Faster to just set the new values here than double-compare them to the old ones
489-
this.offset.set(this._parentBounds.left, this._parentBounds.top);
505+
Phaser.Canvas.getOffset(this.game.canvas, this.offset);
490506

507+
491508
if (this._scaleMode === Phaser.ScaleManager.RESIZE)
492509
{
510+
this._parentBounds = this.parentNode.getBoundingClientRect();
511+
493512
if (this._parentBounds.width !== this.width || this._parentBounds.height !== this.height)
494513
{
495514
// The parent has changed size, so we need to adapt
@@ -854,9 +873,8 @@ Phaser.ScaleManager.prototype = {
854873
}
855874
}
856875

857-
Phaser.Canvas.getOffset(this.game.canvas, this.game.stage.offset);
858-
859-
this.bounds.setTo(this.game.stage.offset.x, this.game.stage.offset.y, this.width, this.height);
876+
Phaser.Canvas.getOffset(this.game.canvas, this.offset);
877+
this.bounds.setTo(this.offset.x, this.offset.y, this.width, this.height);
860878

861879
this.aspectRatio = this.width / this.height;
862880

0 commit comments

Comments
 (0)