Physics World events added.

Group has new 'addToWorld' parameter, which fulfills the same function as the old useStage.
Stage now extends PIXI.Stage rather than owns one.
This commit is contained in:
photonstorm
2014-02-12 19:45:09 +00:00
parent 424d1126bc
commit f6113ac6c4
10 changed files with 401 additions and 159 deletions
+2 -2
View File
@@ -595,7 +595,7 @@ Phaser.Game.prototype = {
if (this._paused)
{
this.renderer.render(this.stage._stage);
this.renderer.render(this.stage);
this.plugins.render();
this.state.render();
}
@@ -627,7 +627,7 @@ Phaser.Game.prototype = {
if (this.renderType !== Phaser.HEADLESS)
{
this.renderer.render(this.stage._stage);
this.renderer.render(this.stage);
this.plugins.render();
this.state.render();
+5 -5
View File
@@ -12,9 +12,9 @@
* @param {Phaser.Game} game - A reference to the currently running game.
* @param {*} parent - The parent Group, DisplayObject or DisplayObjectContainer that this Group will be added to. If undefined or null it will use game.world.
* @param {string} [name=group] - A name for this Group. Not used internally but useful for debugging.
* @param {boolean} [useStage=false] - Should this Group be added to the World (default, false) or direct to the Stage (true).
* @param {boolean} [addToStage=false] - If set to true this Group will be added directly to the Game.Stage instead of Game.World.
*/
Phaser.Group = function (game, parent, name, useStage) {
Phaser.Group = function (game, parent, name, addToStage) {
/**
* @property {Phaser.Game} game - A reference to the currently running Game.
@@ -33,7 +33,7 @@ Phaser.Group = function (game, parent, name, useStage) {
PIXI.DisplayObjectContainer.call(this);
if (typeof useStage === 'undefined')
if (typeof addToStage === 'undefined')
{
if (parent)
{
@@ -41,12 +41,12 @@ Phaser.Group = function (game, parent, name, useStage) {
}
else
{
this.game.stage._stage.addChild(this);
this.game.stage.addChild(this);
}
}
else
{
this.game.stage._stage.addChild(this);
this.game.stage.addChild(this);
}
/**
+135 -131
View File
@@ -9,6 +9,7 @@
* focus handling, game resizing, scaling and the pause, boot and orientation screens.
*
* @class Phaser.Stage
* @extends PIXI.Stage
* @constructor
* @param {Phaser.Game} game - Game reference to the currently running game.
* @param {number} width - Width of the canvas element.
@@ -36,19 +37,25 @@ Phaser.Stage = function (game, width, height) {
* @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;
// 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 {PIXI.Stage} display - The Pixi Stage which is hooked to the renderer.
*/
this.display = this._stage;
// this.display = this._stage;
/**
* @property {number} scaleMode - The current scaleMode.
@@ -63,7 +70,7 @@ Phaser.Stage = function (game, width, height) {
/**
* @property {Phaser.StageScaleMode} scale - The scale of the current running game.
*/
this.scale = new Phaser.StageScaleMode(this.game, width, height);
// this.scale = new Phaser.StageScaleMode(this.game, width, height);
/**
* @property {number} aspectRatio - Aspect ratio.
@@ -100,143 +107,140 @@ Phaser.Stage = function (game, width, height) {
};
Phaser.Stage.prototype = {
Phaser.Stage.prototype = Object.create(PIXI.Stage.prototype);
Phaser.Stage.prototype.constructor = Phaser.Stage;
/**
* Parses a Game configuration object.
*
* @method Phaser.Stage#parseConfig
* @protected
*/
parseConfig: function (config) {
/**
* Parses a Game configuration object.
*
* @method Phaser.Stage#parseConfig
* @protected
*/
Phaser.Stage.prototype.parseConfig = function (config) {
if (config['canvasID'])
if (config['canvasID'])
{
this.canvas = Phaser.Canvas.create(this.game.width, this.game.height, config['canvasID']);
}
else
{
this.canvas = Phaser.Canvas.create(this.game.width, this.game.height);
}
if (config['canvasStyle'])
{
this.canvas.stlye = config['canvasStyle'];
}
else
{
this.canvas.style['-webkit-full-screen'] = 'width: 100%; height: 100%';
}
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.canvas, this.offset);
this.bounds = new Phaser.Rectangle(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.canvas, 'none');
Phaser.Canvas.setTouchAction(this.canvas, 'none');
// this.backgroundColor = '#000000';
document.addEventListener('visibilitychange', this._onChange, false);
document.addEventListener('webkitvisibilitychange', this._onChange, false);
document.addEventListener('pagehide', this._onChange, false);
document.addEventListener('pageshow', this._onChange, false);
window.onblur = this._onChange;
window.onfocus = this._onChange;
}
/**
* Runs Stage processes that need periodic updates, such as the offset checks.
* @method Phaser.Stage#update
*/
Phaser.Stage.prototype.update = function () {
if (this.checkOffsetInterval !== false)
{
if (this.game.time.now > this._nextOffsetCheck)
{
this.canvas = Phaser.Canvas.create(this.game.width, this.game.height, config['canvasID']);
}
else
{
this.canvas = Phaser.Canvas.create(this.game.width, this.game.height);
}
if (config['canvasStyle'])
{
this.canvas.stlye = config['canvasStyle'];
}
else
{
this.canvas.style['-webkit-full-screen'] = 'width: 100%; height: 100%';
}
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
*/
boot: function () {
Phaser.Canvas.getOffset(this.canvas, this.offset);
this.bounds = new Phaser.Rectangle(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.canvas, 'none');
Phaser.Canvas.setTouchAction(this.canvas, 'none');
this.backgroundColor = '#000000';
document.addEventListener('visibilitychange', this._onChange, false);
document.addEventListener('webkitvisibilitychange', this._onChange, false);
document.addEventListener('pagehide', this._onChange, false);
document.addEventListener('pageshow', this._onChange, false);
window.onblur = this._onChange;
window.onfocus = this._onChange;
},
/**
* Runs Stage processes that need periodic updates, such as the offset checks.
* @method Phaser.Stage#update
*/
update: function () {
if (this.checkOffsetInterval !== false)
{
if (this.game.time.now > this._nextOffsetCheck)
{
Phaser.Canvas.getOffset(this.canvas, this.offset);
this._nextOffsetCheck = this.game.time.now + this.checkOffsetInterval;
}
}
},
/**
* This method is called when the document visibility is changed.
* @method Phaser.Stage#visibilityChange
* @param {Event} event - Its type will be used to decide whether the game should be paused or not.
*/
visibilityChange: function (event) {
if (this.disableVisibilityChange)
{
return;
}
if (this.game.paused === false && (event.type == 'pagehide' || event.type == 'blur' || document['hidden'] === true || document['webkitHidden'] === true))
{
this.game.paused = true;
}
else
{
this.game.paused = false;
Phaser.Canvas.getOffset(this.canvas, this.offset);
this._nextOffsetCheck = this.game.time.now + this.checkOffsetInterval;
}
}
};
}
Phaser.Stage.prototype.constructor = Phaser.Stage;
/**
* This method is called when the document visibility is changed.
* @method Phaser.Stage#visibilityChange
* @param {Event} event - Its type will be used to decide whether the game should be paused or not.
*/
Phaser.Stage.prototype.visibilityChange = function (event) {
if (this.disableVisibilityChange)
{
return;
}
if (this.game.paused === false && (event.type == 'pagehide' || event.type == 'blur' || document['hidden'] === true || document['webkitHidden'] === true))
{
this.game.paused = true;
}
else
{
this.game.paused = false;
}
}
/**
* @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'
*/
Object.defineProperty(Phaser.Stage.prototype, "backgroundColor", {
Object.defineProperty(Phaser.Stage.prototype, "NEWbackgroundColor", {
get: function () {
return this._backgroundColor;
@@ -253,7 +257,7 @@ Object.defineProperty(Phaser.Stage.prototype, "backgroundColor", {
color = Phaser.Color.hexToRGB(color);
}
this._stage.setBackgroundColor(color);
this.setBackgroundColor(color);
}
}
+1 -1
View File
@@ -58,7 +58,7 @@ Phaser.World.prototype.boot = function () {
this.game.camera = this.camera;
this.game.stage._stage.addChild(this);
this.game.stage.addChild(this);
}