mirror of
https://github.com/wassname/phaser.git
synced 2026-07-31 12:40:07 +08:00
Updating all files to adhere to the JSHint settings and fixing lots of documentation errors on the way.
This commit is contained in:
+41
-38
@@ -19,35 +19,35 @@
|
||||
*/
|
||||
Phaser.Camera = function (game, id, x, y, width, height) {
|
||||
|
||||
/**
|
||||
* @property {Phaser.Game} game - A reference to the currently running Game.
|
||||
*/
|
||||
this.game = game;
|
||||
/**
|
||||
* @property {Phaser.Game} game - A reference to the currently running Game.
|
||||
*/
|
||||
this.game = game;
|
||||
|
||||
/**
|
||||
* @property {Phaser.World} world - A reference to the game world.
|
||||
*/
|
||||
this.world = game.world;
|
||||
/**
|
||||
* @property {Phaser.World} world - A reference to the game world.
|
||||
*/
|
||||
this.world = game.world;
|
||||
|
||||
/**
|
||||
* @property {number} id - Reserved for future multiple camera set-ups.
|
||||
* @default
|
||||
*/
|
||||
this.id = 0;
|
||||
/**
|
||||
* @property {number} id - Reserved for future multiple camera set-ups.
|
||||
* @default
|
||||
*/
|
||||
this.id = 0;
|
||||
|
||||
/**
|
||||
* Camera view.
|
||||
* The view into the world we wish to render (by default the game dimensions).
|
||||
/**
|
||||
* Camera view.
|
||||
* The view into the world we wish to render (by default the game dimensions).
|
||||
* The x/y values are in world coordinates, not screen coordinates, the width/height is how many pixels to render.
|
||||
* Objects outside of this view are not rendered (unless set to ignore the Camera, i.e. UI?).
|
||||
* @property {Phaser.Rectangle} view
|
||||
*/
|
||||
* @property {Phaser.Rectangle} view
|
||||
*/
|
||||
this.view = new Phaser.Rectangle(x, y, width, height);
|
||||
|
||||
/**
|
||||
* @property {Phaser.Rectangle} screenView - Used by Sprites to work out Camera culling.
|
||||
*/
|
||||
this.screenView = new Phaser.Rectangle(x, y, width, height);
|
||||
* @property {Phaser.Rectangle} screenView - Used by Sprites to work out Camera culling.
|
||||
*/
|
||||
this.screenView = new Phaser.Rectangle(x, y, width, height);
|
||||
|
||||
/**
|
||||
* The Camera is bound to this Rectangle and cannot move outside of it. By default it is enabled and set to the size of the World.
|
||||
@@ -58,36 +58,36 @@ Phaser.Camera = function (game, id, x, y, width, height) {
|
||||
this.bounds = new Phaser.Rectangle(x, y, width, height);
|
||||
|
||||
/**
|
||||
* @property {Phaser.Rectangle} deadzone - Moving inside this Rectangle will not cause camera moving.
|
||||
*/
|
||||
* @property {Phaser.Rectangle} deadzone - Moving inside this Rectangle will not cause camera moving.
|
||||
*/
|
||||
this.deadzone = null;
|
||||
|
||||
/**
|
||||
* @property {boolean} visible - Whether this camera is visible or not.
|
||||
* @default
|
||||
*/
|
||||
/**
|
||||
* @property {boolean} visible - Whether this camera is visible or not.
|
||||
* @default
|
||||
*/
|
||||
this.visible = true;
|
||||
|
||||
/**
|
||||
* @property {boolean} atLimit - Whether this camera is flush with the World Bounds or not.
|
||||
/**
|
||||
* @property {boolean} atLimit - Whether this camera is flush with the World Bounds or not.
|
||||
*/
|
||||
this.atLimit = { x: false, y: false };
|
||||
|
||||
/**
|
||||
* @property {Phaser.Sprite} target - If the camera is tracking a Sprite, this is a reference to it, otherwise null.
|
||||
/**
|
||||
* @property {Phaser.Sprite} target - If the camera is tracking a Sprite, this is a reference to it, otherwise null.
|
||||
* @default
|
||||
*/
|
||||
this.target = null;
|
||||
|
||||
/**
|
||||
* @property {number} edge - Edge property.
|
||||
/**
|
||||
* @property {number} edge - Edge property.
|
||||
* @private
|
||||
* @default
|
||||
*/
|
||||
this._edge = 0;
|
||||
|
||||
this.displayObject = null;
|
||||
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -116,7 +116,7 @@ Phaser.Camera.FOLLOW_TOPDOWN_TIGHT = 3;
|
||||
|
||||
Phaser.Camera.prototype = {
|
||||
|
||||
/**
|
||||
/**
|
||||
* Tells this camera which sprite to follow.
|
||||
* @method Phaser.Camera#follow
|
||||
* @param {Phaser.Sprite} target - The object you want the camera to track. Set to null to not follow anything.
|
||||
@@ -149,6 +149,9 @@ Phaser.Camera.prototype = {
|
||||
break;
|
||||
|
||||
case Phaser.Camera.FOLLOW_LOCKON:
|
||||
this.deadzone = null;
|
||||
break;
|
||||
|
||||
default:
|
||||
this.deadzone = null;
|
||||
break;
|
||||
@@ -167,7 +170,7 @@ Phaser.Camera.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
/**
|
||||
* Move the camera focus on a location instantly.
|
||||
* @method Phaser.Camera#focusOnXY
|
||||
* @param {number} x - X position.
|
||||
@@ -179,7 +182,7 @@ Phaser.Camera.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
/**
|
||||
* Update focusing and scrolling.
|
||||
* @method Phaser.Camera#update
|
||||
*/
|
||||
@@ -348,7 +351,7 @@ Object.defineProperty(Phaser.Camera.prototype, "x", {
|
||||
* @property {number} y - Gets or sets the cameras y position.
|
||||
*/
|
||||
Object.defineProperty(Phaser.Camera.prototype, "y", {
|
||||
|
||||
|
||||
get: function () {
|
||||
return this.view.y;
|
||||
},
|
||||
|
||||
+4
-4
@@ -16,9 +16,9 @@
|
||||
*/
|
||||
Phaser.Filter = function (game, uniforms, fragmentSrc) {
|
||||
|
||||
/**
|
||||
* @property {Phaser.Game} game - A reference to the currently running game.
|
||||
*/
|
||||
/**
|
||||
* @property {Phaser.Game} game - A reference to the currently running game.
|
||||
*/
|
||||
this.game = game;
|
||||
|
||||
/**
|
||||
@@ -86,7 +86,7 @@ Phaser.Filter.prototype = {
|
||||
this.uniforms.mouse.y = pointer.y;
|
||||
}
|
||||
|
||||
this.uniforms.time.value = this.game.time.totalElapsedSeconds();
|
||||
this.uniforms.time.value = this.game.time.totalElapsedSeconds();
|
||||
|
||||
},
|
||||
|
||||
|
||||
+313
-313
@@ -24,380 +24,380 @@
|
||||
*/
|
||||
Phaser.Game = function (width, height, renderer, parent, state, transparent, antialias) {
|
||||
|
||||
width = width || 800;
|
||||
height = height || 600;
|
||||
renderer = renderer || Phaser.AUTO;
|
||||
parent = parent || '';
|
||||
state = state || null;
|
||||
width = width || 800;
|
||||
height = height || 600;
|
||||
renderer = renderer || Phaser.AUTO;
|
||||
parent = parent || '';
|
||||
state = state || null;
|
||||
|
||||
if (typeof transparent == 'undefined') { transparent = false; }
|
||||
if (typeof antialias == 'undefined') { antialias = true; }
|
||||
if (typeof transparent == 'undefined') { transparent = false; }
|
||||
if (typeof antialias == 'undefined') { antialias = true; }
|
||||
|
||||
/**
|
||||
* @property {number} id - Phaser Game ID (for when Pixi supports multiple instances).
|
||||
*/
|
||||
this.id = Phaser.GAMES.push(this) - 1;
|
||||
/**
|
||||
* @property {number} id - Phaser Game ID (for when Pixi supports multiple instances).
|
||||
*/
|
||||
this.id = Phaser.GAMES.push(this) - 1;
|
||||
|
||||
/**
|
||||
* @property {HTMLElement} parent - The Games DOM parent.
|
||||
*/
|
||||
this.parent = parent;
|
||||
/**
|
||||
* @property {HTMLElement} parent - The Games DOM parent.
|
||||
*/
|
||||
this.parent = parent;
|
||||
|
||||
// Do some more intelligent size parsing here, so they can set "100%" for example, maybe pass the scale mode in here too?
|
||||
// Do some more intelligent size parsing here, so they can set "100%" for example, maybe pass the scale mode in here too?
|
||||
|
||||
/**
|
||||
* @property {number} width - The Game width (in pixels).
|
||||
*/
|
||||
this.width = width;
|
||||
/**
|
||||
* @property {number} width - The Game width (in pixels).
|
||||
*/
|
||||
this.width = width;
|
||||
|
||||
/**
|
||||
* @property {number} height - The Game height (in pixels).
|
||||
*/
|
||||
this.height = height;
|
||||
/**
|
||||
* @property {number} height - The Game height (in pixels).
|
||||
*/
|
||||
this.height = height;
|
||||
|
||||
/**
|
||||
* @property {boolean} transparent - Use a transparent canvas background or not.
|
||||
*/
|
||||
this.transparent = transparent;
|
||||
/**
|
||||
* @property {boolean} transparent - Use a transparent canvas background or not.
|
||||
*/
|
||||
this.transparent = transparent;
|
||||
|
||||
/**
|
||||
* @property {boolean} antialias - Anti-alias graphics (in WebGL this helps with edges, in Canvas2D it retains pixel-art quality).
|
||||
*/
|
||||
this.antialias = antialias;
|
||||
/**
|
||||
* @property {boolean} antialias - Anti-alias graphics (in WebGL this helps with edges, in Canvas2D it retains pixel-art quality).
|
||||
*/
|
||||
this.antialias = antialias;
|
||||
|
||||
/**
|
||||
* @property {number} renderer - The Pixi Renderer
|
||||
* @default
|
||||
*/
|
||||
this.renderer = null;
|
||||
/**
|
||||
* @property {number} renderer - The Pixi Renderer
|
||||
* @default
|
||||
*/
|
||||
this.renderer = null;
|
||||
|
||||
/**
|
||||
* @property {number} state - The StateManager.
|
||||
*/
|
||||
this.state = new Phaser.StateManager(this, state);
|
||||
/**
|
||||
* @property {number} state - The StateManager.
|
||||
*/
|
||||
this.state = new Phaser.StateManager(this, state);
|
||||
|
||||
/**
|
||||
* @property {boolean} _paused - Is game paused?
|
||||
* @private
|
||||
* @default
|
||||
*/
|
||||
this._paused = false;
|
||||
/**
|
||||
* @property {boolean} _paused - Is game paused?
|
||||
* @private
|
||||
* @default
|
||||
*/
|
||||
this._paused = false;
|
||||
|
||||
/**
|
||||
* @property {number} renderType - The Renderer this Phaser.Game will use. Either Phaser.RENDERER_AUTO, Phaser.RENDERER_CANVAS or Phaser.RENDERER_WEBGL.
|
||||
*/
|
||||
this.renderType = renderer;
|
||||
/**
|
||||
* @property {number} renderType - The Renderer this Phaser.Game will use. Either Phaser.RENDERER_AUTO, Phaser.RENDERER_CANVAS or Phaser.RENDERER_WEBGL.
|
||||
*/
|
||||
this.renderType = renderer;
|
||||
|
||||
/**
|
||||
* @property {boolean} _loadComplete - Whether load complete loading or not.
|
||||
* @private
|
||||
* @default
|
||||
*/
|
||||
this._loadComplete = false;
|
||||
/**
|
||||
* @property {boolean} _loadComplete - Whether load complete loading or not.
|
||||
* @private
|
||||
* @default
|
||||
*/
|
||||
this._loadComplete = false;
|
||||
|
||||
/**
|
||||
* @property {boolean} isBooted - Whether the game engine is booted, aka available.
|
||||
* @default
|
||||
*/
|
||||
this.isBooted = false;
|
||||
/**
|
||||
* @property {boolean} isBooted - Whether the game engine is booted, aka available.
|
||||
* @default
|
||||
*/
|
||||
this.isBooted = false;
|
||||
|
||||
/**
|
||||
* @property {boolean} id -Is game running or paused?
|
||||
* @default
|
||||
*/
|
||||
this.isRunning = false;
|
||||
/**
|
||||
* @property {boolean} id -Is game running or paused?
|
||||
* @default
|
||||
*/
|
||||
this.isRunning = false;
|
||||
|
||||
/**
|
||||
* @property {Phaser.RequestAnimationFrame} raf - Automatically handles the core game loop via requestAnimationFrame or setTimeout
|
||||
* @default
|
||||
*/
|
||||
this.raf = null;
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
/**
|
||||
* @property {Phaser.GameObjectFactory} add - Reference to the GameObject Factory.
|
||||
* @default
|
||||
*/
|
||||
this.add = null;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Cache} cache - Reference to the assets cache.
|
||||
* @default
|
||||
*/
|
||||
* @property {Phaser.Cache} cache - Reference to the assets cache.
|
||||
* @default
|
||||
*/
|
||||
this.cache = null;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Input} input - Reference to the input manager
|
||||
* @default
|
||||
*/
|
||||
* @property {Phaser.Input} input - Reference to the input manager
|
||||
* @default
|
||||
*/
|
||||
this.input = null;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Loader} load - Reference to the assets loader.
|
||||
* @default
|
||||
*/
|
||||
* @property {Phaser.Loader} load - Reference to the assets loader.
|
||||
* @default
|
||||
*/
|
||||
this.load = null;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Math} math - Reference to the math helper.
|
||||
* @default
|
||||
*/
|
||||
* @property {Phaser.Math} math - Reference to the math helper.
|
||||
* @default
|
||||
*/
|
||||
this.math = null;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Net} net - Reference to the network class.
|
||||
* @default
|
||||
*/
|
||||
* @property {Phaser.Net} net - Reference to the network class.
|
||||
* @default
|
||||
*/
|
||||
this.net = null;
|
||||
|
||||
/**
|
||||
* @property {Phaser.SoundManager} sound - Reference to the sound manager.
|
||||
* @default
|
||||
*/
|
||||
* @property {Phaser.SoundManager} sound - Reference to the sound manager.
|
||||
* @default
|
||||
*/
|
||||
this.sound = null;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Stage} stage - Reference to the stage.
|
||||
* @default
|
||||
*/
|
||||
* @property {Phaser.Stage} stage - Reference to the stage.
|
||||
* @default
|
||||
*/
|
||||
this.stage = null;
|
||||
|
||||
/**
|
||||
* @property {Phaser.TimeManager} time - Reference to game clock.
|
||||
* @default
|
||||
*/
|
||||
* @property {Phaser.TimeManager} time - Reference to game clock.
|
||||
* @default
|
||||
*/
|
||||
this.time = null;
|
||||
|
||||
/**
|
||||
* @property {Phaser.TweenManager} tweens - Reference to the tween manager.
|
||||
* @default
|
||||
*/
|
||||
* @property {Phaser.TweenManager} tweens - Reference to the tween manager.
|
||||
* @default
|
||||
*/
|
||||
this.tweens = null;
|
||||
|
||||
/**
|
||||
* @property {Phaser.World} world - Reference to the world.
|
||||
* @default
|
||||
*/
|
||||
* @property {Phaser.World} world - Reference to the world.
|
||||
* @default
|
||||
*/
|
||||
this.world = null;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Physics.PhysicsManager} physics - Reference to the physics manager.
|
||||
* @default
|
||||
*/
|
||||
* @property {Phaser.Physics.PhysicsManager} physics - Reference to the physics manager.
|
||||
* @default
|
||||
*/
|
||||
this.physics = null;
|
||||
|
||||
/**
|
||||
* @property {Phaser.RandomDataGenerator} rnd - Instance of repeatable random data generator helper.
|
||||
* @default
|
||||
*/
|
||||
* @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
|
||||
*/
|
||||
* @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 {Phaser.Physics.PhysicsManager} camera - A handy reference to world.camera.
|
||||
* @default
|
||||
*/
|
||||
this.camera = null;
|
||||
|
||||
/**
|
||||
* @property {HTMLCanvasElement} canvas - A handy reference to renderer.view.
|
||||
* @default
|
||||
*/
|
||||
this.canvas = null;
|
||||
|
||||
/**
|
||||
* @property {Context} context - A handy reference to renderer.context (only set for CANVAS games)
|
||||
* @default
|
||||
*/
|
||||
this.context = null;
|
||||
/**
|
||||
* @property {HTMLCanvasElement} canvas - A handy reference to renderer.view.
|
||||
* @default
|
||||
*/
|
||||
this.canvas = null;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Utils.Debug} debug - A set of useful debug utilitie.
|
||||
* @default
|
||||
*/
|
||||
this.debug = null;
|
||||
* @property {Context} context - A handy reference to renderer.context (only set for CANVAS games)
|
||||
* @default
|
||||
*/
|
||||
this.context = null;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Particles} particles - The Particle Manager.
|
||||
* @default
|
||||
*/
|
||||
this.particles = null;
|
||||
/**
|
||||
* @property {Phaser.Utils.Debug} debug - A set of useful debug utilitie.
|
||||
* @default
|
||||
*/
|
||||
this.debug = null;
|
||||
|
||||
var _this = this;
|
||||
/**
|
||||
* @property {Phaser.Particles} particles - The Particle Manager.
|
||||
* @default
|
||||
*/
|
||||
this.particles = null;
|
||||
|
||||
var _this = this;
|
||||
|
||||
this._onBoot = function () {
|
||||
return _this.boot();
|
||||
}
|
||||
|
||||
if (document.readyState === 'complete' || document.readyState === 'interactive')
|
||||
{
|
||||
window.setTimeout(this._onBoot, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
document.addEventListener('DOMContentLoaded', this._onBoot, false);
|
||||
window.addEventListener('load', this._onBoot, false);
|
||||
}
|
||||
if (document.readyState === 'complete' || document.readyState === 'interactive')
|
||||
{
|
||||
window.setTimeout(this._onBoot, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
document.addEventListener('DOMContentLoaded', this._onBoot, false);
|
||||
window.addEventListener('load', this._onBoot, false);
|
||||
}
|
||||
|
||||
return this;
|
||||
return this;
|
||||
|
||||
};
|
||||
|
||||
Phaser.Game.prototype = {
|
||||
|
||||
/**
|
||||
* Initialize engine sub modules and start the game.
|
||||
*
|
||||
* @method Phaser.Game#boot
|
||||
* @protected
|
||||
*/
|
||||
boot: function () {
|
||||
/**
|
||||
* Initialize engine sub modules and start the game.
|
||||
*
|
||||
* @method Phaser.Game#boot
|
||||
* @protected
|
||||
*/
|
||||
boot: function () {
|
||||
|
||||
if (this.isBooted)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (this.isBooted)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!document.body)
|
||||
{
|
||||
window.setTimeout(this._onBoot, 20);
|
||||
}
|
||||
else
|
||||
{
|
||||
document.removeEventListener('DOMContentLoaded', this._onBoot);
|
||||
window.removeEventListener('load', this._onBoot);
|
||||
if (!document.body)
|
||||
{
|
||||
window.setTimeout(this._onBoot, 20);
|
||||
}
|
||||
else
|
||||
{
|
||||
document.removeEventListener('DOMContentLoaded', this._onBoot);
|
||||
window.removeEventListener('load', this._onBoot);
|
||||
|
||||
this.onPause = new Phaser.Signal;
|
||||
this.onResume = new Phaser.Signal;
|
||||
this.onPause = new Phaser.Signal();
|
||||
this.onResume = new Phaser.Signal();
|
||||
|
||||
this.isBooted = true;
|
||||
this.isBooted = true;
|
||||
|
||||
this.device = new Phaser.Device();
|
||||
this.math = Phaser.Math;
|
||||
this.rnd = new Phaser.RandomDataGenerator([(Date.now() * Math.random()).toString()]);
|
||||
this.device = new Phaser.Device();
|
||||
this.math = Phaser.Math;
|
||||
this.rnd = new Phaser.RandomDataGenerator([(Date.now() * Math.random()).toString()]);
|
||||
|
||||
this.stage = new Phaser.Stage(this, this.width, this.height);
|
||||
this.stage = new Phaser.Stage(this, this.width, this.height);
|
||||
|
||||
this.setUpRenderer();
|
||||
this.setUpRenderer();
|
||||
|
||||
this.world = new Phaser.World(this);
|
||||
this.add = new Phaser.GameObjectFactory(this);
|
||||
this.cache = new Phaser.Cache(this);
|
||||
this.load = new Phaser.Loader(this);
|
||||
this.time = new Phaser.Time(this);
|
||||
this.tweens = new Phaser.TweenManager(this);
|
||||
this.input = new Phaser.Input(this);
|
||||
this.sound = new Phaser.SoundManager(this);
|
||||
this.physics = new Phaser.Physics.Arcade(this);
|
||||
this.particles = new Phaser.Particles(this);
|
||||
this.plugins = new Phaser.PluginManager(this, this);
|
||||
this.net = new Phaser.Net(this);
|
||||
this.debug = new Phaser.Utils.Debug(this);
|
||||
this.world = new Phaser.World(this);
|
||||
this.add = new Phaser.GameObjectFactory(this);
|
||||
this.cache = new Phaser.Cache(this);
|
||||
this.load = new Phaser.Loader(this);
|
||||
this.time = new Phaser.Time(this);
|
||||
this.tweens = new Phaser.TweenManager(this);
|
||||
this.input = new Phaser.Input(this);
|
||||
this.sound = new Phaser.SoundManager(this);
|
||||
this.physics = new Phaser.Physics.Arcade(this);
|
||||
this.particles = new Phaser.Particles(this);
|
||||
this.plugins = new Phaser.PluginManager(this, this);
|
||||
this.net = new Phaser.Net(this);
|
||||
this.debug = new Phaser.Utils.Debug(this);
|
||||
|
||||
this.stage.boot();
|
||||
this.world.boot();
|
||||
this.input.boot();
|
||||
this.sound.boot();
|
||||
this.state.boot();
|
||||
this.stage.boot();
|
||||
this.world.boot();
|
||||
this.input.boot();
|
||||
this.sound.boot();
|
||||
this.state.boot();
|
||||
|
||||
this.load.onLoadComplete.add(this.loadComplete, this);
|
||||
this.load.onLoadComplete.add(this.loadComplete, this);
|
||||
|
||||
this.showDebugHeader();
|
||||
this.showDebugHeader();
|
||||
|
||||
this.isRunning = true;
|
||||
this.isRunning = true;
|
||||
this._loadComplete = false;
|
||||
|
||||
this.raf = new Phaser.RequestAnimationFrame(this);
|
||||
this.raf.start();
|
||||
this.raf = new Phaser.RequestAnimationFrame(this);
|
||||
this.raf.start();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
/**
|
||||
* Displays a Phaser version debug header in the console.
|
||||
*
|
||||
* @method Phaser.Game#showDebugHeader
|
||||
* @protected
|
||||
*/
|
||||
showDebugHeader: function () {
|
||||
showDebugHeader: function () {
|
||||
|
||||
var v = Phaser.DEV_VERSION;
|
||||
var r = 'Canvas';
|
||||
var a = 'HTML Audio';
|
||||
var v = Phaser.DEV_VERSION;
|
||||
var r = 'Canvas';
|
||||
var a = 'HTML Audio';
|
||||
|
||||
if (this.renderType == Phaser.WEBGL)
|
||||
{
|
||||
r = 'WebGL';
|
||||
}
|
||||
if (this.renderType == Phaser.WEBGL)
|
||||
{
|
||||
r = 'WebGL';
|
||||
}
|
||||
|
||||
if (this.device.webAudio)
|
||||
{
|
||||
a = 'WebAudio';
|
||||
}
|
||||
if (this.device.webAudio)
|
||||
{
|
||||
a = 'WebAudio';
|
||||
}
|
||||
|
||||
if (this.device.chrome)
|
||||
{
|
||||
var args = [
|
||||
'%c %c %c Phaser v' + v + ' - Renderer: ' + r + ' - Audio: ' + a + ' %c %c ',
|
||||
'background: #00bff3',
|
||||
'background: #0072bc',
|
||||
'color: #ffffff; background: #003471',
|
||||
'background: #0072bc',
|
||||
'background: #00bff3'
|
||||
];
|
||||
if (this.device.chrome)
|
||||
{
|
||||
var args = [
|
||||
'%c %c %c Phaser v' + v + ' - Renderer: ' + r + ' - Audio: ' + a + ' %c %c ',
|
||||
'background: #00bff3',
|
||||
'background: #0072bc',
|
||||
'color: #ffffff; background: #003471',
|
||||
'background: #0072bc',
|
||||
'background: #00bff3'
|
||||
];
|
||||
|
||||
console.log.apply(console, args);
|
||||
}
|
||||
else
|
||||
{
|
||||
console.log('Phaser v' + v + ' - Renderer: ' + r + ' - Audio: ' + a);
|
||||
}
|
||||
console.log.apply(console, args);
|
||||
}
|
||||
else
|
||||
{
|
||||
console.log('Phaser v' + v + ' - Renderer: ' + r + ' - Audio: ' + a);
|
||||
}
|
||||
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks if the device is capable of using the requested renderer and sets it up or an alternative if not.
|
||||
*
|
||||
* @method Phaser.Game#setUpRenderer
|
||||
* @protected
|
||||
*/
|
||||
setUpRenderer: function () {
|
||||
/**
|
||||
* Checks if the device is capable of using the requested renderer and sets it up or an alternative if not.
|
||||
*
|
||||
* @method Phaser.Game#setUpRenderer
|
||||
* @protected
|
||||
*/
|
||||
setUpRenderer: function () {
|
||||
|
||||
if (this.renderType === Phaser.CANVAS || (this.renderType === Phaser.AUTO && this.device.webGL == false))
|
||||
{
|
||||
if (this.device.canvas)
|
||||
{
|
||||
this.renderType = Phaser.CANVAS;
|
||||
this.renderer = new PIXI.CanvasRenderer(this.width, this.height, this.stage.canvas, this.transparent);
|
||||
Phaser.Canvas.setSmoothingEnabled(this.renderer.context, this.antialias);
|
||||
this.canvas = this.renderer.view;
|
||||
this.context = this.renderer.context;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Error('Phaser.Game - cannot create Canvas or WebGL context, aborting.');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// They requested WebGL, and their browser supports it
|
||||
this.renderType = Phaser.WEBGL;
|
||||
this.renderer = new PIXI.WebGLRenderer(this.width, this.height, this.stage.canvas, this.transparent, this.antialias);
|
||||
this.canvas = this.renderer.view;
|
||||
this.context = null;
|
||||
}
|
||||
if (this.renderType === Phaser.CANVAS || (this.renderType === Phaser.AUTO && this.device.webGL === false))
|
||||
{
|
||||
if (this.device.canvas)
|
||||
{
|
||||
this.renderType = Phaser.CANVAS;
|
||||
this.renderer = new PIXI.CanvasRenderer(this.width, this.height, this.stage.canvas, this.transparent);
|
||||
Phaser.Canvas.setSmoothingEnabled(this.renderer.context, this.antialias);
|
||||
this.canvas = this.renderer.view;
|
||||
this.context = this.renderer.context;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Error('Phaser.Game - cannot create Canvas or WebGL context, aborting.');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// They requested WebGL, and their browser supports it
|
||||
this.renderType = Phaser.WEBGL;
|
||||
this.renderer = new PIXI.WebGLRenderer(this.width, this.height, this.stage.canvas, this.transparent, this.antialias);
|
||||
this.canvas = this.renderer.view;
|
||||
this.context = null;
|
||||
}
|
||||
|
||||
Phaser.Canvas.addToDOM(this.renderer.view, this.parent, true);
|
||||
Phaser.Canvas.setTouchAction(this.renderer.view);
|
||||
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
/**
|
||||
* Called when the load has finished, after preload was run.
|
||||
*
|
||||
* @method Phaser.Game#loadComplete
|
||||
@@ -411,61 +411,61 @@ Phaser.Game.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
/**
|
||||
* The core game loop.
|
||||
*
|
||||
* @method Phaser.Game#update
|
||||
* @protected
|
||||
* @param {number} time - The current time as provided by RequestAnimationFrame.
|
||||
* @param {number} time - The current time as provided by RequestAnimationFrame.
|
||||
*/
|
||||
update: function (time) {
|
||||
update: function (time) {
|
||||
|
||||
this.time.update(time);
|
||||
this.time.update(time);
|
||||
|
||||
if (this._paused)
|
||||
{
|
||||
this.renderer.render(this.stage._stage);
|
||||
this.plugins.render();
|
||||
this.state.render();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.plugins.preUpdate();
|
||||
this.physics.preUpdate();
|
||||
if (this._paused)
|
||||
{
|
||||
this.renderer.render(this.stage._stage);
|
||||
this.plugins.render();
|
||||
this.state.render();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.plugins.preUpdate();
|
||||
this.physics.preUpdate();
|
||||
|
||||
this.stage.update();
|
||||
this.input.update();
|
||||
this.tweens.update();
|
||||
this.sound.update();
|
||||
this.world.update();
|
||||
this.particles.update();
|
||||
this.state.update();
|
||||
this.plugins.update();
|
||||
this.stage.update();
|
||||
this.input.update();
|
||||
this.tweens.update();
|
||||
this.sound.update();
|
||||
this.world.update();
|
||||
this.particles.update();
|
||||
this.state.update();
|
||||
this.plugins.update();
|
||||
|
||||
this.world.postUpdate();
|
||||
this.world.postUpdate();
|
||||
this.plugins.postUpdate();
|
||||
|
||||
this.renderer.render(this.stage._stage);
|
||||
this.plugins.render();
|
||||
this.state.render();
|
||||
this.renderer.render(this.stage._stage);
|
||||
this.plugins.render();
|
||||
this.state.render();
|
||||
|
||||
this.plugins.postRender();
|
||||
}
|
||||
this.plugins.postRender();
|
||||
}
|
||||
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
/**
|
||||
* Nuke the entire game from orbit
|
||||
*
|
||||
* @method Phaser.Game#destroy
|
||||
*/
|
||||
destroy: function () {
|
||||
|
||||
this.raf.stop();
|
||||
this.raf.stop();
|
||||
|
||||
this.input.destroy();
|
||||
this.input.destroy();
|
||||
|
||||
this.state.destroy();
|
||||
this.state.destroy();
|
||||
|
||||
this.state = null;
|
||||
this.cache = null;
|
||||
@@ -495,22 +495,22 @@ Object.defineProperty(Phaser.Game.prototype, "paused", {
|
||||
|
||||
set: function (value) {
|
||||
|
||||
if (value === true)
|
||||
{
|
||||
if (this._paused == false)
|
||||
{
|
||||
this._paused = true;
|
||||
this.onPause.dispatch(this);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this._paused)
|
||||
{
|
||||
this._paused = false;
|
||||
this.onResume.dispatch(this);
|
||||
}
|
||||
}
|
||||
if (value === true)
|
||||
{
|
||||
if (this._paused === false)
|
||||
{
|
||||
this._paused = true;
|
||||
this.onPause.dispatch(this);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this._paused)
|
||||
{
|
||||
this._paused = false;
|
||||
this.onResume.dispatch(this);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
+978
-979
File diff suppressed because it is too large
Load Diff
+85
-85
@@ -13,141 +13,141 @@
|
||||
Phaser.LinkedList = function () {
|
||||
|
||||
/**
|
||||
* @property {object} next - Next element in the list.
|
||||
* @default
|
||||
*/
|
||||
* @property {object} next - Next element in the list.
|
||||
* @default
|
||||
*/
|
||||
this.next = null;
|
||||
|
||||
/**
|
||||
* @property {object} prev - Previous element in the list.
|
||||
* @default
|
||||
*/
|
||||
* @property {object} prev - Previous element in the list.
|
||||
* @default
|
||||
*/
|
||||
this.prev = null;
|
||||
|
||||
/**
|
||||
* @property {object} first - First element in the list.
|
||||
* @default
|
||||
*/
|
||||
* @property {object} first - First element in the list.
|
||||
* @default
|
||||
*/
|
||||
this.first = null;
|
||||
|
||||
/**
|
||||
* @property {object} last - Last element in the list.
|
||||
* @default
|
||||
*/
|
||||
* @property {object} last - Last element in the list.
|
||||
* @default
|
||||
*/
|
||||
this.last = null;
|
||||
|
||||
/**
|
||||
* @property {object} game - Number of elements in the list.
|
||||
* @default
|
||||
*/
|
||||
* @property {object} game - Number of elements in the list.
|
||||
* @default
|
||||
*/
|
||||
this.total = 0;
|
||||
|
||||
};
|
||||
|
||||
Phaser.LinkedList.prototype = {
|
||||
|
||||
/**
|
||||
/**
|
||||
* Adds a new element to this linked list.
|
||||
*
|
||||
* @method Phaser.LinkedList#add
|
||||
* @param {object} child - The element to add to this list. Can be a Phaser.Sprite or any other object you need to quickly iterate through.
|
||||
* @return {object} The child that was added.
|
||||
*
|
||||
* @method Phaser.LinkedList#add
|
||||
* @param {object} child - The element to add to this list. Can be a Phaser.Sprite or any other object you need to quickly iterate through.
|
||||
* @return {object} The child that was added.
|
||||
*/
|
||||
add: function (child) {
|
||||
|
||||
// If the list is empty
|
||||
if (this.total == 0 && this.first == null && this.last == null)
|
||||
{
|
||||
this.first = child;
|
||||
this.last = child;
|
||||
this.next = child;
|
||||
child.prev = this;
|
||||
this.total++;
|
||||
return child;
|
||||
}
|
||||
// If the list is empty
|
||||
if (this.total === 0 && this.first == null && this.last == null)
|
||||
{
|
||||
this.first = child;
|
||||
this.last = child;
|
||||
this.next = child;
|
||||
child.prev = this;
|
||||
this.total++;
|
||||
return child;
|
||||
}
|
||||
|
||||
// Get gets appended to the end of the list, regardless of anything, and it won't have any children of its own (non-nested list)
|
||||
this.last.next = child;
|
||||
// Get gets appended to the end of the list, regardless of anything, and it won't have any children of its own (non-nested list)
|
||||
this.last.next = child;
|
||||
|
||||
child.prev = this.last;
|
||||
child.prev = this.last;
|
||||
|
||||
this.last = child;
|
||||
this.last = child;
|
||||
|
||||
this.total++;
|
||||
this.total++;
|
||||
|
||||
return child;
|
||||
return child;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
/**
|
||||
* Removes the given element from this linked list if it exists.
|
||||
*
|
||||
* @method Phaser.LinkedList#remove
|
||||
* @param {object} child - The child to be removed from the list.
|
||||
*
|
||||
* @method Phaser.LinkedList#remove
|
||||
* @param {object} child - The child to be removed from the list.
|
||||
*/
|
||||
remove: function (child) {
|
||||
|
||||
if (child == this.first)
|
||||
{
|
||||
// It was 'first', make 'first' point to first.next
|
||||
this.first = this.first.next;
|
||||
}
|
||||
else if (child == this.last)
|
||||
{
|
||||
// It was 'last', make 'last' point to last.prev
|
||||
this.last = this.last.prev;
|
||||
}
|
||||
if (child == this.first)
|
||||
{
|
||||
// It was 'first', make 'first' point to first.next
|
||||
this.first = this.first.next;
|
||||
}
|
||||
else if (child == this.last)
|
||||
{
|
||||
// It was 'last', make 'last' point to last.prev
|
||||
this.last = this.last.prev;
|
||||
}
|
||||
|
||||
if (child.prev)
|
||||
{
|
||||
// make child.prev.next point to childs.next instead of child
|
||||
child.prev.next = child.next;
|
||||
}
|
||||
if (child.prev)
|
||||
{
|
||||
// make child.prev.next point to childs.next instead of child
|
||||
child.prev.next = child.next;
|
||||
}
|
||||
|
||||
if (child.next)
|
||||
{
|
||||
// make child.next.prev point to child.prev instead of child
|
||||
child.next.prev = child.prev;
|
||||
}
|
||||
if (child.next)
|
||||
{
|
||||
// make child.next.prev point to child.prev instead of child
|
||||
child.next.prev = child.prev;
|
||||
}
|
||||
|
||||
child.next = child.prev = null;
|
||||
child.next = child.prev = null;
|
||||
|
||||
if (this.first == null )
|
||||
{
|
||||
this.last = null;
|
||||
}
|
||||
if (this.first == null )
|
||||
{
|
||||
this.last = null;
|
||||
}
|
||||
|
||||
this.total--;
|
||||
this.total--;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
/**
|
||||
* Calls a function on all members of this list, using the member as the context for the callback.
|
||||
* The function must exist on the member.
|
||||
*
|
||||
* @method Phaser.LinkedList#callAll
|
||||
* @param {function} callback - The function to call.
|
||||
*
|
||||
* @method Phaser.LinkedList#callAll
|
||||
* @param {function} callback - The function to call.
|
||||
*/
|
||||
callAll: function (callback) {
|
||||
|
||||
if (!this.first || !this.last)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!this.first || !this.last)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var entity = this.first;
|
||||
|
||||
do
|
||||
{
|
||||
if (entity && entity[callback])
|
||||
{
|
||||
entity[callback].call(entity);
|
||||
}
|
||||
var entity = this.first;
|
||||
|
||||
do
|
||||
{
|
||||
if (entity && entity[callback])
|
||||
{
|
||||
entity[callback].call(entity);
|
||||
}
|
||||
|
||||
entity = entity.next;
|
||||
entity = entity.next;
|
||||
|
||||
}
|
||||
while(entity != this.last.next)
|
||||
}
|
||||
while(entity != this.last.next)
|
||||
|
||||
}
|
||||
|
||||
|
||||
+23
-23
@@ -17,38 +17,38 @@ Phaser.Plugin = function (game, parent) {
|
||||
|
||||
if (typeof parent === 'undefined') { parent = null; }
|
||||
|
||||
/**
|
||||
* @property {Phaser.Game} game - A reference to the currently running game.
|
||||
*/
|
||||
/**
|
||||
* @property {Phaser.Game} game - A reference to the currently running game.
|
||||
*/
|
||||
this.game = game;
|
||||
|
||||
/**
|
||||
* @property {Any} parent - The parent of this plugin. If added to the PluginManager the parent will be set to that, otherwise it will be null.
|
||||
*/
|
||||
* @property {Any} parent - The parent of this plugin. If added to the PluginManager the parent will be set to that, otherwise it will be null.
|
||||
*/
|
||||
this.parent = parent;
|
||||
|
||||
/**
|
||||
* @property {boolean} active - A Plugin with active=true has its preUpdate and update methods called by the parent, otherwise they are skipped.
|
||||
* @default
|
||||
*/
|
||||
* @property {boolean} active - A Plugin with active=true has its preUpdate and update methods called by the parent, otherwise they are skipped.
|
||||
* @default
|
||||
*/
|
||||
this.active = false;
|
||||
|
||||
/**
|
||||
* @property {boolean} visible - A Plugin with visible=true has its render and postRender methods called by the parent, otherwise they are skipped.
|
||||
* @default
|
||||
*/
|
||||
* @property {boolean} visible - A Plugin with visible=true has its render and postRender methods called by the parent, otherwise they are skipped.
|
||||
* @default
|
||||
*/
|
||||
this.visible = false;
|
||||
|
||||
/**
|
||||
* @property {boolean} hasPreUpdate - A flag to indicate if this plugin has a preUpdate method.
|
||||
* @default
|
||||
*/
|
||||
* @property {boolean} hasPreUpdate - A flag to indicate if this plugin has a preUpdate method.
|
||||
* @default
|
||||
*/
|
||||
this.hasPreUpdate = false;
|
||||
|
||||
/**
|
||||
* @property {boolean} hasUpdate - A flag to indicate if this plugin has an update method.
|
||||
* @default
|
||||
*/
|
||||
* @property {boolean} hasUpdate - A flag to indicate if this plugin has an update method.
|
||||
* @default
|
||||
*/
|
||||
this.hasUpdate = false;
|
||||
|
||||
/**
|
||||
@@ -58,15 +58,15 @@ Phaser.Plugin = function (game, parent) {
|
||||
this.hasPostUpdate = false;
|
||||
|
||||
/**
|
||||
* @property {boolean} hasRender - A flag to indicate if this plugin has a render method.
|
||||
* @default
|
||||
*/
|
||||
* @property {boolean} hasRender - A flag to indicate if this plugin has a render method.
|
||||
* @default
|
||||
*/
|
||||
this.hasRender = false;
|
||||
|
||||
/**
|
||||
* @property {boolean} hasPostRender - A flag to indicate if this plugin has a postRender method.
|
||||
* @default
|
||||
*/
|
||||
* @property {boolean} hasPostRender - A flag to indicate if this plugin has a postRender method.
|
||||
* @default
|
||||
*/
|
||||
this.hasPostRender = false;
|
||||
|
||||
};
|
||||
|
||||
+21
-19
@@ -1,3 +1,5 @@
|
||||
/* jshint newcap: false */
|
||||
|
||||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2013 Photon Storm Ltd.
|
||||
@@ -5,7 +7,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* The Plugin Manager is responsible for the loading, running and unloading of Phaser Plugins.
|
||||
*
|
||||
* @class Phaser.PluginManager
|
||||
* @classdesc Phaser - PluginManager
|
||||
@@ -15,27 +17,27 @@
|
||||
*/
|
||||
Phaser.PluginManager = function(game, parent) {
|
||||
|
||||
/**
|
||||
* @property {Phaser.Game} game - A reference to the currently running game.
|
||||
*/
|
||||
/**
|
||||
* @property {Phaser.Game} game - A reference to the currently running game.
|
||||
*/
|
||||
this.game = game;
|
||||
|
||||
/**
|
||||
* @property {Description} _parent - Description.
|
||||
* @private
|
||||
*/
|
||||
* @property {Description} _parent - Description.
|
||||
* @private
|
||||
*/
|
||||
this._parent = parent;
|
||||
|
||||
/**
|
||||
* @property {array} plugins - Description.
|
||||
*/
|
||||
* @property {array} plugins - Description.
|
||||
*/
|
||||
this.plugins = [];
|
||||
|
||||
/**
|
||||
* @property {array} _pluginsLength - Description.
|
||||
* @private
|
||||
* @default
|
||||
*/
|
||||
* @property {array} _pluginsLength - Description.
|
||||
* @private
|
||||
* @default
|
||||
*/
|
||||
this._pluginsLength = 0;
|
||||
|
||||
};
|
||||
@@ -131,7 +133,7 @@ Phaser.PluginManager.prototype = {
|
||||
*/
|
||||
remove: function (plugin) {
|
||||
|
||||
if (this._pluginsLength == 0)
|
||||
if (this._pluginsLength === 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -170,7 +172,7 @@ Phaser.PluginManager.prototype = {
|
||||
*/
|
||||
preUpdate: function () {
|
||||
|
||||
if (this._pluginsLength == 0)
|
||||
if (this._pluginsLength === 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -193,7 +195,7 @@ Phaser.PluginManager.prototype = {
|
||||
*/
|
||||
update: function () {
|
||||
|
||||
if (this._pluginsLength == 0)
|
||||
if (this._pluginsLength === 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -217,7 +219,7 @@ Phaser.PluginManager.prototype = {
|
||||
*/
|
||||
postUpdate: function () {
|
||||
|
||||
if (this._pluginsLength == 0)
|
||||
if (this._pluginsLength === 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -240,7 +242,7 @@ Phaser.PluginManager.prototype = {
|
||||
*/
|
||||
render: function () {
|
||||
|
||||
if (this._pluginsLength == 0)
|
||||
if (this._pluginsLength === 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -263,7 +265,7 @@ Phaser.PluginManager.prototype = {
|
||||
*/
|
||||
postRender: function () {
|
||||
|
||||
if (this._pluginsLength == 0)
|
||||
if (this._pluginsLength === 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
+244
-239
@@ -12,286 +12,291 @@
|
||||
*/
|
||||
Phaser.Signal = function () {
|
||||
|
||||
/**
|
||||
* @property {Array.<Phaser.SignalBinding>} _bindings - Description.
|
||||
* @private
|
||||
*/
|
||||
this._bindings = [];
|
||||
|
||||
/**
|
||||
* @property {Description} _prevParams - Description.
|
||||
* @private
|
||||
*/
|
||||
this._prevParams = null;
|
||||
/**
|
||||
* @property {Array.<Phaser.SignalBinding>} _bindings - Description.
|
||||
* @private
|
||||
*/
|
||||
this._bindings = [];
|
||||
|
||||
/**
|
||||
* @property {Description} _prevParams - Description.
|
||||
* @private
|
||||
*/
|
||||
this._prevParams = null;
|
||||
|
||||
// enforce dispatch to aways work on same context (#47)
|
||||
var self = this;
|
||||
// enforce dispatch to aways work on same context (#47)
|
||||
var self = this;
|
||||
|
||||
/**
|
||||
* @property {Description} dispatch - Description.
|
||||
*/
|
||||
this.dispatch = function(){
|
||||
Phaser.Signal.prototype.dispatch.apply(self, arguments);
|
||||
};
|
||||
/**
|
||||
* @property {Description} dispatch - Description.
|
||||
*/
|
||||
this.dispatch = function(){
|
||||
Phaser.Signal.prototype.dispatch.apply(self, arguments);
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
Phaser.Signal.prototype = {
|
||||
|
||||
/**
|
||||
/**
|
||||
* If Signal should keep record of previously dispatched parameters and
|
||||
* automatically execute listener during `add()`/`addOnce()` if Signal was
|
||||
* already dispatched before.
|
||||
* @property {boolean} memorize
|
||||
*/
|
||||
memorize: false,
|
||||
* automatically execute listener during `add()`/`addOnce()` if Signal was
|
||||
* already dispatched before.
|
||||
* @property {boolean} memorize
|
||||
*/
|
||||
memorize: false,
|
||||
|
||||
/**
|
||||
* @property {boolean} _shouldPropagate
|
||||
* @private
|
||||
*/
|
||||
_shouldPropagate: true,
|
||||
/**
|
||||
* @property {boolean} _shouldPropagate
|
||||
* @private
|
||||
*/
|
||||
_shouldPropagate: true,
|
||||
|
||||
/**
|
||||
* If Signal is active and should broadcast events.
|
||||
* <p><strong>IMPORTANT:</strong> Setting this property during a dispatch will only affect the next dispatch, if you want to stop the propagation of a signal use `halt()` instead.</p>
|
||||
* @property {boolean} active
|
||||
/**
|
||||
* If Signal is active and should broadcast events.
|
||||
* <p><strong>IMPORTANT:</strong> Setting this property during a dispatch will only affect the next dispatch, if you want to stop the propagation of a signal use `halt()` instead.</p>
|
||||
* @property {boolean} active
|
||||
* @default
|
||||
*/
|
||||
active: true,
|
||||
active: true,
|
||||
|
||||
/**
|
||||
* @method Phaser.Signal#validateListener
|
||||
* @param {function} listener - Signal handler function.
|
||||
* @param {Description} fnName - Description.
|
||||
* @private
|
||||
/**
|
||||
* @method Phaser.Signal#validateListener
|
||||
* @param {function} listener - Signal handler function.
|
||||
* @param {Description} fnName - Description.
|
||||
* @private
|
||||
*/
|
||||
validateListener: function (listener, fnName) {
|
||||
if (typeof listener !== 'function') {
|
||||
throw new Error( 'listener is a required param of {fn}() and should be a Function.'.replace('{fn}', fnName) );
|
||||
}
|
||||
},
|
||||
validateListener: function (listener, fnName) {
|
||||
if (typeof listener !== 'function') {
|
||||
throw new Error( 'listener is a required param of {fn}() and should be a Function.'.replace('{fn}', fnName) );
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* @method Phaser.Signal#_registerListener
|
||||
* @param {function} listener - Signal handler function.
|
||||
* @param {boolean} isOnce - Description.
|
||||
* @param {object} [listenerContext] - Description.
|
||||
* @param {number} [priority] - The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0).
|
||||
* @return {Phaser.SignalBinding} An Object representing the binding between the Signal and listener.
|
||||
* @private
|
||||
*/
|
||||
_registerListener: function (listener, isOnce, listenerContext, priority) {
|
||||
/**
|
||||
* @method Phaser.Signal#_registerListener
|
||||
* @param {function} listener - Signal handler function.
|
||||
* @param {boolean} isOnce - Description.
|
||||
* @param {object} [listenerContext] - Description.
|
||||
* @param {number} [priority] - The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0).
|
||||
* @return {Phaser.SignalBinding} An Object representing the binding between the Signal and listener.
|
||||
* @private
|
||||
*/
|
||||
_registerListener: function (listener, isOnce, listenerContext, priority) {
|
||||
|
||||
var prevIndex = this._indexOfListener(listener, listenerContext),
|
||||
binding;
|
||||
var prevIndex = this._indexOfListener(listener, listenerContext),
|
||||
binding;
|
||||
|
||||
if (prevIndex !== -1) {
|
||||
binding = this._bindings[prevIndex];
|
||||
if (binding.isOnce() !== isOnce) {
|
||||
throw new Error('You cannot add'+ (isOnce? '' : 'Once') +'() then add'+ (!isOnce? '' : 'Once') +'() the same listener without removing the relationship first.');
|
||||
}
|
||||
} else {
|
||||
binding = new Phaser.SignalBinding(this, listener, isOnce, listenerContext, priority);
|
||||
this._addBinding(binding);
|
||||
}
|
||||
if (prevIndex !== -1) {
|
||||
binding = this._bindings[prevIndex];
|
||||
if (binding.isOnce() !== isOnce) {
|
||||
throw new Error('You cannot add'+ (isOnce? '' : 'Once') +'() then add'+ (!isOnce? '' : 'Once') +'() the same listener without removing the relationship first.');
|
||||
}
|
||||
} else {
|
||||
binding = new Phaser.SignalBinding(this, listener, isOnce, listenerContext, priority);
|
||||
this._addBinding(binding);
|
||||
}
|
||||
|
||||
if (this.memorize && this._prevParams){
|
||||
binding.execute(this._prevParams);
|
||||
}
|
||||
if (this.memorize && this._prevParams){
|
||||
binding.execute(this._prevParams);
|
||||
}
|
||||
|
||||
return binding;
|
||||
},
|
||||
return binding;
|
||||
},
|
||||
|
||||
/**
|
||||
* @method Phaser.Signal#_addBinding
|
||||
* @param {Phaser.SignalBinding} binding - An Object representing the binding between the Signal and listener.
|
||||
* @private
|
||||
*/
|
||||
_addBinding: function (binding) {
|
||||
//simplified insertion sort
|
||||
var n = this._bindings.length;
|
||||
do { --n; } while (this._bindings[n] && binding._priority <= this._bindings[n]._priority);
|
||||
this._bindings.splice(n + 1, 0, binding);
|
||||
},
|
||||
/**
|
||||
* @method Phaser.Signal#_addBinding
|
||||
* @param {Phaser.SignalBinding} binding - An Object representing the binding between the Signal and listener.
|
||||
* @private
|
||||
*/
|
||||
_addBinding: function (binding) {
|
||||
//simplified insertion sort
|
||||
var n = this._bindings.length;
|
||||
do { --n; } while (this._bindings[n] && binding._priority <= this._bindings[n]._priority);
|
||||
this._bindings.splice(n + 1, 0, binding);
|
||||
},
|
||||
|
||||
/**
|
||||
* @method Phaser.Signal#_indexOfListener
|
||||
* @param {function} listener - Signal handler function.
|
||||
* @return {number} Description.
|
||||
* @private
|
||||
*/
|
||||
_indexOfListener: function (listener, context) {
|
||||
var n = this._bindings.length,
|
||||
cur;
|
||||
while (n--) {
|
||||
cur = this._bindings[n];
|
||||
if (cur._listener === listener && cur.context === context) {
|
||||
return n;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
},
|
||||
/**
|
||||
* @method Phaser.Signal#_indexOfListener
|
||||
* @param {function} listener - Signal handler function.
|
||||
* @return {number} Description.
|
||||
* @private
|
||||
*/
|
||||
_indexOfListener: function (listener, context) {
|
||||
var n = this._bindings.length,
|
||||
cur;
|
||||
while (n--) {
|
||||
cur = this._bindings[n];
|
||||
if (cur._listener === listener && cur.context === context) {
|
||||
return n;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
},
|
||||
|
||||
/**
|
||||
* Check if listener was attached to Signal.
|
||||
*
|
||||
* @method Phaser.Signal#has
|
||||
* @param {Function} listener - Signal handler function.
|
||||
* @param {Object} [context] - Context on which listener will be executed (object that should represent the `this` variable inside listener function).
|
||||
* @return {boolean} If Signal has the specified listener.
|
||||
*/
|
||||
has: function (listener, context) {
|
||||
return this._indexOfListener(listener, context) !== -1;
|
||||
},
|
||||
/**
|
||||
* Check if listener was attached to Signal.
|
||||
*
|
||||
* @method Phaser.Signal#has
|
||||
* @param {Function} listener - Signal handler function.
|
||||
* @param {Object} [context] - Context on which listener will be executed (object that should represent the `this` variable inside listener function).
|
||||
* @return {boolean} If Signal has the specified listener.
|
||||
*/
|
||||
has: function (listener, context) {
|
||||
return this._indexOfListener(listener, context) !== -1;
|
||||
},
|
||||
|
||||
/**
|
||||
* Add a listener to the signal.
|
||||
*
|
||||
* @method Phaser.Signal#add
|
||||
* @param {function} listener - Signal handler function.
|
||||
* @param {object} [listenerContext] Context on which listener will be executed (object that should represent the `this` variable inside listener function).
|
||||
* @param {number} [priority] The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0).
|
||||
* @return {Phaser.SignalBinding} An Object representing the binding between the Signal and listener.
|
||||
*/
|
||||
add: function (listener, listenerContext, priority) {
|
||||
this.validateListener(listener, 'add');
|
||||
return this._registerListener(listener, false, listenerContext, priority);
|
||||
},
|
||||
/**
|
||||
* Add a listener to the signal.
|
||||
*
|
||||
* @method Phaser.Signal#add
|
||||
* @param {function} listener - Signal handler function.
|
||||
* @param {object} [listenerContext] Context on which listener will be executed (object that should represent the `this` variable inside listener function).
|
||||
* @param {number} [priority] The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0).
|
||||
* @return {Phaser.SignalBinding} An Object representing the binding between the Signal and listener.
|
||||
*/
|
||||
add: function (listener, listenerContext, priority) {
|
||||
this.validateListener(listener, 'add');
|
||||
return this._registerListener(listener, false, listenerContext, priority);
|
||||
},
|
||||
|
||||
/**
|
||||
* Add listener to the signal that should be removed after first execution (will be executed only once).
|
||||
*
|
||||
* @method Phaser.Signal#addOnce
|
||||
* @param {function} listener Signal handler function.
|
||||
* @param {object} [listenerContext] Context on which listener will be executed (object that should represent the `this` variable inside listener function).
|
||||
* @param {number} [priority] The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0)
|
||||
* @return {Phaser.SignalBinding} An Object representing the binding between the Signal and listener.
|
||||
*/
|
||||
addOnce: function (listener, listenerContext, priority) {
|
||||
this.validateListener(listener, 'addOnce');
|
||||
return this._registerListener(listener, true, listenerContext, priority);
|
||||
},
|
||||
/**
|
||||
* Add listener to the signal that should be removed after first execution (will be executed only once).
|
||||
*
|
||||
* @method Phaser.Signal#addOnce
|
||||
* @param {function} listener Signal handler function.
|
||||
* @param {object} [listenerContext] Context on which listener will be executed (object that should represent the `this` variable inside listener function).
|
||||
* @param {number} [priority] The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0)
|
||||
* @return {Phaser.SignalBinding} An Object representing the binding between the Signal and listener.
|
||||
*/
|
||||
addOnce: function (listener, listenerContext, priority) {
|
||||
this.validateListener(listener, 'addOnce');
|
||||
return this._registerListener(listener, true, listenerContext, priority);
|
||||
},
|
||||
|
||||
/**
|
||||
* Remove a single listener from the dispatch queue.
|
||||
*
|
||||
* @method Phaser.Signal#remove
|
||||
* @param {function} listener Handler function that should be removed.
|
||||
* @param {object} [context] Execution context (since you can add the same handler multiple times if executing in a different context).
|
||||
* @return {function} Listener handler function.
|
||||
*/
|
||||
remove: function (listener, context) {
|
||||
/**
|
||||
* Remove a single listener from the dispatch queue.
|
||||
*
|
||||
* @method Phaser.Signal#remove
|
||||
* @param {function} listener Handler function that should be removed.
|
||||
* @param {object} [context] Execution context (since you can add the same handler multiple times if executing in a different context).
|
||||
* @return {function} Listener handler function.
|
||||
*/
|
||||
remove: function (listener, context) {
|
||||
|
||||
this.validateListener(listener, 'remove');
|
||||
this.validateListener(listener, 'remove');
|
||||
|
||||
var i = this._indexOfListener(listener, context);
|
||||
var i = this._indexOfListener(listener, context);
|
||||
|
||||
if (i !== -1)
|
||||
{
|
||||
this._bindings[i]._destroy(); //no reason to a Phaser.SignalBinding exist if it isn't attached to a signal
|
||||
this._bindings.splice(i, 1);
|
||||
}
|
||||
if (i !== -1)
|
||||
{
|
||||
this._bindings[i]._destroy(); //no reason to a Phaser.SignalBinding exist if it isn't attached to a signal
|
||||
this._bindings.splice(i, 1);
|
||||
}
|
||||
|
||||
return listener;
|
||||
return listener;
|
||||
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* Remove all listeners from the Signal.
|
||||
*
|
||||
* @method Phaser.Signal#removeAll
|
||||
*/
|
||||
removeAll: function () {
|
||||
var n = this._bindings.length;
|
||||
while (n--) {
|
||||
this._bindings[n]._destroy();
|
||||
}
|
||||
this._bindings.length = 0;
|
||||
},
|
||||
/**
|
||||
* Remove all listeners from the Signal.
|
||||
*
|
||||
* @method Phaser.Signal#removeAll
|
||||
*/
|
||||
removeAll: function () {
|
||||
var n = this._bindings.length;
|
||||
while (n--) {
|
||||
this._bindings[n]._destroy();
|
||||
}
|
||||
this._bindings.length = 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets the total number of listeneres attached to ths Signal.
|
||||
*
|
||||
* @method Phaser.Signal#getNumListeners
|
||||
* @return {number} Number of listeners attached to the Signal.
|
||||
*/
|
||||
getNumListeners: function () {
|
||||
return this._bindings.length;
|
||||
},
|
||||
/**
|
||||
* Gets the total number of listeneres attached to ths Signal.
|
||||
*
|
||||
* @method Phaser.Signal#getNumListeners
|
||||
* @return {number} Number of listeners attached to the Signal.
|
||||
*/
|
||||
getNumListeners: function () {
|
||||
return this._bindings.length;
|
||||
},
|
||||
|
||||
/**
|
||||
* Stop propagation of the event, blocking the dispatch to next listeners on the queue.
|
||||
* <p><strong>IMPORTANT:</strong> should be called only during signal dispatch, calling it before/after dispatch won't affect signal broadcast.</p>
|
||||
* @see Signal.prototype.disable
|
||||
*
|
||||
* @method Phaser.Signal#halt
|
||||
*/
|
||||
halt: function () {
|
||||
this._shouldPropagate = false;
|
||||
},
|
||||
/**
|
||||
* Stop propagation of the event, blocking the dispatch to next listeners on the queue.
|
||||
* <p><strong>IMPORTANT:</strong> should be called only during signal dispatch, calling it before/after dispatch won't affect signal broadcast.</p>
|
||||
* @see Signal.prototype.disable
|
||||
*
|
||||
* @method Phaser.Signal#halt
|
||||
*/
|
||||
halt: function () {
|
||||
this._shouldPropagate = false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Dispatch/Broadcast Signal to all listeners added to the queue.
|
||||
*
|
||||
* @method Phaser.Signal#dispatch
|
||||
* @param {any} [params] - Parameters that should be passed to each handler.
|
||||
*/
|
||||
dispatch: function (params) {
|
||||
if (! this.active) {
|
||||
return;
|
||||
}
|
||||
/**
|
||||
* Dispatch/Broadcast Signal to all listeners added to the queue.
|
||||
*
|
||||
* @method Phaser.Signal#dispatch
|
||||
* @param {...} [params] - Parameters that should be passed to each handler.
|
||||
*/
|
||||
dispatch: function () {
|
||||
|
||||
var paramsArr = Array.prototype.slice.call(arguments),
|
||||
n = this._bindings.length,
|
||||
bindings;
|
||||
if (!this.active)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.memorize) {
|
||||
this._prevParams = paramsArr;
|
||||
}
|
||||
var paramsArr = Array.prototype.slice.call(arguments);
|
||||
var n = this._bindings.length;
|
||||
var bindings;
|
||||
|
||||
if (! n) {
|
||||
//should come after memorize
|
||||
return;
|
||||
}
|
||||
if (this.memorize)
|
||||
{
|
||||
this._prevParams = paramsArr;
|
||||
}
|
||||
|
||||
bindings = this._bindings.slice(); //clone array in case add/remove items during dispatch
|
||||
this._shouldPropagate = true; //in case `halt` was called before dispatch or during the previous dispatch.
|
||||
if (!n)
|
||||
{
|
||||
// Should come after memorize
|
||||
return;
|
||||
}
|
||||
|
||||
//execute all callbacks until end of the list or until a callback returns `false` or stops propagation
|
||||
//reverse loop since listeners with higher priority will be added at the end of the list
|
||||
do { n--; } while (bindings[n] && this._shouldPropagate && bindings[n].execute(paramsArr) !== false);
|
||||
},
|
||||
bindings = this._bindings.slice(); //clone array in case add/remove items during dispatch
|
||||
this._shouldPropagate = true; //in case `halt` was called before dispatch or during the previous dispatch.
|
||||
|
||||
/**
|
||||
* Forget memorized arguments.
|
||||
* @see Signal.memorize
|
||||
*
|
||||
* @method Phaser.Signal#forget
|
||||
*/
|
||||
forget: function(){
|
||||
this._prevParams = null;
|
||||
},
|
||||
//execute all callbacks until end of the list or until a callback returns `false` or stops propagation
|
||||
//reverse loop since listeners with higher priority will be added at the end of the list
|
||||
do { n--; } while (bindings[n] && this._shouldPropagate && bindings[n].execute(paramsArr) !== false);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Remove all bindings from signal and destroy any reference to external objects (destroy Signal object).
|
||||
* <p><strong>IMPORTANT:</strong> calling any method on the signal instance after calling dispose will throw errors.</p>
|
||||
*
|
||||
* @method Phaser.Signal#dispose
|
||||
*/
|
||||
dispose: function () {
|
||||
this.removeAll();
|
||||
delete this._bindings;
|
||||
delete this._prevParams;
|
||||
},
|
||||
/**
|
||||
* Forget memorized arguments.
|
||||
* @see Signal.memorize
|
||||
*
|
||||
* @method Phaser.Signal#forget
|
||||
*/
|
||||
forget: function(){
|
||||
this._prevParams = null;
|
||||
},
|
||||
|
||||
/**
|
||||
*
|
||||
* @method Phaser.Signal#toString
|
||||
* @return {string} String representation of the object.
|
||||
*/
|
||||
toString: function () {
|
||||
return '[Phaser.Signal active:'+ this.active +' numListeners:'+ this.getNumListeners() +']';
|
||||
}
|
||||
/**
|
||||
* Remove all bindings from signal and destroy any reference to external objects (destroy Signal object).
|
||||
* <p><strong>IMPORTANT:</strong> calling any method on the signal instance after calling dispose will throw errors.</p>
|
||||
*
|
||||
* @method Phaser.Signal#dispose
|
||||
*/
|
||||
dispose: function () {
|
||||
this.removeAll();
|
||||
delete this._bindings;
|
||||
delete this._prevParams;
|
||||
},
|
||||
|
||||
/**
|
||||
*
|
||||
* @method Phaser.Signal#toString
|
||||
* @return {string} String representation of the object.
|
||||
*/
|
||||
toString: function () {
|
||||
return '[Phaser.Signal active:'+ this.active +' numListeners:'+ this.getNumListeners() +']';
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
+16
-16
@@ -25,33 +25,33 @@
|
||||
Phaser.SignalBinding = function (signal, listener, isOnce, listenerContext, priority) {
|
||||
|
||||
/**
|
||||
* @property {Phaser.Game} _listener - Handler function bound to the signal.
|
||||
* @private
|
||||
*/
|
||||
* @property {Phaser.Game} _listener - Handler function bound to the signal.
|
||||
* @private
|
||||
*/
|
||||
this._listener = listener;
|
||||
|
||||
/**
|
||||
* @property {boolean} _isOnce - If binding should be executed just once.
|
||||
* @private
|
||||
*/
|
||||
* @property {boolean} _isOnce - If binding should be executed just once.
|
||||
* @private
|
||||
*/
|
||||
this._isOnce = isOnce;
|
||||
|
||||
/**
|
||||
* @property {object|undefined|null} context - Context on which listener will be executed (object that should represent the `this` variable inside listener function).
|
||||
* @memberof SignalBinding.prototype
|
||||
*/
|
||||
* @property {object|undefined|null} context - Context on which listener will be executed (object that should represent the `this` variable inside listener function).
|
||||
* @memberof SignalBinding.prototype
|
||||
*/
|
||||
this.context = listenerContext;
|
||||
|
||||
/**
|
||||
* @property {Signal} _signal - Reference to Signal object that listener is currently bound to.
|
||||
* @private
|
||||
*/
|
||||
* @property {Signal} _signal - Reference to Signal object that listener is currently bound to.
|
||||
* @private
|
||||
*/
|
||||
this._signal = signal;
|
||||
|
||||
/**
|
||||
* @property {number} _priority - Listener priority.
|
||||
* @private
|
||||
*/
|
||||
* @property {number} _priority - Listener priority.
|
||||
* @private
|
||||
*/
|
||||
this._priority = priority || 0;
|
||||
|
||||
};
|
||||
@@ -62,7 +62,7 @@ Phaser.SignalBinding.prototype = {
|
||||
* If binding is active and should be executed.
|
||||
* @property {boolean} active
|
||||
* @default
|
||||
*/
|
||||
*/
|
||||
active: true,
|
||||
|
||||
/**
|
||||
|
||||
+17
-17
@@ -17,26 +17,26 @@
|
||||
Phaser.Stage = function (game, width, height) {
|
||||
|
||||
/**
|
||||
* @property {Phaser.Game} game - A reference to the currently running Game.
|
||||
*/
|
||||
this.game = game;
|
||||
* @property {Phaser.Game} game - A reference to the currently running Game.
|
||||
*/
|
||||
this.game = game;
|
||||
|
||||
/**
|
||||
* @property {string} game - Background color of the stage (defaults to black). Set via the public backgroundColor property.
|
||||
* @private
|
||||
* @default 'rgb(0,0,0)'
|
||||
*/
|
||||
* @property {string} game - Background color of the stage (defaults to black). Set via the public backgroundColor property.
|
||||
* @private
|
||||
* @default 'rgb(0,0,0)'
|
||||
*/
|
||||
this._backgroundColor = 'rgb(0,0,0)';
|
||||
|
||||
/**
|
||||
* @property {Phaser.Point} offset - Get the offset values (for input and other things).
|
||||
*/
|
||||
this.offset = new Phaser.Point;
|
||||
* @property {Phaser.Point} offset - Get the offset values (for input and other things).
|
||||
*/
|
||||
this.offset = new Phaser.Point();
|
||||
|
||||
/**
|
||||
* @property {HTMLCanvasElement} canvas - Reference to the newly created <canvas> element.
|
||||
*/
|
||||
this.canvas = Phaser.Canvas.create(width, height);
|
||||
this.canvas = Phaser.Canvas.create(width, height);
|
||||
this.canvas.style['-webkit-full-screen'] = 'width: 100%; height: 100%';
|
||||
|
||||
/**
|
||||
@@ -49,7 +49,7 @@ Phaser.Stage = function (game, width, height) {
|
||||
|
||||
/**
|
||||
* @property {number} scaleMode - The current scaleMode.
|
||||
*/
|
||||
*/
|
||||
this.scaleMode = Phaser.StageScaleMode.NO_SCALE;
|
||||
|
||||
/**
|
||||
@@ -126,7 +126,7 @@ Phaser.Stage.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
/**
|
||||
* 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.
|
||||
@@ -138,16 +138,16 @@ Phaser.Stage.prototype = {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.type == 'pagehide' || event.type == 'blur' || document['hidden'] == true || document['webkitHidden'] == true)
|
||||
if (event.type == 'pagehide' || event.type == 'blur' || document['hidden'] === true || document['webkitHidden'] === true)
|
||||
{
|
||||
this.game.paused = true;
|
||||
this.game.paused = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.game.paused = false;
|
||||
this.game.paused = false;
|
||||
}
|
||||
|
||||
},
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
+43
-43
@@ -15,86 +15,86 @@
|
||||
Phaser.State = function () {
|
||||
|
||||
/**
|
||||
* @property {Phaser.Game} game - A reference to the currently running Game.
|
||||
*/
|
||||
* @property {Phaser.Game} game - A reference to the currently running Game.
|
||||
*/
|
||||
this.game = null;
|
||||
|
||||
/**
|
||||
* @property {Phaser.GameObjectFactory} add - Reference to the GameObjectFactory.
|
||||
* @default
|
||||
*/
|
||||
/**
|
||||
* @property {Phaser.GameObjectFactory} add - Reference to the GameObjectFactory.
|
||||
* @default
|
||||
*/
|
||||
this.add = null;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Physics.PhysicsManager} camera - A handy reference to world.camera.
|
||||
* @default
|
||||
*/
|
||||
* @property {Phaser.Camera} camera - A handy reference to world.camera.
|
||||
* @default
|
||||
*/
|
||||
this.camera = null;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Cache} cache - Reference to the assets cache.
|
||||
* @default
|
||||
*/
|
||||
* @property {Phaser.Cache} cache - Reference to the assets cache.
|
||||
* @default
|
||||
*/
|
||||
this.cache = null;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Input} input - Reference to the input manager
|
||||
* @default
|
||||
*/
|
||||
* @property {Phaser.Input} input - Reference to the input manager
|
||||
* @default
|
||||
*/
|
||||
this.input = null;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Loader} load - Reference to the assets loader.
|
||||
* @default
|
||||
*/
|
||||
* @property {Phaser.Loader} load - Reference to the assets loader.
|
||||
* @default
|
||||
*/
|
||||
this.load = null;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Math} math - Reference to the math helper.
|
||||
* @default
|
||||
*/
|
||||
* @property {Phaser.Math} math - Reference to the math helper.
|
||||
* @default
|
||||
*/
|
||||
this.math = null;
|
||||
|
||||
/**
|
||||
* @property {Phaser.SoundManager} sound - Reference to the sound manager.
|
||||
* @default
|
||||
*/
|
||||
* @property {Phaser.SoundManager} sound - Reference to the sound manager.
|
||||
* @default
|
||||
*/
|
||||
this.sound = null;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Stage} stage - Reference to the stage.
|
||||
* @default
|
||||
*/
|
||||
* @property {Phaser.Stage} stage - Reference to the stage.
|
||||
* @default
|
||||
*/
|
||||
this.stage = null;
|
||||
|
||||
/**
|
||||
* @property {Phaser.TimeManager} time - Reference to game clock.
|
||||
* @default
|
||||
*/
|
||||
* @property {Phaser.TimeManager} time - Reference to game clock.
|
||||
* @default
|
||||
*/
|
||||
this.time = null;
|
||||
|
||||
/**
|
||||
* @property {Phaser.TweenManager} tweens - Reference to the tween manager.
|
||||
* @default
|
||||
*/
|
||||
* @property {Phaser.TweenManager} tweens - Reference to the tween manager.
|
||||
* @default
|
||||
*/
|
||||
this.tweens = null;
|
||||
|
||||
/**
|
||||
* @property {Phaser.World} world - Reference to the world.
|
||||
* @default
|
||||
*/
|
||||
* @property {Phaser.World} world - Reference to the world.
|
||||
* @default
|
||||
*/
|
||||
this.world = null;
|
||||
|
||||
/**
|
||||
* @property {Description} add - Description.
|
||||
* @default
|
||||
*/
|
||||
/**
|
||||
* @property {Phaser.Particles} particles - The Particle Manager for the game. It is called during the game update loop and in turn updates any Emitters attached to it.
|
||||
* @default
|
||||
*/
|
||||
this.particles = null;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Physics.PhysicsManager} physics - Reference to the physics manager.
|
||||
* @default
|
||||
*/
|
||||
* @property {Phaser.Physics.PhysicsManager} physics - Reference to the physics manager.
|
||||
* @default
|
||||
*/
|
||||
this.physics = null;
|
||||
|
||||
};
|
||||
|
||||
+259
-310
@@ -1,3 +1,5 @@
|
||||
/* jshint newcap: false */
|
||||
|
||||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2013 Photon Storm Ltd.
|
||||
@@ -14,148 +16,117 @@
|
||||
*/
|
||||
Phaser.StateManager = function (game, pendingState) {
|
||||
|
||||
/**
|
||||
* A reference to the currently running game.
|
||||
* @property {Phaser.Game} game.
|
||||
*/
|
||||
this.game = game;
|
||||
/**
|
||||
* @property {Phaser.Game} game - A reference to the currently running game.
|
||||
*/
|
||||
this.game = game;
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @property {Description} states.
|
||||
*/
|
||||
this.states = {};
|
||||
/**
|
||||
* @property {Object} states - The object containing Phaser.States.
|
||||
*/
|
||||
this.states = {};
|
||||
|
||||
/**
|
||||
* @property {Phaser.State} _pendingState - The state to be switched to in the next frame.
|
||||
* @private
|
||||
*/
|
||||
this._pendingState = null;
|
||||
|
||||
if (pendingState !== null)
|
||||
{
|
||||
this._pendingState = pendingState;
|
||||
}
|
||||
|
||||
/**
|
||||
* @property {boolean} _created - Flag that sets if the State has been created or not.
|
||||
* @private
|
||||
*/
|
||||
this._created = false;
|
||||
|
||||
/**
|
||||
* @property {string} current - The current active State object (defaults to null).
|
||||
*/
|
||||
this.current = '';
|
||||
|
||||
/**
|
||||
* @property {function} onInitCallback - This will be called when the state is started (i.e. set as the current active state).
|
||||
*/
|
||||
this.onInitCallback = null;
|
||||
|
||||
/**
|
||||
* @property {function} onPreloadCallback - This will be called when init states (loading assets...).
|
||||
*/
|
||||
this.onPreloadCallback = null;
|
||||
|
||||
/**
|
||||
* @property {function} onCreateCallback - This will be called when create states (setup states...).
|
||||
*/
|
||||
this.onCreateCallback = null;
|
||||
|
||||
/**
|
||||
* @property {function} onUpdateCallback - This will be called when State is updated, this doesn't happen during load (@see onLoadUpdateCallback).
|
||||
*/
|
||||
this.onUpdateCallback = null;
|
||||
|
||||
/**
|
||||
* @property {function} onRenderCallback - This will be called when the State is rendered, this doesn't happen during load (see onLoadRenderCallback).
|
||||
*/
|
||||
this.onRenderCallback = null;
|
||||
|
||||
/**
|
||||
* @property {function} onPreRenderCallback - This will be called before the State is rendered and before the stage is cleared.
|
||||
*/
|
||||
this.onPreRenderCallback = null;
|
||||
|
||||
/**
|
||||
* @property {function} onLoadUpdateCallback - This will be called when the State is updated but only during the load process.
|
||||
*/
|
||||
this.onLoadUpdateCallback = null;
|
||||
|
||||
/**
|
||||
* @property {function} onLoadRenderCallback - This will be called when the State is rendered but only during the load process.
|
||||
*/
|
||||
this.onLoadRenderCallback = null;
|
||||
|
||||
/**
|
||||
* @property {function} onPausedCallback - This will be called when the state is paused.
|
||||
*/
|
||||
this.onPausedCallback = null;
|
||||
|
||||
/**
|
||||
* @property {function} onShutDownCallback - This will be called when the state is shut down (i.e. swapped to another state).
|
||||
*/
|
||||
this.onShutDownCallback = null;
|
||||
|
||||
if (pendingState !== null)
|
||||
{
|
||||
this._pendingState = pendingState;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Phaser.StateManager.prototype = {
|
||||
|
||||
/**
|
||||
* A reference to the currently running game.
|
||||
* @property {Phaser.Game} game.
|
||||
*/
|
||||
game: null,
|
||||
|
||||
/**
|
||||
* The state to be switched to in the next frame.
|
||||
* @property {State} _pendingState
|
||||
* @private
|
||||
*/
|
||||
_pendingState: null,
|
||||
/**
|
||||
* The Boot handler is called by Phaser.Game when it first starts up.
|
||||
* @method Phaser.StateManager#boot
|
||||
* @private
|
||||
*/
|
||||
boot: function () {
|
||||
|
||||
/**
|
||||
* Flag that sets if the State has been created or not.
|
||||
* @property {boolean}_created
|
||||
* @private
|
||||
*/
|
||||
_created: false,
|
||||
if (this._pendingState !== null)
|
||||
{
|
||||
if (typeof this._pendingState === 'string')
|
||||
{
|
||||
// State was already added, so just start it
|
||||
this.start(this._pendingState, false, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.add('default', this._pendingState, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* The state to be switched to in the next frame.
|
||||
* @property {Description} states
|
||||
*/
|
||||
states: {},
|
||||
}
|
||||
|
||||
/**
|
||||
* The current active State object (defaults to null).
|
||||
* @property {string} current
|
||||
*/
|
||||
current: '',
|
||||
|
||||
/**
|
||||
* This will be called when the state is started (i.e. set as the current active state).
|
||||
* @property {function} onInitCallback
|
||||
*/
|
||||
onInitCallback: null,
|
||||
},
|
||||
|
||||
/**
|
||||
* This will be called when init states (loading assets...).
|
||||
* @property {function} onPreloadCallback
|
||||
*/
|
||||
onPreloadCallback: null,
|
||||
|
||||
/**
|
||||
* This will be called when create states (setup states...).
|
||||
* @property {function} onCreateCallback
|
||||
*/
|
||||
onCreateCallback: null,
|
||||
|
||||
/**
|
||||
* This will be called when State is updated, this doesn't happen during load (@see onLoadUpdateCallback).
|
||||
* @property {function} onUpdateCallback
|
||||
*/
|
||||
onUpdateCallback: null,
|
||||
|
||||
/**
|
||||
* This will be called when the State is rendered, this doesn't happen during load (see onLoadRenderCallback).
|
||||
* @property {function} onRenderCallback
|
||||
*/
|
||||
onRenderCallback: null,
|
||||
|
||||
/**
|
||||
* This will be called before the State is rendered and before the stage is cleared.
|
||||
* @property {function} onPreRenderCallback
|
||||
*/
|
||||
onPreRenderCallback: null,
|
||||
|
||||
/**
|
||||
* This will be called when the State is updated but only during the load process.
|
||||
* @property {function} onLoadUpdateCallback
|
||||
*/
|
||||
onLoadUpdateCallback: null,
|
||||
|
||||
/**
|
||||
* This will be called when the State is rendered but only during the load process.
|
||||
* @property {function} onLoadRenderCallback
|
||||
*/
|
||||
onLoadRenderCallback: null,
|
||||
|
||||
/**
|
||||
* This will be called when states paused.
|
||||
* @property {function} onPausedCallback
|
||||
*/
|
||||
onPausedCallback: null,
|
||||
|
||||
/**
|
||||
* This will be called when the state is shut down (i.e. swapped to another state).
|
||||
* @property {function} onShutDownCallback
|
||||
*/
|
||||
onShutDownCallback: null,
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @method Phaser.StateManager#boot
|
||||
* @private
|
||||
*/
|
||||
boot: function () {
|
||||
|
||||
// console.log('Phaser.StateManager.boot');
|
||||
|
||||
if (this._pendingState !== null)
|
||||
{
|
||||
// console.log('_pendingState found');
|
||||
// console.log(typeof this._pendingState);
|
||||
|
||||
if (typeof this._pendingState === 'string')
|
||||
{
|
||||
// State was already added, so just start it
|
||||
this.start(this._pendingState, false, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.add('default', this._pendingState, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
/**
|
||||
* Add a new State.
|
||||
* @method Phaser.StateManager#add
|
||||
* @param key {string} - A unique key you use to reference this state, i.e. "MainMenu", "Level1".
|
||||
@@ -166,78 +137,69 @@ Phaser.StateManager.prototype = {
|
||||
|
||||
if (typeof autoStart === "undefined") { autoStart = false; }
|
||||
|
||||
// console.log('Phaser.StateManager.addState', key);
|
||||
// console.log(typeof state);
|
||||
// console.log('autoStart?', autoStart);
|
||||
var newState;
|
||||
|
||||
var newState;
|
||||
if (state instanceof Phaser.State)
|
||||
{
|
||||
newState = state;
|
||||
}
|
||||
else if (typeof state === 'object')
|
||||
{
|
||||
newState = state;
|
||||
newState.game = this.game;
|
||||
}
|
||||
else if (typeof state === 'function')
|
||||
{
|
||||
newState = new state(this.game);
|
||||
}
|
||||
|
||||
if (state instanceof Phaser.State)
|
||||
{
|
||||
// console.log('Phaser.StateManager.addState: Phaser.State given');
|
||||
newState = state;
|
||||
}
|
||||
else if (typeof state === 'object')
|
||||
{
|
||||
// console.log('Phaser.StateManager.addState: Object given');
|
||||
newState = state;
|
||||
newState.game = this.game;
|
||||
}
|
||||
else if (typeof state === 'function')
|
||||
{
|
||||
// console.log('Phaser.StateManager.addState: Function given');
|
||||
newState = new state(this.game);
|
||||
}
|
||||
this.states[key] = newState;
|
||||
|
||||
this.states[key] = newState;
|
||||
if (autoStart)
|
||||
{
|
||||
if (this.game.isBooted)
|
||||
{
|
||||
this.start(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._pendingState = key;
|
||||
}
|
||||
}
|
||||
|
||||
if (autoStart)
|
||||
{
|
||||
if (this.game.isBooted)
|
||||
{
|
||||
// console.log('Game is booted, so we can start the state now');
|
||||
this.start(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
// console.log('Game is NOT booted, so set the current state as pending');
|
||||
this._pendingState = key;
|
||||
}
|
||||
}
|
||||
|
||||
return newState;
|
||||
return newState;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
/**
|
||||
* Delete the given state.
|
||||
* @method Phaser.StateManager#remove
|
||||
* @param {string} key - A unique key you use to reference this state, i.e. "MainMenu", "Level1".
|
||||
*/
|
||||
remove: function (key) {
|
||||
|
||||
if (this.current == key)
|
||||
{
|
||||
this.callbackContext = null;
|
||||
if (this.current == key)
|
||||
{
|
||||
this.callbackContext = null;
|
||||
|
||||
this.onInitCallback = null;
|
||||
this.onShutDownCallback = null;
|
||||
this.onInitCallback = null;
|
||||
this.onShutDownCallback = null;
|
||||
|
||||
this.onPreloadCallback = null;
|
||||
this.onLoadRenderCallback = null;
|
||||
this.onLoadUpdateCallback = null;
|
||||
this.onCreateCallback = null;
|
||||
this.onUpdateCallback = null;
|
||||
this.onRenderCallback = null;
|
||||
this.onPausedCallback = null;
|
||||
this.onDestroyCallback = null;
|
||||
}
|
||||
this.onPreloadCallback = null;
|
||||
this.onLoadRenderCallback = null;
|
||||
this.onLoadUpdateCallback = null;
|
||||
this.onCreateCallback = null;
|
||||
this.onUpdateCallback = null;
|
||||
this.onRenderCallback = null;
|
||||
this.onPausedCallback = null;
|
||||
this.onDestroyCallback = null;
|
||||
}
|
||||
|
||||
delete this.states[key];
|
||||
delete this.states[key];
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
/**
|
||||
* Start the given state
|
||||
* @method Phaser.StateManager#start
|
||||
* @param {string} key - The key of the state you want to start.
|
||||
@@ -246,84 +208,75 @@ Phaser.StateManager.prototype = {
|
||||
*/
|
||||
start: function (key, clearWorld, clearCache) {
|
||||
|
||||
// console.log('Phaser.StateManager.start', key);
|
||||
// console.log(this);
|
||||
// console.log(this.callbackContext);
|
||||
|
||||
if (typeof clearWorld === "undefined") { clearWorld = true; }
|
||||
if (typeof clearCache === "undefined") { clearCache = false; }
|
||||
|
||||
if (this.game.isBooted == false)
|
||||
if (this.game.isBooted === false)
|
||||
{
|
||||
// console.log('Game is NOT booted, so set the requested state as pending');
|
||||
this._pendingState = key;
|
||||
return;
|
||||
this._pendingState = key;
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.checkState(key) == false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Already got a state running?
|
||||
if (this.current)
|
||||
{
|
||||
this.onShutDownCallback.call(this.callbackContext, this.game);
|
||||
}
|
||||
if (this.checkState(key) === false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Already got a state running?
|
||||
if (this.current)
|
||||
{
|
||||
this.onShutDownCallback.call(this.callbackContext, this.game);
|
||||
}
|
||||
|
||||
if (clearWorld)
|
||||
{
|
||||
this.game.tweens.removeAll();
|
||||
if (clearWorld)
|
||||
{
|
||||
this.game.tweens.removeAll();
|
||||
|
||||
this.game.world.destroy();
|
||||
this.game.world.destroy();
|
||||
|
||||
if (clearCache == true)
|
||||
{
|
||||
this.game.cache.destroy();
|
||||
}
|
||||
}
|
||||
if (clearCache === true)
|
||||
{
|
||||
this.game.cache.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
this.setCurrentState(key);
|
||||
}
|
||||
this.setCurrentState(key);
|
||||
}
|
||||
|
||||
if (this.onPreloadCallback)
|
||||
{
|
||||
// console.log('Preload Callback found');
|
||||
this.game.load.reset();
|
||||
this.onPreloadCallback.call(this.callbackContext, this.game);
|
||||
|
||||
// Is the loader empty?
|
||||
if (this.game.load.queueSize == 0)
|
||||
if (this.game.load.queueSize === 0)
|
||||
{
|
||||
// console.log('Loader queue empty');
|
||||
this.game.loadComplete();
|
||||
}
|
||||
else
|
||||
{
|
||||
// console.log('Loader started');
|
||||
// Start the loader going as we have something in the queue
|
||||
this.game.load.start();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// console.log('Preload callback not found');
|
||||
// No init? Then there was nothing to load either
|
||||
this.game.loadComplete();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Used by onInit and onShutdown when those functions don't exist on the state
|
||||
|
||||
/**
|
||||
* Used by onInit and onShutdown when those functions don't exist on the state
|
||||
* @method Phaser.StateManager#dummy
|
||||
* @private
|
||||
*/
|
||||
dummy: function () {
|
||||
},
|
||||
|
||||
/**
|
||||
/**
|
||||
* Description.
|
||||
* @method Phaser.StateManager#checkState
|
||||
* @param {string} key - The key of the state you want to check.
|
||||
@@ -331,37 +284,37 @@ Phaser.StateManager.prototype = {
|
||||
*/
|
||||
checkState: function (key) {
|
||||
|
||||
if (this.states[key])
|
||||
{
|
||||
var valid = false;
|
||||
if (this.states[key])
|
||||
{
|
||||
var valid = false;
|
||||
|
||||
if (this.states[key]['preload']) { valid = true; }
|
||||
if (this.states[key]['preload']) { valid = true; }
|
||||
|
||||
if (valid == false && this.states[key]['loadRender']) { valid = true; }
|
||||
if (valid == false && this.states[key]['loadUpdate']) { valid = true; }
|
||||
if (valid == false && this.states[key]['create']) { valid = true; }
|
||||
if (valid == false && this.states[key]['update']) { valid = true; }
|
||||
if (valid == false && this.states[key]['preRender']) { valid = true; }
|
||||
if (valid == false && this.states[key]['render']) { valid = true; }
|
||||
if (valid == false && this.states[key]['paused']) { valid = true; }
|
||||
if (valid === false && this.states[key]['loadRender']) { valid = true; }
|
||||
if (valid === false && this.states[key]['loadUpdate']) { valid = true; }
|
||||
if (valid === false && this.states[key]['create']) { valid = true; }
|
||||
if (valid === false && this.states[key]['update']) { valid = true; }
|
||||
if (valid === false && this.states[key]['preRender']) { valid = true; }
|
||||
if (valid === false && this.states[key]['render']) { valid = true; }
|
||||
if (valid === false && this.states[key]['paused']) { valid = true; }
|
||||
|
||||
if (valid == false)
|
||||
{
|
||||
console.warn("Invalid Phaser State object given. Must contain at least a one of the required functions.");
|
||||
return false;
|
||||
}
|
||||
if (valid === false)
|
||||
{
|
||||
console.warn("Invalid Phaser State object given. Must contain at least a one of the required functions.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
console.warn("Phaser.StateManager - No state found with the key: " + key);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
console.warn("Phaser.StateManager - No state found with the key: " + key);
|
||||
return false;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
/**
|
||||
* Links game properties to the State given by the key.
|
||||
* @method Phaser.StateManager#link
|
||||
* @param {string} key - State key.
|
||||
@@ -369,7 +322,6 @@ Phaser.StateManager.prototype = {
|
||||
*/
|
||||
link: function (key) {
|
||||
|
||||
// console.log('linked');
|
||||
this.states[key].game = this.game;
|
||||
this.states[key].add = this.game.add;
|
||||
this.states[key].camera = this.game.camera;
|
||||
@@ -388,19 +340,19 @@ Phaser.StateManager.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
/**
|
||||
* Sets the current State. Should not be called directly (use StateManager.start)
|
||||
* @method Phaser.StateManager#setCurrentState
|
||||
* @param {string} key - State key.
|
||||
* @protected
|
||||
*/
|
||||
setCurrentState: function (key) {
|
||||
setCurrentState: function (key) {
|
||||
|
||||
this.callbackContext = this.states[key];
|
||||
|
||||
this.link(key);
|
||||
|
||||
// Used when the state is set as being the current active state
|
||||
// Used when the state is set as being the current active state
|
||||
this.onInitCallback = this.states[key]['init'] || this.dummy;
|
||||
|
||||
this.onPreloadCallback = this.states[key]['preload'] || null;
|
||||
@@ -412,102 +364,99 @@ Phaser.StateManager.prototype = {
|
||||
this.onRenderCallback = this.states[key]['render'] || null;
|
||||
this.onPausedCallback = this.states[key]['paused'] || null;
|
||||
|
||||
// Used when the state is no longer the current active state
|
||||
// Used when the state is no longer the current active state
|
||||
this.onShutDownCallback = this.states[key]['shutdown'] || this.dummy;
|
||||
|
||||
this.current = key;
|
||||
this._created = false;
|
||||
this.current = key;
|
||||
this._created = false;
|
||||
|
||||
this.onInitCallback.call(this.callbackContext, this.game);
|
||||
this.onInitCallback.call(this.callbackContext, this.game);
|
||||
|
||||
},
|
||||
},
|
||||
|
||||
/**
|
||||
* @method Phaser.StateManager#loadComplete
|
||||
/**
|
||||
* @method Phaser.StateManager#loadComplete
|
||||
* @protected
|
||||
*/
|
||||
*/
|
||||
loadComplete: function () {
|
||||
|
||||
// console.log('Phaser.StateManager.loadComplete');
|
||||
|
||||
if (this._created == false && this.onCreateCallback)
|
||||
if (this._created === false && this.onCreateCallback)
|
||||
{
|
||||
// console.log('Create callback found');
|
||||
this._created = true;
|
||||
this._created = true;
|
||||
this.onCreateCallback.call(this.callbackContext, this.game);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._created = true;
|
||||
this._created = true;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* @method Phaser.StateManager#update
|
||||
/**
|
||||
* @method Phaser.StateManager#update
|
||||
* @protected
|
||||
*/
|
||||
*/
|
||||
update: function () {
|
||||
|
||||
if (this._created && this.onUpdateCallback)
|
||||
{
|
||||
this.onUpdateCallback.call(this.callbackContext, this.game);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.onLoadUpdateCallback)
|
||||
{
|
||||
this.onLoadUpdateCallback.call(this.callbackContext, this.game);
|
||||
}
|
||||
}
|
||||
if (this._created && this.onUpdateCallback)
|
||||
{
|
||||
this.onUpdateCallback.call(this.callbackContext, this.game);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.onLoadUpdateCallback)
|
||||
{
|
||||
this.onLoadUpdateCallback.call(this.callbackContext, this.game);
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* @method Phaser.StateManager#preRender
|
||||
/**
|
||||
* @method Phaser.StateManager#preRender
|
||||
* @protected
|
||||
*/
|
||||
*/
|
||||
preRender: function () {
|
||||
|
||||
if (this.onPreRenderCallback)
|
||||
{
|
||||
this.onPreRenderCallback.call(this.callbackContext, this.game);
|
||||
}
|
||||
if (this.onPreRenderCallback)
|
||||
{
|
||||
this.onPreRenderCallback.call(this.callbackContext, this.game);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* @method Phaser.StateManager#render
|
||||
/**
|
||||
* @method Phaser.StateManager#render
|
||||
* @protected
|
||||
*/
|
||||
*/
|
||||
render: function () {
|
||||
|
||||
if (this._created && this.onRenderCallback)
|
||||
{
|
||||
if (this.game.renderType === Phaser.CANVAS)
|
||||
{
|
||||
this.game.context.save();
|
||||
this.game.context.setTransform(1, 0, 0, 1, 0, 0);
|
||||
}
|
||||
if (this._created && this.onRenderCallback)
|
||||
{
|
||||
if (this.game.renderType === Phaser.CANVAS)
|
||||
{
|
||||
this.game.context.save();
|
||||
this.game.context.setTransform(1, 0, 0, 1, 0, 0);
|
||||
}
|
||||
|
||||
this.onRenderCallback.call(this.callbackContext, this.game);
|
||||
this.onRenderCallback.call(this.callbackContext, this.game);
|
||||
|
||||
if (this.game.renderType === Phaser.CANVAS)
|
||||
{
|
||||
this.game.context.restore();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.onLoadRenderCallback)
|
||||
{
|
||||
this.onLoadRenderCallback.call(this.callbackContext, this.game);
|
||||
}
|
||||
}
|
||||
if (this.game.renderType === Phaser.CANVAS)
|
||||
{
|
||||
this.game.context.restore();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.onLoadRenderCallback)
|
||||
{
|
||||
this.onLoadRenderCallback.call(this.callbackContext, this.game);
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
/**
|
||||
* Nuke the entire game from orbit
|
||||
* @method Phaser.StateManager#destroy
|
||||
*/
|
||||
|
||||
+32
-32
@@ -21,7 +21,7 @@ Phaser.World = function (game) {
|
||||
|
||||
/**
|
||||
* @property {Phaser.Point} scale - Replaces the PIXI.Point with a slightly more flexible one.
|
||||
*/
|
||||
*/
|
||||
this.scale = new Phaser.Point(1, 1);
|
||||
|
||||
/**
|
||||
@@ -29,20 +29,20 @@ Phaser.World = function (game) {
|
||||
* By default we set the Bounds to be from 0,0 to Game.width,Game.height. I.e. it will match the size given to the game constructor with 0,0 representing the top-left of the display.
|
||||
* However 0,0 is actually the center of the world, and if you rotate or scale the world all of that will happen from 0,0.
|
||||
* So if you want to make a game in which the world itself will rotate you should adjust the bounds so that 0,0 is the center point, i.e. set them to -1000,-1000,2000,2000 for a 2000x2000 sized world centered around 0,0.
|
||||
* @property {Phaser.Rectangle} bounds - Bound of this world that objects can not escape from.
|
||||
*/
|
||||
this.bounds = new Phaser.Rectangle(0, 0, game.width, game.height);
|
||||
* @property {Phaser.Rectangle} bounds - Bound of this world that objects can not escape from.
|
||||
*/
|
||||
this.bounds = new Phaser.Rectangle(0, 0, game.width, game.height);
|
||||
|
||||
/**
|
||||
* @property {Phaser.Camera} camera - Camera instance.
|
||||
*/
|
||||
this.camera = null;
|
||||
* @property {Phaser.Camera} camera - Camera instance.
|
||||
*/
|
||||
this.camera = null;
|
||||
|
||||
/**
|
||||
* @property {number} currentRenderOrderID - Reset each frame, keeps a count of the total number of objects updated.
|
||||
*/
|
||||
this.currentRenderOrderID = 0;
|
||||
|
||||
* @property {number} currentRenderOrderID - Reset each frame, keeps a count of the total number of objects updated.
|
||||
*/
|
||||
this.currentRenderOrderID = 0;
|
||||
|
||||
};
|
||||
|
||||
Phaser.World.prototype = Object.create(Phaser.Group.prototype);
|
||||
@@ -71,27 +71,27 @@ Phaser.World.prototype.boot = function () {
|
||||
*/
|
||||
Phaser.World.prototype.update = function () {
|
||||
|
||||
this.currentRenderOrderID = 0;
|
||||
this.currentRenderOrderID = 0;
|
||||
|
||||
if (this.game.stage._stage.first._iNext)
|
||||
{
|
||||
var currentNode = this.game.stage._stage.first._iNext;
|
||||
if (this.game.stage._stage.first._iNext)
|
||||
{
|
||||
var currentNode = this.game.stage._stage.first._iNext;
|
||||
var skipChildren;
|
||||
|
||||
do
|
||||
{
|
||||
|
||||
do
|
||||
{
|
||||
skipChildren = false;
|
||||
|
||||
if (currentNode['preUpdate'])
|
||||
{
|
||||
skipChildren = (currentNode.preUpdate() === false);
|
||||
}
|
||||
if (currentNode['preUpdate'])
|
||||
{
|
||||
skipChildren = (currentNode.preUpdate() === false);
|
||||
}
|
||||
|
||||
if (currentNode['update'])
|
||||
{
|
||||
skipChildren = (currentNode.update() === false) || skipChildren;
|
||||
}
|
||||
|
||||
if (currentNode['update'])
|
||||
{
|
||||
skipChildren = (currentNode.update() === false) || skipChildren;
|
||||
}
|
||||
|
||||
if (skipChildren)
|
||||
{
|
||||
currentNode = currentNode.last._iNext;
|
||||
@@ -100,10 +100,10 @@ Phaser.World.prototype.update = function () {
|
||||
{
|
||||
currentNode = currentNode._iNext;
|
||||
}
|
||||
|
||||
}
|
||||
while (currentNode != this.game.stage._stage.last._iNext)
|
||||
}
|
||||
|
||||
}
|
||||
while (currentNode != this.game.stage._stage.last._iNext)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ Phaser.World.prototype.postUpdate = function () {
|
||||
{
|
||||
var currentNode = this.game.stage._stage.first._iNext;
|
||||
|
||||
do
|
||||
do
|
||||
{
|
||||
if (currentNode['postUpdate'])
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user