ScaleManager window.resize handler would constantly dispatch enterPortrait and enterLandscape events on window resizing, regardless if it actually entered that orientation or not.

Stage.offset has been moved to ScaleManager.offset
Stage.bounds has been removed, you can access it via Stage.getBounds.
Stage.checkOffsetInterval has been moved to ScaleManager.trackParentInterval
ScaleManager.hasResized signal has been removed. Use ScaleManager.setResizeCallback instead.
This commit is contained in:
photonstorm 2014-09-01 01:02:41 +01:00
parent b08bfec372
commit 5fb8c7eb85
7 changed files with 398 additions and 275 deletions

View file

@ -125,6 +125,10 @@ Version 2.1.0 - "Cairhien" - -in development-
* If Time.elapsed was > Time.timeCap it would reset the elapsed value to be 1 / 60. It's now set to Time.timeCap and Time.timeCap defaults to `1 / 60 * 1000` as it's a ms value (thanks @casensiom #899)
* Tiled polylines are now imported into the map objects property as well as map collision (#1117)
* Tile.setCollision now adjusts the tiles interesting faces list as well, this allows you to create one-way jump tiles without using custom callbacks on a specific tile basis (thanks @RafaelOliveira #886)
* Stage.offset has been moved to ScaleManager.offset
* Stage.bounds has been removed, you can access it via Stage.getBounds.
* Stage.checkOffsetInterval has been moved to ScaleManager.trackParentInterval
* ScaleManager.hasResized signal has been removed. Use ScaleManager.setResizeCallback instead.
### Bug Fixes
@ -155,6 +159,7 @@ Version 2.1.0 - "Cairhien" - -in development-
* GamepadButton.justPressed and justReleased now correctly report if the button has just been pressed or released (thanks @padpadpad #1019)
* TilemapParser.getEmptyData now correct adds an empty bodies array into layers. This fixes an issue where p2 couldn't convert a csv map into collision tiles (thanks @sru #845)
* CocoonJS doesn't support mouse wheel events so they've been moved into a conditional check (thanks @videlais #1151)
* ScaleManager window.resize handler would constantly dispatch enterPortrait and enterLandscape events on window resizing, regardless if it actually entered that orientation or not.
### p2.js 0.6.0 Changes and New Features

View file

@ -656,9 +656,11 @@ Phaser.Game.prototype = {
this.pendingStep = true;
}
this.scale.preUpdate();
if (this.config['enableDebug'])
{
this.debug.preUpdate();
// this.debug.preUpdate();
}
this.physics.preUpdate();
@ -684,7 +686,7 @@ Phaser.Game.prototype = {
if (this.config['enableDebug'])
{
this.debug.preUpdate();
// this.debug.preUpdate();
}
}

View file

@ -56,26 +56,26 @@ Phaser.ScaleManager = function (game, width, height) {
this.offset = new Phaser.Point();
/**
* @property {boolean} forceLandscape - If the game should be forced to use Landscape mode, this is set to true by Game.Stage
* @property {boolean} forceLandscape - Set to `true` if the game should only run in a landscape orientation.
* @default
*/
this.forceLandscape = false;
/**
* @property {boolean} forcePortrait - If the game should be forced to use Portrait mode, this is set to true by Game.Stage
* @property {boolean} forcePortrait - Set to `true` if the game should only run in a portrait orientation.
* @default
*/
this.forcePortrait = false;
/**
* @property {boolean} incorrectOrientation - If the game should be forced to use a specific orientation and the device currently isn't in that orientation this is set to true.
* @property {boolean} incorrectOrientation - If `forceLandscape` or `forcePortrait` are true and the browser doesn't match that orientation this is set to `true`.
* @default
*/
this.incorrectOrientation = false;
/**
* @property {boolean} pageAlignHorizontally - If you wish to align your game in the middle of the page then you can set this value to true.
* It will place a re-calculated margin-left pixel value onto the canvas element which is updated on orientation/resizing.
* It will place a re-calculated margin-left pixel value onto the canvas element which is updated on orientation/resizing events.
* It doesn't care about any other DOM element that may be on the page, it literally just sets the margin.
* @default
*/
@ -83,7 +83,7 @@ Phaser.ScaleManager = function (game, width, height) {
/**
* @property {boolean} pageAlignVertically - If you wish to align your game in the middle of the page then you can set this value to true.
* It will place a re-calculated margin-left pixel value onto the canvas element which is updated on orientation/resizing.
* It will place a re-calculated margin-left pixel value onto the canvas element which is updated on orientation/resizing events.
* It doesn't care about any other DOM element that may be on the page, it literally just sets the margin.
* @default
*/
@ -101,12 +101,12 @@ Phaser.ScaleManager = function (game, width, height) {
this.orientationSprite = null;
/**
* @property {Phaser.Signal} enterLandscape - The event that is dispatched when the browser enters landscape orientation.
* @property {Phaser.Signal} enterLandscape - The event that is dispatched when the browser enters landscape orientation having been in portrait.
*/
this.enterLandscape = new Phaser.Signal();
/**
* @property {Phaser.Signal} enterPortrait - The event that is dispatched when the browser enters horizontal orientation.
* @property {Phaser.Signal} enterPortrait - The event that is dispatched when the browser enters portrait orientation having been in landscape.
*/
this.enterPortrait = new Phaser.Signal();
@ -120,11 +120,6 @@ Phaser.ScaleManager = function (game, width, height) {
*/
this.leaveIncorrectOrientation = new Phaser.Signal();
/**
* @property {Phaser.Signal} hasResized - The event that is dispatched when the game scale changes.
*/
this.hasResized = new Phaser.Signal();
/**
* This is the DOM element that will have the Full Screen mode called on it. It defaults to the game canvas, but can be retargetted to any valid DOM element.
* If you adjust this property it's up to you to see it has the correct CSS applied, and that you have contained the game canvas correctly.
@ -228,7 +223,19 @@ Phaser.ScaleManager = function (game, width, height) {
* @property {number} trackParentInterval - The interval (in ms) upon which the ScaleManager checks if the parent has changed dimensions. Only applies if scaleMode = RESIZE and the game is contained within another html element.
* @default
*/
this.trackParentInterval = 2500;
this.trackParentInterval = 50;
/**
* @property {function} onResize - The callback that will be called each time a window.resize event happens or if set, the parent container resizes.
* @default
*/
this.onResize = null;
/**
* @property {object} onResizeContext - The context in which the callback will be called.
* @default
*/
this.onResizeContext = null;
/**
* @property {number} scaleMode - The current scaling method being used.
@ -266,6 +273,17 @@ Phaser.ScaleManager = function (game, width, height) {
*/
this._nextParentCheck = 0;
/**
* @property {object} _parentBounds - The cached result of getBoundingClientRect from the parent.
* @private
*/
this._parentBounds = null;
if (game.config)
{
this.parseConfig(game.config);
}
var _this = this;
this._checkOrientation = function(event) {
@ -290,7 +308,7 @@ Phaser.ScaleManager = function (game, width, height) {
document.addEventListener('fullscreenchange', this._fullScreenChange, false);
}
this.calculateDimensions(width, height);
this.boot(width, height);
};
@ -316,30 +334,31 @@ Phaser.ScaleManager.SHOW_ALL = 2;
* @constant
* @type {number}
*/
Phaser.ScaleManager.RESIZE_CANVAS = 3;
Phaser.ScaleManager.RESIZE = 3;
Phaser.ScaleManager.prototype = {
update: function () {
/**
* Parses the Game configuration object.
*
* @method Phaser.ScaleManager#parseConfig
* @param {object} config - The game configuration object.
*/
parseConfig: function (config) {
if (this._scaleMode === Phaser.ScaleManager.RESIZE_CANVAS && this.parentIsWindow === false && this.game.time.now > this._nextParentCheck)
if (config['scaleMode'])
{
var bounds = this.parentNode.getBoundingClientRect();
this.scaleMode = config['scaleMode'];
}
if (bounds.left !== this.offset.x || bounds.top !== this.offset.y)
{
// The parent has changed position (but maybe not size), we need to update regardless
// Update the Stage bounds, otherwise the Input tracking fails OR we just adjust Pointer#408 to check here instead of the Stage
this.offset.set(bounds.left, bounds.top);
}
if (config['fullScreenScaleMode'])
{
this.fullScreenScaleMode = config['fullScreenScaleMode'];
}
if (bounds.width !== this.width || bounds.height !== this.height)
{
// The parent has changed size, so we need to adapt
this.updateDimensions(bounds.width, bounds.height);
}
this._nextParentCheck = this.game.time.now + this.trackParentInterval;
if (config['fullScreenTarget'])
{
this.fullScreenTarget = config['fullScreenTarget'];
}
},
@ -347,13 +366,13 @@ Phaser.ScaleManager.prototype = {
/**
* Calculates and sets the game dimensions based on the given width and height.
*
* @method Phaser.ScaleManager#calculateDimensions
* @method Phaser.ScaleManager#boot
* @param {number|string} width - The width of the game.
* @param {number|string} height - The height of the game.
*/
calculateDimensions: function (width, height) {
boot: function (width, height) {
console.log('ScaleManager calculateDimensions');
console.log('ScaleManager boot');
console.log('parent', this.game.parent);
var target;
@ -427,14 +446,67 @@ Phaser.ScaleManager.prototype = {
console.log(rect);
console.log('source', width, height);
this.updateDimensions(newWidth, newHeight);
this.updateDimensions(newWidth, newHeight, false);
},
updateDimensions: function (newWidth, newHeight) {
/**
* Sets the callback that will be called when the window resize event occurs, or if set the parent container changes dimensions.
* Use this to handle responsive game layout options.
* Note that the callback will only be called if the ScaleManager.scaleMode is set to RESIZE.
*
* @method Phaser.ScaleManager#setResizeCallback
* @param {function} callback - The callback that will be called each time a window.resize event happens or if set, the parent container resizes.
* @param {object} context - The context in which the callback will be called.
*/
setResizeCallback: function (callback, context) {
this.width = newWidth * this.parentScaleFactor.x;
this.height = newHeight * this.parentScaleFactor.y;
this.onResize = callback;
this.onResizeContext = context;
},
/**
* The ScaleManager.preUpdate is called automatically by the core Game loop.
*
* @method Phaser.ScaleManager#preUpdate
* @protected
*/
preUpdate: function () {
if (this._scaleMode === Phaser.ScaleManager.RESIZE && this.parentIsWindow === false && this.game.time.now > this._nextParentCheck)
{
this._parentBounds = this.parentNode.getBoundingClientRect();
if (this._parentBounds.left !== this.offset.x || this._parentBounds.top !== this.offset.y)
{
// The parent has changed position (but maybe not size), we need to update regardless
this.offset.set(this._parentBounds.left, this._parentBounds.top);
}
if (this._parentBounds.width !== this.width || this._parentBounds.height !== this.height)
{
// The parent has changed size, so we need to adapt
this.updateDimensions(this._parentBounds.width, this._parentBounds.height, true);
}
this._nextParentCheck = this.game.time.now + this.trackParentInterval;
}
},
/**
* Called automatically when the game parent dimensions change.
*
* @method updateDimensions
* @param {number} width - The new width of the parent container.
* @param {number} height - The new height of the parent container.
* @param {boolean} resize - True if the renderer should be resized, otherwise false to just update the internal vars.
*/
updateDimensions: function (width, height, resize) {
this.width = width * this.parentScaleFactor.x;
this.height = height * this.parentScaleFactor.y;
this.game.width = this.width;
this.game.height = this.height;
@ -444,103 +516,20 @@ Phaser.ScaleManager.prototype = {
this.bounds.width = this.width;
this.bounds.height = this.height;
console.log('updateDimensions', this.width, this.height);
},
/**
* Tries to enter the browser into full screen mode.
* Please note that this needs to be supported by the web browser and isn't the same thing as setting your game to fill the browser.
* @method Phaser.ScaleManager#startFullScreen
* @param {boolean} antialias - You can toggle the anti-alias feature of the canvas before jumping in to full screen (false = retain pixel art, true = smooth art)
*/
startFullScreen: function (antialias) {
if (this.isFullScreen || !this.game.device.fullscreen)
if (resize)
{
return;
this.game.renderer.resize(this.width, this.height);
// The Camera can never be smaller than the game size
this.game.camera.setSize(this.width, this.height);
// This should only happen if the world is smaller than the new canvas size
this.game.world.resize(this.width, this.height);
}
if (typeof antialias !== 'undefined' && this.game.renderType === Phaser.CANVAS)
if (this.onResize)
{
this.game.stage.smoothed = antialias;
}
this._width = this.width;
this._height = this.height;
if (this.game.device.fullscreenKeyboard)
{
this.fullScreenTarget[this.game.device.requestFullscreen](Element.ALLOW_KEYBOARD_INPUT);
}
else
{
this.fullScreenTarget[this.game.device.requestFullscreen]();
}
},
/**
* Stops full screen mode if the browser is in it.
* @method Phaser.ScaleManager#stopFullScreen
*/
stopFullScreen: function () {
document[this.game.device.cancelFullscreen]();
},
/**
* Called automatically when the browser enters of leaves full screen mode.
* @method Phaser.ScaleManager#fullScreenChange
* @param {Event} event - The fullscreenchange event
* @protected
*/
fullScreenChange: function (event) {
this.event = event;
if (this.isFullScreen)
{
if (this.fullScreenScaleMode === Phaser.ScaleManager.EXACT_FIT)
{
this.fullScreenTarget.style['width'] = '100%';
this.fullScreenTarget.style['height'] = '100%';
this.width = window.outerWidth;
this.height = window.outerHeight;
this.game.input.scale.setTo(this.game.width / this.width, this.game.height / this.height);
this.aspectRatio = this.width / this.height;
this.scaleFactor.x = this.game.width / this.width;
this.scaleFactor.y = this.game.height / this.height;
this.checkResize();
}
else if (this.fullScreenScaleMode === Phaser.ScaleManager.SHOW_ALL)
{
this.setShowAll();
this.refresh();
}
this.enterFullScreen.dispatch(this.width, this.height);
}
else
{
this.fullScreenTarget.style['width'] = this.game.width + 'px';
this.fullScreenTarget.style['height'] = this.game.height + 'px';
this.width = this._width;
this.height = this._height;
this.game.input.scale.setTo(this.game.width / this.width, this.game.height / this.height);
this.aspectRatio = this.width / this.height;
this.scaleFactor.x = this.game.width / this.width;
this.scaleFactor.y = this.game.height / this.height;
this.leaveFullScreen.dispatch(this.width, this.height);
this.onResize.call(this.onResizeContext, this.width, this.height);
}
},
@ -638,7 +627,8 @@ Phaser.ScaleManager.prototype = {
},
/**
* Handle window.orientationchange events
* window.orientationchange event handler.
*
* @method Phaser.ScaleManager#checkOrientation
* @param {Event} event - The orientationchange event data.
*/
@ -665,7 +655,8 @@ Phaser.ScaleManager.prototype = {
},
/**
* Handle window.resize events
* window.resize event handler.
*
* @method Phaser.ScaleManager#checkResize
* @param {Event} event - The resize event data.
*/
@ -673,6 +664,8 @@ Phaser.ScaleManager.prototype = {
this.event = event;
var wasLandscape = this.isLandscape;
if (window.outerWidth > window.outerHeight)
{
this.orientation = 90;
@ -682,26 +675,56 @@ Phaser.ScaleManager.prototype = {
this.orientation = 0;
}
if (this.isLandscape)
{
this.enterLandscape.dispatch(this.orientation, true, false);
}
else
// If it WAS in Landscape but is now in portrait ...
if (wasLandscape && this.isPortrait)
{
this.enterPortrait.dispatch(this.orientation, false, true);
if (this.forceLandscape)
{
this.enterIncorrectOrientation.dispatch();
}
else if (this.forcePortrait)
{
this.leaveIncorrectOrientation.dispatch();
}
}
else if (!wasLandscape && this.isLandscape)
{
// 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();
}
}
if (this.scaleMode !== Phaser.ScaleManager.NO_SCALE)
if (this._scaleMode === Phaser.ScaleManager.RESIZE && this.parentIsWindow)
{
// The window has changed size, so we need to adapt
this.updateDimensions(window.innerWidth, window.innerHeight, true);
}
else if (this._scaleMode === Phaser.ScaleManager.EXACT_FIT || this._scaleMode === Phaser.ScaleManager.SHOW_ALL)
{
this.refresh();
this.checkOrientationState();
if (this.onResize)
{
this.onResize.call(this.onResizeContext, this.width, this.height);
}
}
this.checkOrientationState();
},
/**
* Re-calculate scale mode and update screen size.
*
* @method Phaser.ScaleManager#refresh
*/
refresh: function () {
@ -739,6 +762,7 @@ Phaser.ScaleManager.prototype = {
/**
* Set screen size automatically based on the scaleMode.
*
* @param {boolean} force - If force is true it will try to resize the game regardless of the document dimensions.
*/
setScreenSize: function (force) {
@ -803,6 +827,7 @@ Phaser.ScaleManager.prototype = {
/**
* Sets the canvas style width and height values based on minWidth/Height and maxWidth/Height.
*
* @method Phaser.ScaleManager#setSize
*/
setSize: function () {
@ -875,14 +900,13 @@ Phaser.ScaleManager.prototype = {
this.scaleFactorInversed.x = this.width / this.game.width;
this.scaleFactorInversed.y = this.height / this.game.height;
this.hasResized.dispatch(this.width, this.height);
this.checkOrientationState();
},
/**
* Sets this.width equal to window.innerWidth and this.height equal to window.innerHeight
* Sets this.width equal to window.innerWidth and this.height equal to window.innerHeight.
*
* @method Phaser.ScaleManager#setMaximum
*/
setMaximum: function () {
@ -894,6 +918,7 @@ Phaser.ScaleManager.prototype = {
/**
* Calculates the multiplier needed to scale the game proportionally.
*
* @method Phaser.ScaleManager#setShowAll
*/
setShowAll: function () {
@ -907,6 +932,7 @@ Phaser.ScaleManager.prototype = {
/**
* Sets the width and height values of the canvas, no larger than the maxWidth/Height.
*
* @method Phaser.ScaleManager#setExactFit
*/
setExactFit: function () {
@ -934,6 +960,104 @@ Phaser.ScaleManager.prototype = {
},
/**
* Tries to enter the browser into full screen mode.
* Please note that this needs to be supported by the web browser and isn't the same thing as setting your game to fill the browser.
*
* @method Phaser.ScaleManager#startFullScreen
* @param {boolean} antialias - You can toggle the anti-alias feature of the canvas before jumping in to full screen (false = retain pixel art, true = smooth art)
*/
startFullScreen: function (antialias) {
if (this.isFullScreen || !this.game.device.fullscreen)
{
return;
}
if (typeof antialias !== 'undefined' && this.game.renderType === Phaser.CANVAS)
{
this.game.stage.smoothed = antialias;
}
this._width = this.width;
this._height = this.height;
if (this.game.device.fullscreenKeyboard)
{
this.fullScreenTarget[this.game.device.requestFullscreen](Element.ALLOW_KEYBOARD_INPUT);
}
else
{
this.fullScreenTarget[this.game.device.requestFullscreen]();
}
},
/**
* Stops full screen mode if the browser is in it.
* @method Phaser.ScaleManager#stopFullScreen
*/
stopFullScreen: function () {
document[this.game.device.cancelFullscreen]();
},
/**
* Called automatically when the browser enters of leaves full screen mode.
* @method Phaser.ScaleManager#fullScreenChange
* @param {Event} event - The fullscreenchange event
* @protected
*/
fullScreenChange: function (event) {
this.event = event;
if (this.isFullScreen)
{
if (this.fullScreenScaleMode === Phaser.ScaleManager.EXACT_FIT)
{
this.fullScreenTarget.style['width'] = '100%';
this.fullScreenTarget.style['height'] = '100%';
this.width = window.outerWidth;
this.height = window.outerHeight;
this.game.input.scale.setTo(this.game.width / this.width, this.game.height / this.height);
this.aspectRatio = this.width / this.height;
this.scaleFactor.x = this.game.width / this.width;
this.scaleFactor.y = this.game.height / this.height;
this.checkResize();
}
else if (this.fullScreenScaleMode === Phaser.ScaleManager.SHOW_ALL)
{
this.setShowAll();
this.refresh();
}
this.enterFullScreen.dispatch(this.width, this.height);
}
else
{
this.fullScreenTarget.style['width'] = this.game.width + 'px';
this.fullScreenTarget.style['height'] = this.game.height + 'px';
this.width = this._width;
this.height = this._height;
this.game.input.scale.setTo(this.game.width / this.width, this.game.height / this.height);
this.aspectRatio = this.width / this.height;
this.scaleFactor.x = this.game.width / this.width;
this.scaleFactor.y = this.game.height / this.height;
this.leaveFullScreen.dispatch(this.width, this.height);
}
},
/**
* Destroys the ScaleManager and removes any event listeners.
*
@ -973,13 +1097,7 @@ Object.defineProperty(Phaser.ScaleManager.prototype, "scaleMode", {
if (value !== this._scaleMode)
{
console.log('new scale mode set', value);
this._scaleMode = value;
// Do stuff here like set-up tracking, etc
}
}
@ -994,9 +1112,7 @@ Object.defineProperty(Phaser.ScaleManager.prototype, "scaleMode", {
Object.defineProperty(Phaser.ScaleManager.prototype, "isFullScreen", {
get: function () {
return (document['fullscreenElement'] || document['mozFullScreenElement'] || document['webkitFullscreenElement']);
}
});

View file

@ -5,8 +5,8 @@
*/
/**
* The Stage controls the canvas on which everything is displayed. It handles display within the browser,
* focus handling, game resizing, scaling and the pause, boot and orientation screens.
* The Stage controls root level display objects upon which everything is displayed.
* It also handles browser visibility handling and the pausing due to loss of focus.
*
* @class Phaser.Stage
* @extends PIXI.Stage
@ -20,17 +20,6 @@ Phaser.Stage = function (game) {
*/
this.game = game;
/**
* @deprecated
* @property {Phaser.Point} offset - Holds the offset coordinates of the Game.canvas from the top-left of the browser window (used by Input and other classes)
*/
this.offset = new Phaser.Point();
/**
* @property {Phaser.Rectangle} bounds - The bounds of the Stage. Typically x/y = Stage.offset.x/y and the width/height match the game width and height.
*/
this.bounds = new Phaser.Rectangle(0, 0, this.game.width, this.game.height);
PIXI.Stage.call(this, 0x000000);
/**
@ -52,12 +41,6 @@ Phaser.Stage = function (game) {
*/
this.disableVisibilityChange = false;
/**
* @property {number|false} checkOffsetInterval - The time (in ms) between which the stage should check to see if it has moved.
* @default
*/
this.checkOffsetInterval = 2500;
/**
* @property {boolean} exists - If exists is true the Stage and all children are updated, otherwise it is skipped.
* @default
@ -75,12 +58,6 @@ Phaser.Stage = function (game) {
*/
this._hiddenVar = 'hidden';
/**
* @property {number} _nextOffsetCheck - The time to run the next offset check.
* @private
*/
this._nextOffsetCheck = 0;
/**
* @property {number} _backgroundColor - Stage background color.
* @private
@ -97,6 +74,49 @@ Phaser.Stage = function (game) {
Phaser.Stage.prototype = Object.create(PIXI.Stage.prototype);
Phaser.Stage.prototype.constructor = Phaser.Stage;
/**
* Parses a Game configuration object.
*
* @method Phaser.Stage#parseConfig
* @protected
* @param {object} config -The configuration object to parse.
*/
Phaser.Stage.prototype.parseConfig = function (config) {
if (config['disableVisibilityChange'])
{
this.disableVisibilityChange = config['disableVisibilityChange'];
}
if (config['backgroundColor'])
{
this.backgroundColor = config['backgroundColor'];
}
};
/**
* Initialises the stage and adds the event listeners.
* @method Phaser.Stage#boot
* @private
*/
Phaser.Stage.prototype.boot = function () {
Phaser.Canvas.getOffset(this.game.canvas, this.offset);
var _this = this;
this._onChange = function (event) {
return _this.visibilityChange(event);
};
Phaser.Canvas.setUserSelect(this.game.canvas, 'none');
Phaser.Canvas.setTouchAction(this.game.canvas, 'none');
this.checkVisibility();
};
/**
* This is called automatically after the plugins preUpdate and before the State.update.
* Most objects have preUpdate methods and it's where initial movement and positioning is done.
@ -105,20 +125,6 @@ Phaser.Stage.prototype.constructor = Phaser.Stage;
*/
Phaser.Stage.prototype.preUpdate = function () {
// Consider moving all of this into the ScaleManager
/*
if (this.checkOffsetInterval !== false)
{
if (this.game.time.now > this._nextOffsetCheck)
{
Phaser.Canvas.getOffset(this.game.canvas, this.offset);
this.bounds.x = this.offset.x;
this.bounds.y = this.offset.y;
this._nextOffsetCheck = this.game.time.now + this.checkOffsetInterval;
}
}
*/
this.currentRenderOrderID = 0;
// This can't loop in reverse, we need the orderID to be in sequence
@ -147,21 +153,6 @@ Phaser.Stage.prototype.update = function () {
};
Phaser.Stage.prototype.destroy = function () {
if (this._hiddenVar)
{
document.removeEventListener(this._hiddenVar, this._onChange, false);
}
window.onpagehide = null;
window.onpageshow = null;
window.onblur = null;
window.onfocus = null;
};
/**
* This is called automatically before the renderer runs and after the plugins have updated.
* In postUpdate this is where all the final physics calculatations and object positioning happens.
@ -202,66 +193,6 @@ Phaser.Stage.prototype.postUpdate = function () {
};
/**
* Parses a Game configuration object.
*
* @method Phaser.Stage#parseConfig
* @protected
* @param {object} config -The configuration object to parse.
*/
Phaser.Stage.prototype.parseConfig = function (config) {
if (config['checkOffsetInterval'])
{
this.checkOffsetInterval = config['checkOffsetInterval'];
}
if (config['disableVisibilityChange'])
{
this.disableVisibilityChange = config['disableVisibilityChange'];
}
if (config['fullScreenScaleMode'])
{
this.fullScreenScaleMode = config['fullScreenScaleMode'];
}
if (config['scaleMode'])
{
this.scaleMode = config['scaleMode'];
}
if (config['backgroundColor'])
{
this.backgroundColor = config['backgroundColor'];
}
};
/**
* Initialises the stage and adds the event listeners.
* @method Phaser.Stage#boot
* @private
*/
Phaser.Stage.prototype.boot = function () {
Phaser.Canvas.getOffset(this.game.canvas, this.offset);
this.bounds.setTo(this.offset.x, this.offset.y, this.game.width, this.game.height);
var _this = this;
this._onChange = function (event) {
return _this.visibilityChange(event);
};
Phaser.Canvas.setUserSelect(this.game.canvas, 'none');
Phaser.Canvas.setTouchAction(this.game.canvas, 'none');
this.checkVisibility();
};
/**
* Starts a page visibility event listener running, or window.blur/focus if not supported by the browser.
* @method Phaser.Stage#checkVisibility
@ -378,6 +309,26 @@ Phaser.Stage.prototype.setBackgroundColor = function(backgroundColor)
};
/**
* Destroys the Stage and removes event listeners.
*
* @name Phaser.Stage#destroy
*/
Phaser.Stage.prototype.destroy = function () {
if (this._hiddenVar)
{
document.removeEventListener(this._hiddenVar, this._onChange, false);
}
window.onpagehide = null;
window.onpageshow = null;
window.onblur = null;
window.onfocus = null;
};
/**
* @name Phaser.Stage#backgroundColor
* @property {number|string} backgroundColor - Gets and sets the background color of the stage. The color can be given as a number: 0xff0000 or a hex string: '#ff0000'

View file

@ -34,6 +34,16 @@ Phaser.World = function (game) {
*/
this.camera = null;
/**
* @property {number} width - The defined width of the World. Sometimes the bounds needs to grow larger than this (if you resize the game) but this retains the original requested dimension.
*/
this._width = game.width;
/**
* @property {number} height - The defined height of the World. Sometimes the bounds needs to grow larger than this (if you resize the game) but this retains the original requested dimension.
*/
this._height = game.height;
};
Phaser.World.prototype = Object.create(Phaser.Group.prototype);
@ -90,6 +100,31 @@ Phaser.World.prototype.setBounds = function (x, y, width, height) {
this.game.physics.setBoundsToWorld();
this._width = width;
this._height = height;
};
Phaser.World.prototype.resize = function (width, height) {
// Don't ever scale the World bounds lower than the original requested dimensions
if (width < this._width)
{
width = this._width;
}
if (height < this._height)
{
height = this._height;
}
this.bounds.width = width;
this.bounds.height = height;
this.game.camera.setBoundsToWorld();
this.game.physics.setBoundsToWorld();
};
/**
@ -176,7 +211,7 @@ Phaser.World.prototype.wrap = function (sprite, padding, useBounds, horizontal,
/**
* @name Phaser.World#width
* @property {number} width - Gets or sets the current width of the game world.
* @property {number} width - Gets or sets the current width of the game world. The world can never be smaller than the game (canvas) dimensions.
*/
Object.defineProperty(Phaser.World.prototype, "width", {
@ -185,14 +220,22 @@ Object.defineProperty(Phaser.World.prototype, "width", {
},
set: function (value) {
if (value < this.game.width)
{
value = this.game.width;
}
this.bounds.width = value;
this._width = value;
}
});
/**
* @name Phaser.World#height
* @property {number} height - Gets or sets the current height of the game world.
* @property {number} height - Gets or sets the current height of the game world. The world can never be smaller than the game (canvas) dimensions.
*/
Object.defineProperty(Phaser.World.prototype, "height", {
@ -201,7 +244,15 @@ Object.defineProperty(Phaser.World.prototype, "height", {
},
set: function (value) {
if (value < this.game.height)
{
value = this.game.height;
}
this.bounds.height = value;
this._width = value;
}
});

View file

@ -408,12 +408,12 @@ Phaser.Input.prototype = {
*
* @method Phaser.Input#addMoveCallback
* @param {function} callback - The callback that will be called each time the activePointer receives a DOM move event.
* @param {object} callbackContext - The context in which the callback will be called.
* @param {object} context - The context in which the callback will be called.
* @return {number} The index of the callback entry. Use this index when calling Input.deleteMoveCallback.
*/
addMoveCallback: function (callback, callbackContext) {
addMoveCallback: function (callback, context) {
return this.moveCallbacks.push( { callback: callback, context: callbackContext }) - 1;
return this.moveCallbacks.push( { callback: callback, context: context }) - 1;
},

View file

@ -405,8 +405,6 @@ Phaser.Pointer.prototype = {
this.movementY += this.rawMovementY;
}
// this.x = (this.pageX - this.game.stage.offset.x) * this.game.input.scale.x;
// this.y = (this.pageY - this.game.stage.offset.y) * this.game.input.scale.y;
this.x = (this.pageX - this.game.scale.offset.x) * this.game.input.scale.x;
this.y = (this.pageY - this.game.scale.offset.y) * this.game.input.scale.y;