Adding docs.

This commit is contained in:
Richard Davey
2013-10-01 15:01:46 +01:00
parent fa15f8015d
commit 305b12d76b
64 changed files with 6268 additions and 2682 deletions
+81 -108
View File
@@ -1,7 +1,7 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2013 Photon Storm Ltd.
* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
* @module Phaser.Camera
*/
@@ -12,95 +12,71 @@
*
* @class Camera
* @constructor
* @param {Phaser.Game} game game reference to the currently running game.
* @param {number} id not being used at the moment, will be when Phaser supports multiple camera
* @param {number} x position of the camera on the X axis
* @param {number} y position of the camera on the Y axis
* @param {number} width the width of the view rectangle
* @param {number} height the height of the view rectangle
* @param {Phaser.Game} game - Game reference to the currently running game.
* @param {number} id - Not being used at the moment, will be when Phaser supports multiple camera
* @param {number} x - Position of the camera on the X axis
* @param {number} y - Position of the camera on the Y axis
* @param {number} width - The width of the view rectangle
* @param {number} height - The height of the view rectangle
*/
Phaser.Camera = function (game, id, x, y, width, height) {
/**
* A reference to the currently running Game.
* @property game
* @public
* @type {Phaser.Game}
*/
/**
* @property {Phaser.Game} game - A reference to the currently running Game.
*/
this.game = game;
/**
* A reference to the game world
* @property world
* @public
* @type {Phaser.World}
*/
/**
* @property {Phaser.World} world - A reference to the game world.
*/
this.world = game.world;
/**
* reserved for future multiple camera set-ups
* @property id
* @public
* @type {number}
*/
/**
* @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)
* 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 view
* @public
* @type {Phaser.Rectangle}
*/
/**
* 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
*/
this.view = new Phaser.Rectangle(x, y, width, height);
/**
* Used by Sprites to work out Camera culling.
* @property screenView
* @public
* @type {Phaser.Rectangle}
*/
* @property {Phaser.Rectangle} screenView - Used by Sprites to work out Camera culling.
*/
this.screenView = new Phaser.Rectangle(x, y, width, height);
/**
* Sprite moving inside this Rectangle will not cause camera moving.
* @property deadzone
* @type {Phaser.Rectangle}
*/
* @property {Phaser.Rectangle} deadzone - Moving inside this Rectangle will not cause camera moving.
*/
this.deadzone = null;
/**
* Whether this camera is visible or not. (default is true)
* @property visible
* @public
* @default true
* @type {bool}
*/
/**
* @property {bool} visible - Whether this camera is visible or not.
* @default
*/
this.visible = true;
/**
* Whether this camera is flush with the World Bounds or not.
* @property atLimit
* @type {bool}
/**
* @property {bool} atLimit - Whether this camera is flush with the World Bounds or not.
*/
this.atLimit = { x: false, y: false };
/**
* If the camera is tracking a Sprite, this is a reference to it, otherwise null
* @property target
* @public
* @type {Phaser.Sprite}
/**
* @property {Phaser.Sprite} target - If the camera is tracking a Sprite, this is a reference to it, otherwise null.
* @default
*/
this.target = null;
/**
* Edge property
* @property edge
* @private
* @type {number}
/**
* @property {number} edge - Edge property. Description.
* @default
*/
this._edge = 0;
@@ -117,7 +93,7 @@ Phaser.Camera.prototype = {
/**
* Tells this camera which sprite to follow.
* @method follow
* @param {Phaser.Sprite} target The object you want the camera to track. Set to null to not follow anything.
* @param {Phaser.Sprite} target - The object you want the camera to track. Set to null to not follow anything.
* @param {number} [style] Leverage one of the existing "deadzone" presets. If you use a custom deadzone, ignore this parameter and manually specify the deadzone after calling follow().
*/
follow: function (target, style) {
@@ -157,8 +133,8 @@ Phaser.Camera.prototype = {
/**
* Move the camera focus to a location instantly.
* @method focusOnXY
* @param {number} x X position.
* @param {number} y Y position.
* @param {number} x - X position.
* @param {number} y - Y position.
*/
focusOnXY: function (x, y) {
@@ -218,7 +194,7 @@ Phaser.Camera.prototype = {
},
/**
* Method called to ensure the camera doesn't venture outside of the game world
* Method called to ensure the camera doesn't venture outside of the game world.
* @method checkWorldBounds
*/
checkWorldBounds: function () {
@@ -257,11 +233,11 @@ Phaser.Camera.prototype = {
/**
* A helper function to set both the X and Y properties of the camera at once
* without having to use game.camera.x and game.camera.y
* without having to use game.camera.x and game.camera.y.
*
* @method setPosition
* @param {number} x X position.
* @param {number} y Y position.
* @param {number} x - X position.
* @param {number} y - Y position.
*/
setPosition: function (x, y) {
@@ -272,11 +248,11 @@ Phaser.Camera.prototype = {
},
/**
* Sets the size of the view rectangle given the width and height in parameters
* Sets the size of the view rectangle given the width and height in parameters.
*
* @method setSize
* @param {number} width The desired width.
* @param {number} height The desired height.
* @param {number} width - The desired width.
* @param {number} height - The desired height.
*/
setSize: function (width, height) {
@@ -287,19 +263,19 @@ Phaser.Camera.prototype = {
};
/**
* Get
* @return {number} The x position.
*//**
* Sets the camera's x position and clamp it if it's outside the world bounds.
* @param {number} value - The x position.
*/
Object.defineProperty(Phaser.Camera.prototype, "x", {
/**
* @method x
* @return {Number} The x position
*/
get: function () {
return this.view.x;
},
/**
* @method x
* @return {Number} Sets the camera's x position and clamp it if it's outside the world bounds
*/
set: function (value) {
this.view.x = value;
this.checkWorldBounds();
@@ -307,20 +283,19 @@ Object.defineProperty(Phaser.Camera.prototype, "x", {
});
/**
* Get
* @return {number} The y position.
*//**
* Sets the camera's y position and clamp it if it's outside the world bounds.
* @param {number} value - The y position.
*/
Object.defineProperty(Phaser.Camera.prototype, "y", {
/**
* @method y
* @return {Number} The y position
*/
get: function () {
return this.view.y;
},
/**
* @method y
* @return {Number} Sets the camera's y position and clamp it if it's outside the world bounds
*/
set: function (value) {
this.view.y = value;
this.checkWorldBounds();
@@ -328,40 +303,38 @@ Object.defineProperty(Phaser.Camera.prototype, "y", {
});
/**
* Returns the width of the view rectangle, in pixels.
* @return {number} The width of the view rectangle, in pixels.
*//**
* Sets the width of the view rectangle.
* @param {number} value - Width of the view rectangle.
*/
Object.defineProperty(Phaser.Camera.prototype, "width", {
/**
* @method width
* @return {Number} The width of the view rectangle, in pixels
*/
get: function () {
return this.view.width;
},
/**
* @method width
* @return {Number} Sets the width of the view rectangle
*/
set: function (value) {
this.view.width = value;
}
});
/**
* Returns the height of the view rectangle, in pixels.
* @return {number} The height of the view rectangle, in pixels.
*//**
* Sets the height of the view rectangle.
* @param {number} value - Height of the view rectangle.
*/
Object.defineProperty(Phaser.Camera.prototype, "height", {
/**
* @method height
* @return {Number} The height of the view rectangle, in pixels
*/
get: function () {
return this.view.height;
},
/**
* @method height
* @return {Number} Sets the height of the view rectangle
*/
set: function (value) {
this.view.height = value;
}
+123 -109
View File
@@ -1,28 +1,27 @@
/**
* Phaser.Game
*
* This is where the magic happens. The Game object is the heart of your game,
* providing quick access to common functions and handling the boot process.
*
* "Hell, there are no rules here - we're trying to accomplish something."
* Thomas A. Edison
*
* @package Phaser.Game
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2013 Photon Storm Ltd.
* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2013 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
* @module Phaser.Game
*/
/**
* Game constructor
*
* Instantiate a new <code>Phaser.Game</code> object.
*
* @class
* @classdesc This is where the magic happens. The Game object is the heart of your game,
* providing quick access to common functions and handling the boot process.
* <p>"Hell, there are no rules here - we're trying to accomplish something."</p><br>
* Thomas A. Edison
* @constructor
* @param width {number} The width of your game in game pixels.
* @param height {number} The height of your game in game pixels.
* @param renderer {number} Which renderer to use (canvas or webgl)
* @param parent {string} ID of its parent DOM element.
* @param {number} width - The width of your game in game pixels.
* @param {number} height - The height of your game in game pixels.
* @param {number} renderer -Which renderer to use (canvas or webgl)
* @param {HTMLElement} parent -The Games DOM parent.
* @param {Description} state - Description.
* @param {bool} transparent - Use a transparent canvas background or not.
* @param {bool} antialias - Anti-alias graphics.
*/
Phaser.Game = function (width, height, renderer, parent, state, transparent, antialias) {
@@ -32,205 +31,199 @@ Phaser.Game = function (width, height, renderer, parent, state, transparent, ant
parent = parent || '';
state = state || null;
if (typeof transparent == 'undefined') { transparent = false; }
antialias = typeof antialias === 'undefined' ? true : antialias;
if (typeof antialias == 'undefined') { antialias = false; }
/**
* Phaser Game ID (for when Pixi supports multiple instances)
* @type {number}
* @property {number} id - Phaser Game ID (for when Pixi supports multiple instances).
*/
this.id = Phaser.GAMES.push(this) - 1;
/**
* The Games DOM parent.
* @type {HTMLElement}
* @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?
/**
* The Game width (in pixels).
* @type {number}
* @property {number} width - The Game width (in pixels).
*/
this.width = width;
/**
* The Game height (in pixels).
* @type {number}
* @property {number} height - The Game height (in pixels).
*/
this.height = height;
/**
* Use a transparent canvas background or not.
* @type {boolean}
* @property {bool} transparent - Use a transparent canvas background or not.
*/
this.transparent = transparent;
/**
* Anti-alias graphics (in WebGL this helps with edges, in Canvas2D it retains pixel-art quality)
* @type {boolean}
* @property {bool} antialias - Anti-alias graphics (in WebGL this helps with edges, in Canvas2D it retains pixel-art quality).
*/
this.antialias = antialias;
/**
* The Pixi Renderer
* @type {number}
* @property {number} renderer - The Pixi Renderer
* @default
*/
this.renderer = null;
/**
* The StateManager.
* @type {Phaser.StateManager}
*/
/**
* @property {number} state - The StateManager.
*/
this.state = new Phaser.StateManager(this, state);
/**
* Is game paused?
* @type {bool}
* @property {bool} _paused - Is game paused?
* @private
* @default
*/
this._paused = false;
/**
* The Renderer this Phaser.Game will use. Either Phaser.RENDERER_AUTO, Phaser.RENDERER_CANVAS or Phaser.RENDERER_WEBGL
* @type {number}
* @property {number} renderType - The Renderer this Phaser.Game will use. Either Phaser.RENDERER_AUTO, Phaser.RENDERER_CANVAS or Phaser.RENDERER_WEBGL.
*/
this.renderType = renderer;
/**
* Whether load complete loading or not.
* @type {bool}
* @property {bool} _loadComplete - Whether load complete loading or not.
* @private
* @default
*/
this._loadComplete = false;
/**
* Whether the game engine is booted, aka available.
* @type {bool}
* @property {bool} isBooted - Whether the game engine is booted, aka available.
* @default
*/
this.isBooted = false;
/**
* Is game running or paused?
* @type {bool}
* @property {bool} id -Is game running or paused?
* @default
*/
this.isRunning = false;
/**
* Automatically handles the core game loop via requestAnimationFrame or setTimeout
* @type {Phaser.RequestAnimationFrame}
* @property {Phaser.RequestAnimationFrame} raf - Automatically handles the core game loop via requestAnimationFrame or setTimeout
* @default
*/
this.raf = null;
/**
* Reference to the GameObject Factory.
* @type {Phaser.GameObjectFactory}
*/
/**
* @property {Phaser.GameObjectFactory} add - Reference to the GameObject Factory.
* @default
*/
this.add = null;
/**
* Reference to the assets cache.
* @type {Phaser.Cache}
*/
* @property {Phaser.Cache} cache - Reference to the assets cache.
* @default
*/
this.cache = null;
/**
* Reference to the input manager
* @type {Phaser.Input}
*/
* @property {Phaser.Input} input - Reference to the input manager
* @default
*/
this.input = null;
/**
* Reference to the assets loader.
* @type {Phaser.Loader}
*/
* @property {Phaser.Loader} load - Reference to the assets loader.
* @default
*/
this.load = null;
/**
* Reference to the math helper.
* @type {Phaser.GameMath}
*/
* @property {Phaser.GameMath} math - Reference to the math helper.
* @default
*/
this.math = null;
/**
* Reference to the network class.
* @type {Phaser.Net}
*/
* @property {Phaser.Net} net - Reference to the network class.
* @default
*/
this.net = null;
/**
* Reference to the sound manager.
* @type {Phaser.SoundManager}
*/
* @property {Phaser.SoundManager} sound - Reference to the sound manager.
* @default
*/
this.sound = null;
/**
* Reference to the stage.
* @type {Phaser.Stage}
*/
* @property {Phaser.Stage} stage - Reference to the stage.
* @default
*/
this.stage = null;
/**
* Reference to game clock.
* @type {Phaser.TimeManager}
*/
* @property {Phaser.TimeManager} time - Reference to game clock.
* @default
*/
this.time = null;
/**
* Reference to the tween manager.
* @type {Phaser.TweenManager}
*/
* @property {Phaser.TweenManager} tweens - Reference to the tween manager.
* @default
*/
this.tweens = null;
/**
* Reference to the world.
* @type {Phaser.World}
*/
* @property {Phaser.World} world - Reference to the world.
* @default
*/
this.world = null;
/**
* Reference to the physics manager.
* @type {Phaser.Physics.PhysicsManager}
*/
* @property {Phaser.Physics.PhysicsManager} physics - Reference to the physics manager.
* @default
*/
this.physics = null;
/**
* Instance of repeatable random data generator helper.
* @type {Phaser.RandomDataGenerator}
*/
* @property {Phaser.RandomDataGenerator} rnd - Instance of repeatable random data generator helper.
* @default
*/
this.rnd = null;
/**
* Contains device information and capabilities.
* @type {Phaser.Device}
*/
* @property {Phaser.Device} device - Contains device information and capabilities.
* @default
*/
this.device = null;
/**
* A handy reference to world.camera
* @type {Phaser.Camera}
/**
* @property {Phaser.Physics.PhysicsManager} camera - A handy reference to world.camera.
* @default
*/
this.camera = null;
/**
* A handy reference to renderer.view
* @type {HTMLCanvasElement}
/**
* @property {HTMLCanvasElement} canvas - A handy reference to renderer.view.
* @default
*/
this.canvas = null;
/**
* A handy reference to renderer.context (only set for CANVAS games)
* @type {Context}
* @property {Context} context - A handy reference to renderer.context (only set for CANVAS games)
* @default
*/
this.context = null;
/**
* A set of useful debug utilities
* @type {Phaser.Utils.Debug}
/**
* @property {Phaser.Utils.Debug} debug - A set of useful debug utilitie.
* @default
*/
this.debug = null;
/**
* The Particle Manager
* @type {Phaser.Particles}
* @property {Phaser.Particles} particles - The Particle Manager.
* @default
*/
this.particles = null;
@@ -258,9 +251,8 @@ Phaser.Game.prototype = {
/**
* Initialize engine sub modules and start the game.
* @param parent {string} ID of parent Dom element.
* @param width {number} Width of the game screen.
* @param height {number} Height of the game screen.
*
* @method boot
*/
boot: function () {
@@ -336,7 +328,12 @@ Phaser.Game.prototype = {
}
},
/**
* Checks if the device is capable of using the requested renderer and sets it up or an alternative if not.
*
* @method setUpRenderer
*/
setUpRenderer: function () {
if (this.renderType === Phaser.CANVAS || (this.renderType === Phaser.AUTO && this.device.webGL == false))
@@ -370,6 +367,8 @@ Phaser.Game.prototype = {
/**
* Called when the load has finished, after preload was run.
*
* @method loadComplete
*/
loadComplete: function () {
@@ -379,6 +378,12 @@ Phaser.Game.prototype = {
},
/**
* The core game loop.
*
* @method update
* @param {number} time - The current time as provided by RequestAnimationFrame.
*/
update: function (time) {
this.time.update(time);
@@ -409,6 +414,8 @@ Phaser.Game.prototype = {
/**
* Nuke the entire game from orbit
*
* @method destroy
*/
destroy: function () {
@@ -428,6 +435,13 @@ Phaser.Game.prototype = {
};
/**
* Get
* @returns {boolean} - The paused state of the game.
*//**
* Set
* @param {boolean} value - Put the game into a paused state or resume it. A paused game doesn't call any of the subsystems.
*/
Object.defineProperty(Phaser.Game.prototype, "paused", {
get: function () {
+286 -21
View File
@@ -1,3 +1,21 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2013 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
* @module Phaser.Group
*/
/**
* Phaser Group constructor.
* @class Phaser.Group
* @classdesc An Animation instance contains a single animation and the controls to play it.
* It is created by the AnimationManager, consists of Animation.Frame objects and belongs to a single Game Object such as a Sprite.
* @constructor
* @param {Phaser.Game} game - A reference to the currently running game.
* @param {Description} parent - Description.
* @param {string} name - The unique name for this animation, used in playback commands.
* @param {bool} useStage - Description.
*/
Phaser.Group = function (game, parent, name, useStage) {
parent = parent || null;
@@ -7,7 +25,14 @@ Phaser.Group = function (game, parent, name, useStage) {
useStage = false;
}
/**
* @property {Phaser.Game} game - A reference to the currently running Game.
*/
this.game = game;
/**
* @property {Phaser.Game} name - Description.
*/
this.name = name || 'group';
if (useStage)
@@ -36,19 +61,35 @@ Phaser.Group = function (game, parent, name, useStage) {
}
}
/**
* @property {Description} type - Description.
*/
this.type = Phaser.GROUP;
/**
* @property {bool} exists - Description.
* @default
*/
this.exists = true;
/**
* Helper for sort.
*/
/**
* @property {string} _sortIndex - Helper for sort.
* @private
* @default
*/
this._sortIndex = 'y';
};
Phaser.Group.prototype = {
/**
* Description.
*
* @method add
* @param {Description} child - Description.
* @return {Description} Description.
*/
add: function (child) {
if (child.group !== this)
@@ -67,6 +108,14 @@ Phaser.Group.prototype = {
},
/**
* Description.
*
* @method addAt
* @param {Description} child - Description.
* @param {Description} index - Description.
* @return {Description} Description.
*/
addAt: function (child, index) {
if (child.group !== this)
@@ -85,12 +134,30 @@ Phaser.Group.prototype = {
},
/**
* Description.
*
* @method getAt
* @param {Description} index - Description.
* @return {Description} Description.
*/
getAt: function (index) {
return this._container.getChildAt(index);
},
/**
* Description.
*
* @method create
* @param {number} x - Description.
* @param {number} y - Description.
* @param {string} key - Description.
* @param {string} [frame] - Description.
* @param {boolean} [exists] - Description.
* @return {Description} Description.
*/
create: function (x, y, key, frame, exists) {
if (typeof exists == 'undefined') { exists = true; }
@@ -111,6 +178,14 @@ Phaser.Group.prototype = {
},
/**
* Description.
*
* @method swap
* @param {Description} child1 - Description.
* @param {Description} child2 - Description.
* @return {bool} Description.
*/
swap: function (child1, child2) {
if (child1 === child2 || !child1.parent || !child2.parent)
@@ -231,6 +306,13 @@ Phaser.Group.prototype = {
},
/**
* Description.
*
* @method bringToTop
* @param {Description} child - Description.
* @return {Description} Description.
*/
bringToTop: function (child) {
if (child.group === this)
@@ -243,12 +325,26 @@ Phaser.Group.prototype = {
},
/**
* Description.
*
* @method getIndex
* @param {Description} child - Description.
* @return {Description} Description.
*/
getIndex: function (child) {
return this._container.children.indexOf(child);
},
/**
* Description.
*
* @method replace
* @param {Description} oldChild - Description.
* @param {Description} newChild - Description.
*/
replace: function (oldChild, newChild) {
if (!this._container.first._iNext)
@@ -273,7 +369,16 @@ Phaser.Group.prototype = {
},
// key is an ARRAY of values.
/**
* Description.
*
* @method setProperty
* @param {Description} child - Description.
* @param {array} key - An array of values that will be set.
* @param {Description} value - Description.
* @param {Description} operation - Description.
* @return {number} An integer value: -1 (Obj1 before Obj2), 0 (same), or 1 (Obj1 after Obj2). (TODO)
*/
setProperty: function (child, key, value, operation) {
operation = operation || 0;
@@ -327,11 +432,23 @@ Phaser.Group.prototype = {
},
/**
* Description.
*
* @method setAll
* @param {Description} key - Description.
* @param {Description} value - Description.
* @param {Description} checkAlive - Description.
* @param {Description} checkVisible - Description.
* @param {Description} operation - Description.
*/
setAll: function (key, value, checkAlive, checkVisible, operation) {
key = key.split('.');
checkAlive = checkAlive || false;
checkVisible = checkVisible || false;
if (typeof checkAlive === 'undefined') { checkAlive = false; }
if (typeof checkVisible === 'undefined') { checkVisible = false; }
operation = operation || 0;
if (this._container.children.length > 0 && this._container.first._iNext)
@@ -352,33 +469,82 @@ Phaser.Group.prototype = {
},
addAll: function (key, value, checkAlive, checkVisible) {
/**
* Adds the amount to the given property on all children in this Group.
* Group.addAll('x', 10) will add 10 to the child.x value.
*
* @method addAll
* @param {string} property - The property to increment, for example 'body.velocity.x' or 'angle'.
* @param {number} amount - The amount to increment the property by. If child.x = 10 then addAll('x', 40) would make child.x = 50.
* @param {boolean} checkAlive - If true the property will only be changed if the child is alive.
* @param {boolean} checkVisible - If true the property will only be changed if the child is visible.
*/
addAll: function (property, amount, checkAlive, checkVisible) {
this.setAll(key, value, checkAlive, checkVisible, 1);
this.setAll(property, amount, checkAlive, checkVisible, 1);
},
subAll: function (key, value, checkAlive, checkVisible) {
/**
* Subtracts the amount from the given property on all children in this Group.
* Group.subAll('x', 10) will minus 10 from the child.x value.
*
* @method subAll
* @param {string} property - The property to decrement, for example 'body.velocity.x' or 'angle'.
* @param {number} amount - The amount to subtract from the property. If child.x = 50 then subAll('x', 40) would make child.x = 10.
* @param {boolean} checkAlive - If true the property will only be changed if the child is alive.
* @param {boolean} checkVisible - If true the property will only be changed if the child is visible.
*/
subAll: function (property, amount, checkAlive, checkVisible) {
this.setAll(key, value, checkAlive, checkVisible, 2);
this.setAll(property, amount, checkAlive, checkVisible, 2);
},
multiplyAll: function (key, value, checkAlive, checkVisible) {
/**
* Multiplies the given property by the amount on all children in this Group.
* Group.multiplyAll('x', 2) will x2 the child.x value.
*
* @method multiplyAll
* @param {string} property - The property to multiply, for example 'body.velocity.x' or 'angle'.
* @param {number} amount - The amount to multiply the property by. If child.x = 10 then multiplyAll('x', 2) would make child.x = 20.
* @param {boolean} checkAlive - If true the property will only be changed if the child is alive.
* @param {boolean} checkVisible - If true the property will only be changed if the child is visible.
*/
multiplyAll: function (property, amount, checkAlive, checkVisible) {
this.setAll(key, value, checkAlive, checkVisible, 3);
this.setAll(property, amount, checkAlive, checkVisible, 3);
},
divideAll: function (key, value, checkAlive, checkVisible) {
/**
* Divides the given property by the amount on all children in this Group.
* Group.divideAll('x', 2) will half the child.x value.
*
* @method divideAll
* @param {string} property - The property to divide, for example 'body.velocity.x' or 'angle'.
* @param {number} amount - The amount to divide the property by. If child.x = 100 then divideAll('x', 2) would make child.x = 50.
* @param {boolean} checkAlive - If true the property will only be changed if the child is alive.
* @param {boolean} checkVisible - If true the property will only be changed if the child is visible.
*/
divideAll: function (property, amount, checkAlive, checkVisible) {
this.setAll(key, value, checkAlive, checkVisible, 4);
this.setAll(property, amount, checkAlive, checkVisible, 4);
},
callAllExists: function (callback, callbackContext, existsValue) {
/**
* Calls a function on all of the children that have exists=true in this Group.
* After the existsValue parameter you can add as many parameters as you like, which will all be passed to the child callback.
*
* @method callAllExists
* @param {function} callback - The function that exists on the children that will be called.
* @param {boolean} existsValue - Only children with exists=existsValue will be called.
* @param {...*} parameter - Additional parameters that will be passed to the callback.
*/
callAllExists: function (callback, existsValue) {
var args = Array.prototype.splice.call(arguments, 3);
var args = Array.prototype.splice.call(arguments, 2);
if (this._container.children.length > 0 && this._container.first._iNext)
{
@@ -401,7 +567,11 @@ Phaser.Group.prototype = {
/**
* Calls a function on all of the children regardless if they are dead or alive (see callAllExists if you need control over that)
* After the function you can add as many parameters as you like, which will all be passed to the child.
* After the callback parameter you can add as many extra parameters as you like, which will all be passed to the child.
*
* @method callAll
* @param {function} callback - The function that exists on the children that will be called.
* @param {...*} parameter - Additional parameters that will be passed to the callback.
*/
callAll: function (callback) {
@@ -426,7 +596,15 @@ Phaser.Group.prototype = {
},
// After the checkExists parameter you can add as many parameters as you like, which will all be passed to the callback along with the child.
/**
* Description.
* After the checkExists parameter you can add as many parameters as you like, which will all be passed to the callback along with the child.
*
* @method forEach
* @param {Description} callback - Description.
* @param {Description} callbackContext - Description.
* @param {bool} checkExists - Description.
*/
forEach: function (callback, callbackContext, checkExists) {
if (typeof checkExists === 'undefined')
@@ -457,6 +635,13 @@ Phaser.Group.prototype = {
},
/**
* Description.
*
* @method forEachAlive
* @param {Description} callback - Description.
* @param {Description} callbackContext - Description.
*/
forEachAlive: function (callback, callbackContext) {
var args = Array.prototype.splice.call(arguments, 2);
@@ -482,6 +667,13 @@ Phaser.Group.prototype = {
},
/**
* Description.
*
* @method forEachDead
* @param {Description} callback - Description.
* @param {Description} callbackContext - Description.
*/
forEachDead: function (callback, callbackContext) {
var args = Array.prototype.splice.call(arguments, 2);
@@ -509,6 +701,8 @@ Phaser.Group.prototype = {
/**
* Call this function to retrieve the first object with exists == (the given state) in the group.
*
* @method getFirstExists
* @param {Description} state - Description.
* @return {Any} The first child, or null if none found.
*/
getFirstExists: function (state) {
@@ -542,6 +736,7 @@ Phaser.Group.prototype = {
* Call this function to retrieve the first object with alive == true in the group.
* This is handy for checking if everything's wiped out, or choosing a squad leader, etc.
*
* @method getFirstAlive
* @return {Any} The first alive child, or null if none found.
*/
getFirstAlive: function () {
@@ -570,6 +765,7 @@ Phaser.Group.prototype = {
* Call this function to retrieve the first object with alive == false in the group.
* This is handy for checking if everything's wiped out, or choosing a squad leader, etc.
*
* @method getFirstDead
* @return {Any} The first dead child, or null if none found.
*/
getFirstDead: function () {
@@ -597,6 +793,7 @@ Phaser.Group.prototype = {
/**
* Call this function to find out how many members of the group are alive.
*
* @method countLiving
* @return {number} The number of children flagged as alive. Returns -1 if Group is empty.
*/
countLiving: function () {
@@ -626,6 +823,7 @@ Phaser.Group.prototype = {
/**
* Call this function to find out how many members of the group are dead.
*
* @method countDead
* @return {number} The number of children flagged as dead. Returns -1 if Group is empty.
*/
countDead: function () {
@@ -655,9 +853,8 @@ Phaser.Group.prototype = {
/**
* Returns a member at random from the group.
*
* @param {number} startIndex Optional offset off the front of the array. Default value is 0, or the beginning of the array.
* @param {number} length Optional restriction on the number of values you want to randomly select from.
*
* @param {number} startIndex - Optional offset off the front of the array. Default value is 0, or the beginning of the array.
* @param {number} length - Optional restriction on the number of values you want to randomly select from.
* @return {Any} A random child of this Group.
*/
getRandom: function (startIndex, length) {
@@ -674,6 +871,12 @@ Phaser.Group.prototype = {
},
/**
* Description.
*
* @method remove
* @param {Description} child - Description.
*/
remove: function (child) {
child.events.onRemovedFromGroup.dispatch(child, this);
@@ -682,6 +885,11 @@ Phaser.Group.prototype = {
},
/**
* Description.
*
* @method removeAll
*/
removeAll: function () {
if (this._container.children.length == 0)
@@ -701,6 +909,13 @@ Phaser.Group.prototype = {
},
/**
* Description.
*
* @method removeBetween
* @param {Description} startIndex - Description.
* @param {Description} endIndex - Description.
*/
removeBetween: function (startIndex, endIndex) {
if (this._container.children.length == 0)
@@ -722,6 +937,11 @@ Phaser.Group.prototype = {
},
/**
* Description.
*
* @method destroy
*/
destroy: function () {
this.removeAll();
@@ -736,6 +956,11 @@ Phaser.Group.prototype = {
},
/**
* Description.
*
* @method dump
*/
dump: function (full) {
if (typeof full == 'undefined')
@@ -822,6 +1047,11 @@ Phaser.Group.prototype = {
};
/**
* Get
* @return {Description}
*/
Object.defineProperty(Phaser.Group.prototype, "length", {
get: function () {
@@ -830,6 +1060,13 @@ Object.defineProperty(Phaser.Group.prototype, "length", {
});
/**
* Get
* @return {Description}
*//**
* Set
* @param {Description} value - Description
*/
Object.defineProperty(Phaser.Group.prototype, "x", {
get: function () {
@@ -842,6 +1079,13 @@ Object.defineProperty(Phaser.Group.prototype, "x", {
});
/**
* Get
* @return {Description}
*//**
* Set
* @param {Description} value - Description
*/
Object.defineProperty(Phaser.Group.prototype, "y", {
get: function () {
@@ -854,6 +1098,13 @@ Object.defineProperty(Phaser.Group.prototype, "y", {
});
/**
* Get
* @return {Description}
*//**
* Set
* @param {Description} value - Description
*/
Object.defineProperty(Phaser.Group.prototype, "angle", {
get: function() {
@@ -866,6 +1117,13 @@ Object.defineProperty(Phaser.Group.prototype, "angle", {
});
/**
* Get
* @return {Description}
*//**
* Set
* @param {Description} value - Description
*/
Object.defineProperty(Phaser.Group.prototype, "rotation", {
get: function () {
@@ -878,6 +1136,13 @@ Object.defineProperty(Phaser.Group.prototype, "rotation", {
});
/**
* Get
* @return {Description}
*//**
* Set
* @param {Description} value - Description.
*/
Object.defineProperty(Phaser.Group.prototype, "visible", {
get: function () {
+61 -1
View File
@@ -1,16 +1,59 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2013 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
* @module Phaser.LinkedList
*/
/**
* A linked list data structure.
*
* @class Phaser.LinkedList
* @constructor
*/
Phaser.LinkedList = function () {
/**
* @property {object} next - Next element in the list.
* @default
*/
this.next = null;
/**
* @property {object} prev - Previous element in the list.
* @default
*/
this.prev = null;
/**
* @property {object} first - First element in the list.
* @default
*/
this.first = null;
/**
* @property {object} last - Last element in the list.
* @default
*/
this.last = null;
/**
* @property {object} game - Number of elements in the list.
* @default
*/
this.total = 0;
};
Phaser.LinkedList.prototype = {
/**
* Add element to a linked list.
*
* @method add
* @param {object} child - Description.
* @return {object} Description.
*/
add: function (child) {
// If the list is empty
@@ -37,6 +80,12 @@ Phaser.LinkedList.prototype = {
},
/**
* Remove element from a linked list.
*
* @method remove
* @param {object} child - Description.
*/
remove: function (child) {
if( this.first ) {
child.next = this.last.next;
@@ -53,6 +102,12 @@ Phaser.LinkedList.prototype = {
this.total--;
},
/**
* Description.
*
* @method callAll
* @param {object} callback - Description.
*/
callAll: function (callback) {
if (!this.first || !this.last)
@@ -76,6 +131,11 @@ Phaser.LinkedList.prototype = {
},
/**
* Description.
*
* @method dump
*/
dump: function () {
var spacing = 20;
+51 -3
View File
@@ -1,19 +1,67 @@
/**
* Phaser - Plugin
*
* This is a base Plugin template to use for any Phaser plugin development
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2013 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
* @module Phaser.Plugin
*/
/**
* This is a base Plugin template to use for any Phaser plugin development.
*
* @class Phaser.Plugin
* @classdesc Phaser - Plugin
* @constructor
* @param {Phaser.Game} game - A reference to the currently running game.
* @param {Description} parent - Description.
*
*/
Phaser.Plugin = function (game, parent) {
/**
* @property {Phaser.Game} game - A reference to the currently running game.
*/
this.game = game;
/**
* @property {Description} parent - Description.
*/
this.parent = parent;
/**
* @property {bool} active - Description.
* @default
*/
this.active = false;
/**
* @property {bool} visible - Description.
* @default
*/
this.visible = false;
/**
* @property {bool} hasPreUpdate - Description.
* @default
*/
this.hasPreUpdate = false;
/**
* @property {bool} hasUpdate - Description.
* @default
*/
this.hasUpdate = false;
/**
* @property {bool} hasRender - Description.
* @default
*/
this.hasRender = false;
/**
* @property {bool} hasPostRender - Description.
* @default
*/
this.hasPostRender = false;
};
+65 -5
View File
@@ -1,14 +1,44 @@
/**
* Phaser - PluginManager
*
* TODO: We can optimise this a lot by using separate hashes per function (update, render, etc)
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2013 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
* @module Phaser.PluginManager
*/
// TODO: We can optimise this a lot by using separate hashes per function (update, render, etc)
/**
* Description.
*
* @class Phaser.PluginManager
* @classdesc PPhaser - PluginManager
* @constructor
* @param {Phaser.Game} game - A reference to the currently running game.
* @param {Description} parent - Description.
*/
Phaser.PluginManager = function(game, parent) {
/**
* @property {Phaser.Game} game - A reference to the currently running game.
*/
this.game = game;
/**
* @property {Description} _parent - Description.
* @private
*/
this._parent = parent;
/**
* @property {array} plugins - Description.
*/
this.plugins = [];
/**
* @property {array} _pluginsLength - Description.
* @private
* @default
*/
this._pluginsLength = 0;
};
@@ -17,8 +47,9 @@ Phaser.PluginManager.prototype = {
/**
* Add a new Plugin to the PluginManager.
* The plugins game and parent reference are set to this game and pluginmanager parent.
* @type {Phaser.Plugin}
* The plugin's game and parent reference are set to this game and pluginmanager parent.
* @param {Phaser.Plugin} plugin - Description.
* @return {Phaser.Plugin} Description.
*/
add: function (plugin) {
@@ -82,6 +113,10 @@ Phaser.PluginManager.prototype = {
}
},
/**
* Remove a Plugin from the PluginManager.
* @param {Phaser.Plugin} plugin - Description.
*/
remove: function (plugin) {
// TODO
@@ -89,6 +124,11 @@ Phaser.PluginManager.prototype = {
},
/**
* Description.
*
* @method preUpdate
*/
preUpdate: function () {
if (this._pluginsLength == 0)
@@ -106,6 +146,11 @@ Phaser.PluginManager.prototype = {
},
/**
* Description.
*
* @method update
*/
update: function () {
if (this._pluginsLength == 0)
@@ -123,6 +168,11 @@ Phaser.PluginManager.prototype = {
},
/**
* Description.
*
* @method render
*/
render: function () {
if (this._pluginsLength == 0)
@@ -140,6 +190,11 @@ Phaser.PluginManager.prototype = {
},
/**
* Description.
*
* @method postRender
*/
postRender: function () {
if (this._pluginsLength == 0)
@@ -157,6 +212,11 @@ Phaser.PluginManager.prototype = {
},
/**
* Description.
*
* @method destroy
*/
destroy: function () {
this.plugins.length = 0;
+92 -53
View File
@@ -1,23 +1,40 @@
/**
* Phaser.Signal
*
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2013 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
* @module Phaser.Signal
*/
/**
*
* A Signal is used for object communication via a custom broadcaster instead of Events.
*
* @class Phaser.Signal
* @classdesc Phaser Signal
* @author Miller Medeiros http://millermedeiros.github.com/js-signals/
* @constructor
*/
Phaser.Signal = function () {
/**
* @type Array.<Phaser.SignalBinding>
* @private
*/
* @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;
/**
* @property {Description} dispatch - Description.
*/
this.dispatch = function(){
Phaser.Signal.prototype.dispatch.apply(self, arguments);
};
@@ -27,26 +44,35 @@ Phaser.Signal = function () {
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.
* @type boolean
*/
* If Signal should keep record of previously dispatched parameters and
* automatically execute listener during `add()`/`addOnce()` if Signal was
* already dispatched before.
* @property {bool} memorize
*/
memorize: false,
/**
* @type boolean
* @private
*/
* Description.
* @property {bool} _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>
* @type boolean
*/
* 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 {bool} active
* @default
*/
active: true,
/**
* Description.
*
* @method validateListener
* @param {function} listener - Signal handler function.
* @param {Description} fnName - Description.
*/
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) );
@@ -54,11 +80,14 @@ Phaser.Signal.prototype = {
},
/**
* @param {Function} listener
* @param {boolean} isOnce
* @param {Object} [listenerContext]
* @param {Number} [priority]
* @return {Phaser.SignalBinding}
* Description.
*
* @method _registerListener
* @param {function} listener - Signal handler function.
* @param {bool} 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) {
@@ -84,7 +113,10 @@ Phaser.Signal.prototype = {
},
/**
* @param {Phaser.SignalBinding} binding
* Description.
*
* @method _addBinding
* @param {Phaser.SignalBinding} binding - An Object representing the binding between the Signal and listener.
* @private
*/
_addBinding: function (binding) {
@@ -95,8 +127,11 @@ Phaser.Signal.prototype = {
},
/**
* @param {Function} listener
* @return {number}
* Description.
*
* @method _indexOfListener
* @param {function} listener - Signal handler function.
* @return {number} Description.
* @private
*/
_indexOfListener: function (listener, context) {
@@ -113,9 +148,11 @@ Phaser.Signal.prototype = {
/**
* Check if listener was attached to Signal.
* @param {Function} listener
* @param {Object} [context]
* @return {boolean} if Signal has the specified listener.
*
* @method 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 {bool} If Signal has the specified listener.
*/
has: function (listener, context) {
return this._indexOfListener(listener, context) !== -1;
@@ -123,9 +160,11 @@ Phaser.Signal.prototype = {
/**
* Add a listener to the signal.
* @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)
*
* @method 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) {
@@ -134,23 +173,23 @@ Phaser.Signal.prototype = {
},
/**
* Add listener to the signal that should be removed after first execution (will be executed only once).
* @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 listener to the signal that should be removed after first execution (will be executed only once).
* @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.
* @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 a single listener from the dispatch queue.
* @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');
@@ -163,8 +202,8 @@ Phaser.Signal.prototype = {
},
/**
* Remove all listeners from the Signal.
*/
* Remove all listeners from the Signal.
*/
removeAll: function () {
var n = this._bindings.length;
while (n--) {
@@ -174,25 +213,25 @@ Phaser.Signal.prototype = {
},
/**
* @return {number} Number of listeners attached to the Signal.
*/
* @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
*/
* 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
*/
halt: function () {
this._shouldPropagate = false;
},
/**
* Dispatch/Broadcast Signal to all listeners added to the queue.
* @param {...*} [params] Parameters that should be passed to each handler.
*/
* Dispatch/Broadcast Signal to all listeners added to the queue.
* @param {Description} [params] - Parameters that should be passed to each handler.
*/
dispatch: function (params) {
if (! this.active) {
return;
+69 -56
View File
@@ -1,3 +1,11 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2013 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
* @module Phaser.SignalBinding
*/
/**
* Phaser.SignalBinding
*
@@ -5,52 +13,47 @@
* <br />- <strong>This is an internal constructor and shouldn't be called by regular users.</strong>
* <br />- inspired by Joa Ebert AS3 SignalBinding and Robert Penner's Slot classes.
*
* @class Phaser.SignalBinding
* @name SignalBinding
* @author Miller Medeiros http://millermedeiros.github.com/js-signals/
* @constructor
* @internal
* @name SignalBinding
* @param {Signal} signal Reference to Signal object that listener is currently bound to.
* @param {Function} listener Handler function bound to the signal.
* @param {boolean} isOnce If binding should be executed just once.
* @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. (default = 0).
* @inner
* @param {Signal} signal - Reference to Signal object that listener is currently bound to.
* @param {function} listener - Handler function bound to the signal.
* @param {bool} isOnce - If binding should be executed just once.
* @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. (default = 0).
*/
Phaser.SignalBinding = function (signal, listener, isOnce, listenerContext, priority) {
/**
* Handler function bound to the signal.
* @type Function
* @private
*/
* @property {Phaser.Game} _listener - Handler function bound to the signal.
* @private
*/
this._listener = listener;
/**
* If binding should be executed just once.
* @type boolean
* @private
*/
* @property {bool} _isOnce - If binding should be executed just once.
* @private
*/
this._isOnce = isOnce;
/**
* Context on which listener will be executed (object that should represent the `this` variable inside listener function).
* @memberOf SignalBinding.prototype
* @name context
* @type Object|undefined|null
*/
* @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;
/**
* Reference to Signal object that listener is currently bound to.
* @type Signal
* @private
*/
* @property {Signal} _signal - Reference to Signal object that listener is currently bound to.
* @private
*/
this._signal = signal;
/**
* Listener priority
* @type Number
* @private
*/
* @property {number} _priority - Listener priority.
* @private
*/
this._priority = priority || 0;
};
@@ -58,23 +61,26 @@ Phaser.SignalBinding = function (signal, listener, isOnce, listenerContext, prio
Phaser.SignalBinding.prototype = {
/**
* If binding is active and should be executed.
* @type boolean
*/
* If binding is active and should be executed.
* @property {bool} active
* @default
*/
active: true,
/**
* Default parameters passed to listener during `Signal.dispatch` and `SignalBinding.execute`. (curried parameters)
* @type Array|null
*/
* Default parameters passed to listener during `Signal.dispatch` and `SignalBinding.execute` (curried parameters).
* @property {array|null} params
* @default
*/
params: null,
/**
* Call listener passing arbitrary parameters.
* <p>If binding was added using `Signal.addOnce()` it will be automatically removed from signal dispatch queue, this method is used internally for the signal dispatch.</p>
* @param {Array} [paramsArr] Array of parameters that should be passed to the listener
* @return {*} Value returned by the listener.
*/
* Call listener passing arbitrary parameters.
* <p>If binding was added using `Signal.addOnce()` it will be automatically removed from signal dispatch queue, this method is used internally for the signal dispatch.</p>
* @method execute
* @param {array} [paramsArr] - Array of parameters that should be passed to the listener.
* @return {Description} Value returned by the listener.
*/
execute: function (paramsArr) {
var handlerReturn, params;
@@ -95,46 +101,52 @@ Phaser.SignalBinding.prototype = {
},
/**
* Detach binding from signal.
* - alias to: mySignal.remove(myBinding.getListener());
* @return {Function|null} Handler function bound to the signal or `null` if binding was previously detached.
*/
* Detach binding from signal.
* <p>alias to: @see mySignal.remove(myBinding.getListener());
* @method detach
* @return {function|null} Handler function bound to the signal or `null` if binding was previously detached.
*/
detach: function () {
return this.isBound() ? this._signal.remove(this._listener, this.context) : null;
},
/**
* @return {Boolean} `true` if binding is still bound to the signal and have a listener.
*/
* @method isBound
* @return {bool} True if binding is still bound to the signal and has a listener.
*/
isBound: function () {
return (!!this._signal && !!this._listener);
},
/**
* @return {boolean} If SignalBinding will only be executed once.
*/
* @method isOnce
* @return {bool} If SignalBinding will only be executed once.
*/
isOnce: function () {
return this._isOnce;
},
/**
* @return {Function} Handler function bound to the signal.
*/
* @method getListener
* @return {Function} Handler function bound to the signal.
*/
getListener: function () {
return this._listener;
},
/**
* @return {Signal} Signal that listener is currently bound to.
*/
* @method getSignal
* @return {Signal} Signal that listener is currently bound to.
*/
getSignal: function () {
return this._signal;
},
/**
* Delete instance properties
* @private
*/
* @method _destroy
* Delete instance properties
* @private
*/
_destroy: function () {
delete this._signal;
delete this._listener;
@@ -142,8 +154,9 @@ Phaser.SignalBinding.prototype = {
},
/**
* @return {string} String representation of the object.
*/
* @method toString
* @return {string} String representation of the object.
*/
toString: function () {
return '[Phaser.SignalBinding isOnce:' + this._isOnce +', isBound:'+ this.isBound() +', active:' + this.active + ']';
}
+30 -53
View File
@@ -1,7 +1,7 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2013 Photon Storm Ltd.
* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
* @module Phaser.Stage
*/
@@ -12,76 +12,55 @@
*
* @class Stage
* @constructor
* @param {Phaser.Game} game Game reference to the currently running game.
* @param {number} width Width of the canvas element
* @param {number} height Height of the canvas element
* @param {Phaser.Game} game - Game reference to the currently running game.
* @param {number} width - Width of the canvas element.
* @param {number} height - Height of the canvas element.
*/
Phaser.Stage = function (game, width, height) {
/**
* A reference to the currently running Game.
* @property game
* @public
* @type {Phaser.Game}
*/
/**
* @property {Phaser.Game} game - A reference to the currently running Game.
*/
this.game = game;
/**
* Background color of the stage (defaults to black). Set via the public backgroundColor property.
* @property _backgroundColor
* @private
* @type {string}
*/
* @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)';
/**
* Get the offset values (for input and other things)
* @property offset
* @public
* @type {Phaser.Point}
*/
* @property {Phaser.Point} offset - Get the offset values (for input and other things).
*/
this.offset = new Phaser.Point;
/**
* reference to the newly created <canvas> element
* @property canvas
* @public
* @type {HTMLCanvasElement}
* @property {HTMLCanvasElement} canvas - Reference to the newly created &lt;canvas&gt; 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%';
/**
* The Pixi Stage which is hooked to the renderer
* @property _stage
* @property {PIXI.Stage} _stage - The Pixi Stage which is hooked to the renderer.
* @private
* @type {PIXI.Stage}
*/
this._stage = new PIXI.Stage(0x000000, false);
this._stage.name = '_stage_root';
/**
* The current scaleMode
* @property scaleMode
* @public
* @type {number}
*/
* @property {number} scaleMode - The current scaleMode.
*/
this.scaleMode = Phaser.StageScaleMode.NO_SCALE;
/**
* The scale of the current running game
* @property scale
* @public
* @type {Phaser.StageScaleMode}
* @property {Phaser.StageScaleMode} scale - The scale of the current running game.
*/
this.scale = new Phaser.StageScaleMode(this.game, width, height);
/**
* aspect ratio
* @property aspectRatio
* @public
* @type {number}
*/
* @property {number} aspectRatio - Aspect ratio.
*/
this.aspectRatio = width / height;
};
@@ -89,7 +68,7 @@ Phaser.Stage = function (game, width, height) {
Phaser.Stage.prototype = {
/**
* Initialises the stage and adds the event listeners
* Initialises the stage and adds the event listeners.
* @method boot
*/
boot: function () {
@@ -120,7 +99,7 @@ Phaser.Stage.prototype = {
/**
* This method is called when the document visibility is changed.
* @method visibilityChange
* @param {Event} event Its type will be used to decide whether the game should be paused or not
* @param {Event} event - Its type will be used to decide whether the game should be paused or not.
*/
visibilityChange: function (event) {
@@ -144,21 +123,19 @@ Phaser.Stage.prototype = {
};
/**
* Get
* @returns {string} Returns the background color of the stage.
*//**
* Set
* @param {string} The background color you want the stage to have
*/.
Object.defineProperty(Phaser.Stage.prototype, "backgroundColor", {
/**
* @method backgroundColor
* @return {string} returns the background color of the stage
*/
get: function () {
return this._backgroundColor;
},
/**
* @method backgroundColor
* @param {string} the background color you want the stage to have
* @return {string} returns the background color of the stage
*/
set: function (color) {
this._backgroundColor = color;
+91 -9
View File
@@ -1,30 +1,101 @@
/**
* State
*
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2013 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
* @module Phaser.State
*/
/**
* This is a base State class which can be extended if you are creating your own game.
* It provides quick access to common functions such as the camera, cache, input, match, sound and more.
*
* @package Phaser.State
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2013 Photon Storm Ltd.
* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
* @class Phaser.State
* @constructor
*/
Phaser.State = function () {
/**
* @property {Phaser.Game} game - A reference to the currently running Game.
*/
this.game = null;
/**
* @property {Description} add - Description.
* @default
*/
this.add = null;
/**
* @property {Phaser.Physics.PhysicsManager} camera - A handy reference to world.camera.
* @default
*/
this.camera = null;
/**
* @property {Phaser.Cache} cache - Reference to the assets cache.
* @default
*/
this.cache = null;
/**
* @property {Phaser.Input} input - Reference to the input manager
* @default
*/
this.input = null;
/**
* @property {Phaser.Loader} load - Reference to the assets loader.
* @default
*/
this.load = null;
/**
* @property {Phaser.GameMath} math - Reference to the math helper.
* @default
*/
this.math = null;
/**
* @property {Phaser.SoundManager} sound - Reference to the sound manager.
* @default
*/
this.sound = null;
/**
* @property {Phaser.Stage} stage - Reference to the stage.
* @default
*/
this.stage = null;
/**
* @property {Phaser.TimeManager} time - Reference to game clock.
* @default
*/
this.time = null;
/**
* @property {Phaser.TweenManager} tweens - Reference to the tween manager.
* @default
*/
this.tweens = null;
/**
* @property {Phaser.World} world - Reference to the world.
* @default
*/
this.world = null;
/**
* @property {Description} add - Description.
* @default
*/
this.particles = null;
/**
* @property {Phaser.Physics.PhysicsManager} physics - Reference to the physics manager.
* @default
*/
this.physics = null;
};
@@ -34,37 +105,48 @@ Phaser.State.prototype = {
/**
* Override this method to add some load operations.
* If you need to use the loader, you may need to use them here.
*
* @method preload
*/
preload: function () {
},
/**
* This method is called after the game engine successfully switches states.
* Feel free to add any setup code here.(Do not load anything here, override preload() instead)
* Feel free to add any setup code here (do not load anything here, override preload() instead).
*
* @method create
*/
create: function () {
},
/**
* Put update logic here.
*
* @method update
*/
update: function () {
},
/**
* Put render operations here.
*
* @method render
*/
render: function () {
},
/**
* This method will be called when game paused.
*
* @method paused
*/
paused: function () {
},
/**
* This method will be called when the state is destroyed
* This method will be called when the state is destroyed.#
* @method destroy
*/
destroy: function () {
}
+107 -33
View File
@@ -1,7 +1,30 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2013 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
* @module Phaser.StateManager
*/
/**
* Description.
*
* @class Phaser.StateManager
* @constructor
* @param {Phaser.Game} game - A reference to the currently running game.
* @param {Description} pendingState - Description.
*/
Phaser.StateManager = function (game, pendingState) {
/**
* A reference to the currently running game.
* @property {Phaser.Game} game.
*/
this.game = game;
/**
* Description.
* @property {Description} states.
*/
this.states = {};
if (pendingState !== null)
@@ -14,94 +37,101 @@ Phaser.StateManager = function (game, pendingState) {
Phaser.StateManager.prototype = {
/**
* @type {Phaser.Game}
* A reference to the currently running game.
* @property {Phaser.Game} game.
*/
game: null,
/**
* The state to be switched to in the next frame.
* @type {State}
* @property {State} _pendingState
* @private
*/
_pendingState: null,
/**
* Flag that sets if the State has been created or not.
* @type {Boolean}
* @property {bool}_created
* @private
*/
_created: false,
/**
* The state to be switched to in the next frame.
* @type {Object}
* @property {Description} states
*/
states: {},
/**
* The current active State object (defaults to null)
* @type {String}
* 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)
* @type {function}
* 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...)
* @type {function}
* This will be called when init states (loading assets...).
* @property {function} onPreloadCallback
*/
onPreloadCallback: null,
/**
* This will be called when create states. (setup states...)
* @type {function}
* 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)
* @type {function}
* 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)
* @type {function}
* 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
* @type {function}
* 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
* @type {function}
* 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
* @type {function}
* 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.
* @type {function}
* @property {function} onPausedCallback
*/
onPausedCallback: null,
/**
* This will be called when the state is shut down (i.e. swapped to another state)
* @type {function}
* This will be called when the state is shut down (i.e. swapped to another state).
* @property {function} onShutDownCallback
*/
onShutDownCallback: null,
/**
* Description.
* @method boot
*/
boot: function () {
// console.log('Phaser.StateManager.boot');
@@ -127,9 +157,10 @@ Phaser.StateManager.prototype = {
/**
* Add a new State.
* @param key {String} A unique key you use to reference this state, i.e. "MainMenu", "Level1".
* @param state {State} The state you want to switch to.
* @param autoStart {Boolean} Start the state immediately after creating it? (default true)
* @method add
* @param key {string} - A unique key you use to reference this state, i.e. "MainMenu", "Level1".
* @param state {State} - The state you want to switch to.
* @param autoStart {bool} - Start the state immediately after creating it? (default true)
*/
add: function (key, state, autoStart) {
@@ -178,6 +209,11 @@ Phaser.StateManager.prototype = {
},
/**
* Delete the given state.
* @method remove
* @param {string} key - A unique key you use to reference this state, i.e. "MainMenu", "Level1".
*/
remove: function (key) {
if (this.current == key)
@@ -203,9 +239,10 @@ Phaser.StateManager.prototype = {
/**
* Start the given state
* @param key {String} The key of the state you want to start.
* @param [clearWorld] {bool} clear everything in the world? (Default to true)
* @param [clearCache] {bool} clear asset cache? (Default to false and ONLY available when clearWorld=true)
* @method start
* @param {string} key - The key of the state you want to start.
* @param {bool} [clearWorld] - clear everything in the world? (Default to true)
* @param {bool} [clearCache] - clear asset cache? (Default to false and ONLY available when clearWorld=true)
*/
start: function (key, clearWorld, clearCache) {
@@ -277,11 +314,21 @@ Phaser.StateManager.prototype = {
}
},
// 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 dummy
* @private
*/
dummy: function () {
},
/**
* Description.
* @method checkState
* @param {string} key - The key of the state you want to check.
* @return {bool} Description.
*/
checkState: function (key) {
if (this.states[key])
@@ -314,6 +361,11 @@ Phaser.StateManager.prototype = {
},
/**
* Description.
* @method link
* @param {string} key - Description.
*/
link: function (key) {
// console.log('linked');
@@ -335,6 +387,11 @@ Phaser.StateManager.prototype = {
},
/**
* Description.
* @method setCurrentState
* @param {string} key - Description.
*/
setCurrentState: function (key) {
this.callbackContext = this.states[key];
@@ -363,6 +420,10 @@ Phaser.StateManager.prototype = {
},
/**
* Description.
* @method loadComplete
*/
loadComplete: function () {
// console.log('Phaser.StateManager.loadComplete');
@@ -380,6 +441,10 @@ Phaser.StateManager.prototype = {
},
/**
* Description.
* @method update
*/
update: function () {
if (this._created && this.onUpdateCallback)
@@ -396,6 +461,10 @@ Phaser.StateManager.prototype = {
},
/**
* Description.
* @method preRender
*/
preRender: function () {
if (this.onPreRenderCallback)
@@ -405,6 +474,10 @@ Phaser.StateManager.prototype = {
},
/**
* Description.
* @method render
*/
render: function () {
if (this._created && this.onRenderCallback)
@@ -423,6 +496,7 @@ Phaser.StateManager.prototype = {
/**
* Nuke the entire game from orbit
* @method destroy
*/
destroy: function () {
+49 -59
View File
@@ -1,71 +1,55 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2013 Photon Storm Ltd.
* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
* @module Phaser.World
*/
/**
*
* "This world is but a canvas to our imagination." - Henry David Thoreau
*
* <p>
* A game has only one world. The world is an abstract place in which all game objects live. It is not bound
* by stage limits and can be any size. You look into the world via cameras. All game objects live within
* the world at world-based coordinates. By default a world is created the same size as your Stage.
*
* @class World
* @class Phaser.World
* @constructor
* @param {Phaser.Game} game Reference to the current game instance.
* @param {Phaser.Game} game - Reference to the current game instance.
*/
Phaser.World = function (game) {
/**
* A reference to the currently running Game.
* @property game
* @public
* @type {Phaser.Game}
*/
* @property {Phaser.Game} game - A reference to the currently running Game.
*/
this.game = game;
/**
* Bound of this world that objects can not escape from.
* @property bounds
* @public
* @type {Phaser.Rectangle}
*/
* @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);
/**
* Camera instance.
* @property camera
* @public
* @type {Phaser.Camera}
*/
* @property {Phaser.Camera} camera - Camera instance.
*/
this.camera = null;
/**
* Reset each frame, keeps a count of the total number of objects updated.
* @property currentRenderOrderID
* @public
* @type {Number}
*/
* @property {number} currentRenderOrderID - Reset each frame, keeps a count of the total number of objects updated.
*/
this.currentRenderOrderID = 0;
/**
* Object container stores every object created with `create*` methods.
* @property group
* @public
* @type {Phaser.Group}
*/
* @property {Phaser.Group} group - Object container stores every object created with `create*` methods.
*/
this.group = null;
};
Phaser.World.prototype = {
/**
* Initialises the game world
* Initialises the game world.
*
* @method boot
*/
@@ -81,6 +65,7 @@ Phaser.World.prototype = {
/**
* This is called automatically every frame, and is where main logic happens.
*
* @method update
*/
update: function () {
@@ -139,8 +124,8 @@ Phaser.World.prototype = {
/**
* Updates the size of this world.
* @method setSize
* @param {number} width New width of the world.
* @param {number} height New height of the world.
* @param {number} width - New width of the world.
* @param {number} height - New height of the world.
*/
setSize: function (width, height) {
@@ -174,7 +159,13 @@ Phaser.World.prototype = {
};
// Getters / Setters
/**
* Get
* @returns {Description}
*//**
* Set
* @param {Description} value - Description
*/
Object.defineProperty(Phaser.World.prototype, "width", {
/**
@@ -195,68 +186,67 @@ Object.defineProperty(Phaser.World.prototype, "width", {
});
/**
* Get
* @returns {number} The current height of the game world.
*//**
* Sets the width of the game world.
* @param {Description} value - Height of the game world.
*/
Object.defineProperty(Phaser.World.prototype, "height", {
/**
* @method height
* @return {Number} The current height of the game world
*/
get: function () {
return this.bounds.height;
},
/**
* @method height
* @return {Number} Sets the width of the game world
*/
set: function (value) {
this.bounds.height = value;
}
});
/**
* Get
* @returns {number} return the X position of the center point of the world
*/
Object.defineProperty(Phaser.World.prototype, "centerX", {
/**
* @method centerX
* @return {Number} return the X position of the center point of the world
*/
get: function () {
return this.bounds.halfWidth;
}
});
/**
* Get
* @returns {number} return the Y position of the center point of the world
*/
Object.defineProperty(Phaser.World.prototype, "centerY", {
/**
* @method centerY
* @return {Number} return the Y position of the center point of the world
*/
get: function () {
return this.bounds.halfHeight;
}
});
/**
* Get
* @returns {number} a random integer which is lesser or equal to the current width of the game world
*/
Object.defineProperty(Phaser.World.prototype, "randomX", {
/**
* @method randomX
* @return {Number} a random integer which is lesser or equal to the current width of the game world
*/
get: function () {
return Math.round(Math.random() * this.bounds.width);
}
});
/**
* Get
* @returns {number} a random integer which is lesser or equal to the current height of the game world
*/
Object.defineProperty(Phaser.World.prototype, "randomY", {
/**
* @method randomY
* @return {Number} a random integer which is lesser or equal to the current height of the game world
*/
get: function () {
return Math.round(Math.random() * this.bounds.height);
}