From 305b12d76be5c43d00a76aaad2a4de5c36213315 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Tue, 1 Oct 2013 13:54:29 +0100 Subject: [PATCH] Adding docs. --- src/Intro.js | 7 + src/Phaser.js | 7 + src/animation/Animation.js | 57 ++-- src/animation/AnimationManager.js | 149 +++++----- src/animation/Frame.js | 144 +++------- src/animation/FrameData.js | 55 ++-- src/animation/Parser.js | 48 ++-- src/core/Camera.js | 189 ++++++------- src/core/Game.js | 232 ++++++++-------- src/core/Group.js | 307 +++++++++++++++++++-- src/core/LinkedList.js | 62 ++++- src/core/Plugin.js | 54 +++- src/core/PluginManager.js | 70 ++++- src/core/Signal.js | 145 ++++++---- src/core/SignalBinding.js | 125 +++++---- src/core/Stage.js | 83 +++--- src/core/State.js | 100 ++++++- src/core/StateManager.js | 140 +++++++--- src/core/World.js | 108 ++++---- src/gameobjects/BitmapText.js | 95 ++++++- src/gameobjects/Button.js | 106 +++++++- src/gameobjects/Events.js | 14 +- src/gameobjects/GameObjectFactory.js | 162 ++++++++++- src/gameobjects/Graphics.js | 22 +- src/gameobjects/RenderTexture.js | 42 ++- src/gameobjects/Sprite.js | 326 +++++++++++++++++----- src/gameobjects/Text.js | 73 ++++- src/gameobjects/TileSprite.js | 40 ++- src/geom/Circle.js | 212 ++++++++------- src/geom/Point.js | 110 ++++---- src/geom/Rectangle.js | 374 ++++++++++++-------------- src/input/Input.js | 299 ++++++++++++++------- src/input/InputHandler.js | 316 +++++++++++++++++----- src/input/Keyboard.js | 120 ++++++--- src/input/MSPointer.js | 68 ++++- src/input/Mouse.js | 69 ++++- src/input/Pointer.js | 234 +++++++++------- src/input/Touch.js | 91 +++++-- src/loader/Cache.js | 198 ++++++++------ src/loader/Loader.js | 231 +++++++++++----- src/loader/Parser.js | 15 +- src/math/Math.js | 388 +++++++++++++++++++-------- src/math/QuadTree.js | 106 +++++--- src/math/RandomDataGenerator.js | 100 ++++--- src/net/Net.js | 40 +++ src/particles/Particles.js | 42 +++ src/particles/arcade/Emitter.js | 216 +++++++++++---- src/sound/Sound.js | 267 +++++++++++++----- src/sound/SoundManager.js | 144 ++++++---- src/system/Canvas.js | 60 ++--- src/system/Device.js | 196 ++++++++------ src/system/RequestAnimationFrame.js | 40 ++- src/system/StageScaleMode.js | 154 ++++++++--- src/tilemap/Tile.js | 92 ++++--- src/tilemap/Tilemap.js | 196 +++++++++----- src/tilemap/TilemapLayer.js | 278 +++++++++++++------ src/tilemap/TilemapRenderer.js | 99 ++++++- src/time/Time.js | 114 ++++---- src/tween/Easing.js | 316 ++++++++++++++++++++++ src/tween/Tween.js | 306 +++++++++++++++++---- src/tween/TweenManager.js | 74 +++-- src/utils/Color.js | 187 ++++++------- src/utils/Debug.js | 196 +++++++++++--- src/utils/Utils.js | 40 +-- 64 files changed, 6268 insertions(+), 2682 deletions(-) diff --git a/src/Intro.js b/src/Intro.js index 08ea73e7..2a7a7f15 100644 --- a/src/Intro.js +++ b/src/Intro.js @@ -1,3 +1,10 @@ +/** +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} +* @module Phaser.Intro +*/ + /** * Phaser - http://www.phaser.io * diff --git a/src/Phaser.js b/src/Phaser.js index 662b1a94..7e408196 100644 --- a/src/Phaser.js +++ b/src/Phaser.js @@ -1,3 +1,10 @@ +/** +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} +* @module Phaser +*/ + /** * @module Phaser */ diff --git a/src/animation/Animation.js b/src/animation/Animation.js index 90f456cf..c24d6621 100644 --- a/src/animation/Animation.js +++ b/src/animation/Animation.js @@ -1,7 +1,7 @@ /** * @author Richard Davey * @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.Animation */ @@ -92,7 +92,18 @@ Phaser.Animation = function (game, parent, name, frameData, frames, delay, loope */ this._frameIndex = 0; + /** + * @property {number} _frameDiff + * @private + * @default + */ this._frameDiff = 0; + + /** + * @property {number} _frameSkip + * @private + * @default + */ this._frameSkip = 1; /** @@ -108,9 +119,9 @@ Phaser.Animation.prototype = { * Plays this animation. * * @method play - * @param {Number} [frameRate=null] The framerate to play the animation at. The speed is given in frames per second. If not provided the previously set frameRate of the Animation is used. - * @param {Boolean} [loop=null] Should the animation be looped after playback. If not provided the previously set loop value of the Animation is used. - * @return {Phaser.Animation} A reference to this Animation instance. + * @param {number} [frameRate=null] - The framerate to play the animation at. The speed is given in frames per second. If not provided the previously set frameRate of the Animation is used. + * @param {boolean} [loop=null] - Should the animation be looped after playback. If not provided the previously set loop value of the Animation is used. + * @return {Phaser.Animation} - A reference to this Animation instance. */ play: function (frameRate, loop) { @@ -169,7 +180,7 @@ Phaser.Animation.prototype = { * Stops playback of this animation and set it to a finished state. If a resetFrame is provided it will stop playback and set frame to the first in the animation. * * @method stop - * @param {Boolean} [resetFrame=false] If true after the animation stops the currentFrame value will be set to the first frame in this animation. + * @param {boolean} [resetFrame=false] - If true after the animation stops the currentFrame value will be set to the first frame in this animation. */ stop: function (resetFrame) { @@ -287,6 +298,14 @@ Phaser.Animation.prototype = { }; /** + * Sets the paused state of the Animation. + * @param {boolean} value - Set to true to pause the animation or false to resume it if previous paused. + * + *//** + * + * Returns the paused state of the Animation. + * @returns {boolean} + * */ Object.defineProperty(Phaser.Animation.prototype, "paused", { @@ -318,12 +337,14 @@ Object.defineProperty(Phaser.Animation.prototype, "paused", { }); +/** + * + * Returns the total number of frames in this Animation. + * @return {number} + * + */ Object.defineProperty(Phaser.Animation.prototype, "frameTotal", { - /** - * @method frameTotal - * @return {Number} The total number of frames in this animation. - */ get: function () { return this._frames.length; } @@ -369,12 +390,18 @@ Object.defineProperty(Phaser.Animation.prototype, "frame", { }); -/* - * Really handy function for when you are creating arrays of animation data but it's using frame names and not numbers. - * For example imagine you've got 30 frames named: 'explosion_0001-large' to 'explosion_0030-large' - * You could use this function to generate those by doing: Phaser.Animation.generateFrameNames('explosion_', 1, 30, '-large', 4); - * The zeroPad value dictates how many zeroes to add in front of the numbers (if any) - */ +/** +* Really handy function for when you are creating arrays of animation data but it's using frame names and not numbers. +* For example imagine you've got 30 frames named: 'explosion_0001-large' to 'explosion_0030-large' +* You could use this function to generate those by doing: Phaser.Animation.generateFrameNames('explosion_', 1, 30, '-large', 4); +* +* @param {string} prefix - The start of the filename. If the filename was 'explosion_0001-large' the prefix would be 'explosion_'. +* @param {number} min - The number to start sequentially counting from. If your frames are named 'explosion_0001' to 'explosion_0034' the min is 1. +* @param {number} max - The number to count up to. If your frames are named 'explosion_0001' to 'explosion_0034' the max is 34. +* @param {string} [suffix=''] - The end of the filename. If the filename was 'explosion_0001-large' the prefix would be '-large'. +* @param {number} [zeroPad=0] - The number of zeroes to pad the min and max values with. If your frames are named 'explosion_0001' to 'explosion_0034' then the zeroPad is 4. +* @method generateFrameNames +*/ Phaser.Animation.generateFrameNames = function (prefix, min, max, suffix, zeroPad) { if (typeof suffix == 'undefined') { suffix = ''; } diff --git a/src/animation/AnimationManager.js b/src/animation/AnimationManager.js index 9bee583a..aadfcad6 100644 --- a/src/animation/AnimationManager.js +++ b/src/animation/AnimationManager.js @@ -1,75 +1,59 @@ /** * @author Richard Davey * @copyright 2013 Photon Storm Ltd. -* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License -* @module Phaser.Animation +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} +* @module Phaser.AnimationManager */ /** * The AnimationManager is used to add, play and update Phaser Animations. * Any Game Object such as Phaser.Sprite that supports animation contains a single AnimationManager instance. * -* @class AnimationManager +* @class Phaser.AnimationManager * @constructor -* @param {Phaser.Sprite} sprite A reference to the Game Object that owns this AnimationManager. +* @param {Phaser.Sprite} sprite - A reference to the Game Object that owns this AnimationManager. */ Phaser.AnimationManager = function (sprite) { /** - * A reference to the parent Sprite that owns this AnimationManager. - * @property sprite - * @public - * @type {Phaser.Sprite} + * @property {Phaser.Sprite} sprite - A reference to the parent Sprite that owns this AnimationManager. */ this.sprite = sprite; /** - * 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 = sprite.game; - /** - * The currently displayed Frame of animation, if any. - * @property currentFrame - * @public - * @type {Phaser.Animation.Frame} - */ + /** + * @property {Phaser.Animation.Frame} currentFrame - The currently displayed Frame of animation, if any. + * @default + */ this.currentFrame = null; - - /** - * Should the animation data continue to update even if the Sprite.visible is set to false. - * @property updateIfVisible - * @public - * @type {Boolean} - * @default true - */ + + /** + * @property {boolean} updateIfVisible - Should the animation data continue to update even if the Sprite.visible is set to false. + * @default + */ this.updateIfVisible = true; - /** - * A temp. var for holding the currently playing Animations FrameData. - * @property _frameData - * @private - * @type {Phaser.Animation.FrameData} - */ + /** + * @property {Phaser.Animation.FrameData} _frameData - A temp. var for holding the currently playing Animations FrameData. + * @private + * @default + */ this._frameData = null; - /** - * An internal object that stores all of the Animation instances. - * @property _anims - * @private - * @type {Object} - */ + /** + * @property {object} _anims - An internal object that stores all of the Animation instances. + * @private + */ this._anims = {}; - /** - * An internal object to help avoid gc. - * @property _outputFrames - * @private - * @type {Object} - */ + /** + * @property {object} _outputFrames - An internal object to help avoid gc. + * @private + */ this._outputFrames = []; }; @@ -82,7 +66,7 @@ Phaser.AnimationManager.prototype = { * * @method loadFrameData * @private - * @param {Phaser.Animation.FrameData} frameData The FrameData set to load. + * @param {Phaser.Animation.FrameData} frameData - The FrameData set to load. */ loadFrameData: function (frameData) { @@ -96,11 +80,11 @@ Phaser.AnimationManager.prototype = { * Animations added in this way are played back with the play function. * * @method add - * @param {String} name The unique (within this Sprite) name for the animation, i.e. "run", "fire", "walk". - * @param {Array} [frames=null] An array of numbers/strings that correspond to the frames to add to this animation and in which order. e.g. [1, 2, 3] or ['run0', 'run1', run2]). If null then all frames will be used. - * @param {Number} [frameRate=60] The speed at which the animation should play. The speed is given in frames per second. - * @param {Boolean} [loop=false] {bool} Whether or not the animation is looped or just plays once. - * @param {Boolean} [useNumericIndex=true] Are the given frames using numeric indexes (default) or strings? (false) + * @param {string} name - The unique (within this Sprite) name for the animation, i.e. "run", "fire", "walk". + * @param {Array} [frames=null] - An array of numbers/strings that correspond to the frames to add to this animation and in which order. e.g. [1, 2, 3] or ['run0', 'run1', run2]). If null then all frames will be used. + * @param {number} [frameRate=60] - The speed at which the animation should play. The speed is given in frames per second. + * @param {boolean} [loop=false] {boolean} - Whether or not the animation is looped or just plays once. + * @param {boolean} [useNumericIndex=true] - Are the given frames using numeric indexes (default) or strings? * @return {Phaser.Animation} The Animation object that was created. */ add: function (name, frames, frameRate, loop, useNumericIndex) { @@ -141,9 +125,9 @@ Phaser.AnimationManager.prototype = { * Check whether the frames in the given array are valid and exist. * * @method validateFrames - * @param {Array} frames An array of frames to be validated. - * @param {Boolean} [useNumericIndex=true] Validate the frames based on their numeric index (true) or string index (false) - * @return {Boolean} True if all given Frames are valid, otherwise false. + * @param {Array} frames - An array of frames to be validated. + * @param {boolean} [useNumericIndex=true] - Validate the frames based on their numeric index (true) or string index (false) + * @return {boolean} True if all given Frames are valid, otherwise false. */ validateFrames: function (frames, useNumericIndex) { @@ -176,9 +160,9 @@ Phaser.AnimationManager.prototype = { * If the requested animation is already playing this request will be ignored. If you need to reset an already running animation do so directly on the Animation object itself. * * @method play - * @param {String} name The name of the animation to be played, e.g. "fire", "walk", "jump". - * @param {Number} [frameRate=null] The framerate to play the animation at. The speed is given in frames per second. If not provided the previously set frameRate of the Animation is used. - * @param {Boolean} [loop=null] Should the animation be looped after playback. If not provided the previously set loop value of the Animation is used. + * @param {string} name - The name of the animation to be played, e.g. "fire", "walk", "jump". + * @param {number} [frameRate=null] - The framerate to play the animation at. The speed is given in frames per second. If not provided the previously set frameRate of the Animation is used. + * @param {boolean} [loop=null] - Should the animation be looped after playback. If not provided the previously set loop value of the Animation is used. * @return {Phaser.Animation} A reference to playing Animation instance. */ play: function (name, frameRate, loop) { @@ -206,8 +190,8 @@ Phaser.AnimationManager.prototype = { * The currentAnim property of the AnimationManager is automatically set to the animation given. * * @method stop - * @param {String} [name=null] The name of the animation to be stopped, e.g. "fire". If none is given the currently running animation is stopped. - * @param {Boolean} [resetFrame=false] When the animation is stopped should the currentFrame be set to the first frame of the animation (true) or paused on the last frame displayed (false) + * @param {string} [name=null] - The name of the animation to be stopped, e.g. "fire". If none is given the currently running animation is stopped. + * @param {boolean} [resetFrame=false] - When the animation is stopped should the currentFrame be set to the first frame of the animation (true) or paused on the last frame displayed (false) */ stop: function (name, resetFrame) { @@ -236,7 +220,7 @@ Phaser.AnimationManager.prototype = { * * @method update * @protected - * @return {Boolean} True if a new animation frame has been set, otherwise false. + * @return {boolean} True if a new animation frame has been set, otherwise false. */ update: function () { @@ -273,24 +257,22 @@ Phaser.AnimationManager.prototype = { }; +/** +* @return {Phaser.Animation.FrameData} Returns the FrameData of the current animation. +*/ Object.defineProperty(Phaser.AnimationManager.prototype, "frameData", { - /** - * @method frameData - * @return {Phaser.Animation.FrameData} Returns the FrameData of the current animation. - */ get: function () { return this._frameData; } }); +/** +* @return {number} Returns the total number of frames in the loaded FrameData, or -1 if no FrameData is loaded. +*/ Object.defineProperty(Phaser.AnimationManager.prototype, "frameTotal", { - - /** - * @method frameTotal - * @return {Number} Returns the total number of frames in the loaded FrameData, or -1 if no FrameData is loaded. - */ + get: function () { if (this._frameData) @@ -305,6 +287,11 @@ Object.defineProperty(Phaser.AnimationManager.prototype, "frameTotal", { }); +/** +* @return {boolean} Returns the paused state of the current animation. +*//** +* @param {boolean} value - Sets the paused state of the current animation. +*/ Object.defineProperty(Phaser.AnimationManager.prototype, "paused", { get: function () { @@ -321,12 +308,13 @@ Object.defineProperty(Phaser.AnimationManager.prototype, "paused", { }); +/** +* @return {number} Returns the index of the current frame. +*//** +* @param {number} value - Sets the current frame on the Sprite and updates the texture cache for display. +*/ Object.defineProperty(Phaser.AnimationManager.prototype, "frame", { - /** - * @method frame - * @return {Number} Returns the index of the current frame. - */ get: function () { if (this.currentFrame) @@ -336,10 +324,6 @@ Object.defineProperty(Phaser.AnimationManager.prototype, "frame", { }, - /** - * @method frame - * @param {Number} value Sets the current frame on the Sprite and updates the texture cache for display. - */ set: function (value) { if (this._frameData && this._frameData.getFrame(value) !== null) @@ -354,12 +338,13 @@ Object.defineProperty(Phaser.AnimationManager.prototype, "frame", { }); +/** +* @return {string} Returns the name of the current frame if it has one. +*//** +* @param {string} value - Sets the current frame on the Sprite and updates the texture cache for display. +*/ Object.defineProperty(Phaser.AnimationManager.prototype, "frameName", { - /** - * @method frameName - * @return {String} Returns the name of the current frame if it has one. - */ get: function () { if (this.currentFrame) @@ -369,10 +354,6 @@ Object.defineProperty(Phaser.AnimationManager.prototype, "frameName", { }, - /** - * @method frameName - * @param {String} value Sets the current frame on the Sprite and updates the texture cache for display. - */ set: function (value) { if (this._frameData && this._frameData.getFrameByName(value) !== null) diff --git a/src/animation/Frame.js b/src/animation/Frame.js index 35132c13..0ec9e9fa 100644 --- a/src/animation/Frame.js +++ b/src/animation/Frame.js @@ -1,180 +1,124 @@ /** * @author Richard Davey * @copyright 2013 Photon Storm Ltd. -* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License -* @module Phaser.Animation +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} +* @module Phaser.Frame */ /** * A Frame is a single frame of an animation and is part of a FrameData collection. * -* @class Frame +* @class Phaser.Animation.Frame * @constructor -* @param {Number} index The index of this Frame within the FrameData set it is being added to. -* @param {Number} x X position of the frame within the texture image. -* @param {Number} y Y position of the frame within the texture image. -* @param {Number} width Width of the frame within the texture image. -* @param {Number} height Height of the frame within the texture image. -* @param {String} name The name of the frame. In Texture Atlas data this is usually set to the filename. -* @param {String} uuid Internal UUID key. +* @param {number} index - The index of this Frame within the FrameData set it is being added to. +* @param {number} x - X position of the frame within the texture image. +* @param {number} y - Y position of the frame within the texture image. +* @param {number} width - Width of the frame within the texture image. +* @param {number} height - Height of the frame within the texture image. +* @param {string} name - The name of the frame. In Texture Atlas data this is usually set to the filename. +* @param {string} uuid - Internal UUID key. */ Phaser.Animation.Frame = function (index, x, y, width, height, name, uuid) { /** - * The index of this Frame within the FrameData set it is being added to. - * @property index - * @public - * @type {Number} + * @property {number} index - The index of this Frame within the FrameData set it is being added to. */ this.index = index; - + /** - * X position within the image to cut from. - * @property x - * @public - * @type {Number} + * @property {number} x - X position within the image to cut from. */ this.x = x; /** - * Y position within the image to cut from. - * @property y - * @public - * @type {Number} + * @property {number} y - Y position within the image to cut from. */ this.y = y; /** - * Width of the frame. - * @property width - * @public - * @type {Number} + * @property {number} width - Width of the frame. */ this.width = width; /** - * Height of the frame. - * @property height - * @public - * @type {Number} + * @property {number} height - Height of the frame. */ this.height = height; /** - * Useful for Texture Atlas files. (is set to the filename value) - * @property name - * @public - * @type {String} + * @property {string} name - Useful for Texture Atlas files (is set to the filename value). */ this.name = name; /** - * A link to the PIXI.TextureCache entry - * @property uuid - * @public - * @type {String} + * @property {string} uuid - A link to the PIXI.TextureCache entry. */ this.uuid = uuid; /** - * center X position within the image to cut from. - * @property centerX - * @public - * @type {Number} + * @property {number} centerX - Center X position within the image to cut from. */ this.centerX = Math.floor(width / 2); /** - * center Y position within the image to cut from. - * @property centerY - * @public - * @type {Number} + * @property {number} centerY - Center Y position within the image to cut from. */ this.centerY = Math.floor(height / 2); /** - * The distance from the top left to the bottom-right of this Frame. - * @property distance - * @public - * @type {Number} + * @property {number} distance - The distance from the top left to the bottom-right of this Frame. */ this.distance = Phaser.Math.distance(0, 0, width, height); /** - * Rotated? (not yet implemented) - * @property rotated - * @public - * @type {Boolean} - * @default false + * @property {bool} rotated - Rotated? (not yet implemented) + * @default */ this.rotated = false; /** - * Either cw or ccw, rotation is always 90 degrees. - * @property rotationDirection - * @public - * @type {String} - * @default "cw" + * @property {string} rotationDirection - Either 'cw' or 'ccw', rotation is always 90 degrees. + * @default 'cw' */ this.rotationDirection = 'cw'; /** - * Was it trimmed when packed? - * @property trimmed - * @public - * @type {Boolean} + * @property {bool} trimmed - Was it trimmed when packed? + * @default */ this.trimmed = false; /** - * Width of the original sprite. - * @property sourceSizeW - * @public - * @type {Number} + * @property {number} sourceSizeW - Width of the original sprite. */ this.sourceSizeW = width; /** - * Height of the original sprite. - * @property sourceSizeH - * @public - * @type {Number} + * @property {number} sourceSizeH - Height of the original sprite. */ this.sourceSizeH = height; /** - * X position of the trimmed sprite inside original sprite. - * @property spriteSourceSizeX - * @public - * @type {Number} - * @default 0 + * @property {number} spriteSourceSizeX - X position of the trimmed sprite inside original sprite. + * @default */ this.spriteSourceSizeX = 0; /** - * Y position of the trimmed sprite inside original sprite. - * @property spriteSourceSizeY - * @public - * @type {Number} - * @default 0 + * @property {number} spriteSourceSizeY - Y position of the trimmed sprite inside original sprite. + * @default */ this.spriteSourceSizeY = 0; /** - * Width of the trimmed sprite. - * @property spriteSourceSizeW - * @public - * @type {Number} - * @default 0 + * @property {number} spriteSourceSizeW - Width of the trimmed sprite. + * @default */ this.spriteSourceSizeW = 0; /** - * Height of the trimmed sprite. - * @property spriteSourceSizeH - * @public - * @type {Number} - * @default 0 + * @property {number} spriteSourceSizeH - Height of the trimmed sprite. + * @default */ this.spriteSourceSizeH = 0; @@ -186,13 +130,13 @@ Phaser.Animation.Frame.prototype = { * If the frame was trimmed when added to the Texture Atlas this records the trim and source data. * * @method setTrim - * @param {Boolean} trimmed If this frame was trimmed or not. - * @param {Number} actualWidth The width of the frame before being trimmed. - * @param {Number} actualHeight The height of the frame before being trimmed. - * @param {Number} destX The destination X position of the trimmed frame for display. - * @param {Number} destY The destination Y position of the trimmed frame for display. - * @param {Number} destWidth The destination width of the trimmed frame for display. - * @param {Number} destHeight The destination height of the trimmed frame for display. + * @param {bool} trimmed - If this frame was trimmed or not. + * @param {number} actualWidth - The width of the frame before being trimmed. + * @param {number} actualHeight - The height of the frame before being trimmed. + * @param {number} destX - The destination X position of the trimmed frame for display. + * @param {number} destY - The destination Y position of the trimmed frame for display. + * @param {number} destWidth - The destination width of the trimmed frame for display. + * @param {number} destHeight - The destination height of the trimmed frame for display. */ setTrim: function (trimmed, actualWidth, actualHeight, destX, destY, destWidth, destHeight) { diff --git a/src/animation/FrameData.js b/src/animation/FrameData.js index b4f5d407..9f57e5dd 100644 --- a/src/animation/FrameData.js +++ b/src/animation/FrameData.js @@ -1,32 +1,29 @@ /** * @author Richard Davey * @copyright 2013 Photon Storm Ltd. -* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License -* @module Phaser.Animation.FrameData +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} +* @module Phaser.FrameData */ /** * FrameData is a container for Frame objects, which are the internal representation of animation data in Phaser. * -* @class FrameData +* @class Phaser.Animation.FrameData * @constructor */ Phaser.Animation.FrameData = function () { - /** - * Local array of frames. - * @property _frames - * @private - * @type {Array} - */ + /** + * @property {Array} _frames - Local array of frames. + * @private + */ this._frames = []; - /** - * Local array of frame names for name to index conversions. - * @property _frameNames - * @private - * @type {Array} - */ + + /** + * @property {Array} _frameNames - Local array of frame names for name to index conversions. + * @private + */ this._frameNames = []; }; @@ -37,7 +34,7 @@ Phaser.Animation.FrameData.prototype = { * Adds a new Frame to this FrameData collection. Typically called by the Animation.Parser and not directly. * * @method addFrame - * @param {Phaser.Animation.Frame} frame The frame to add to this FrameData set. + * @param {Phaser.Animation.Frame} frame - The frame to add to this FrameData set. * @return {Phaser.Animation.Frame} The frame that was just added. */ addFrame: function (frame) { @@ -59,7 +56,7 @@ Phaser.Animation.FrameData.prototype = { * Get a Frame by its numerical index. * * @method getFrame - * @param {Number} index The index of the frame you want to get. + * @param {number} index - The index of the frame you want to get. * @return {Phaser.Animation.Frame} The frame, if found. */ getFrame: function (index) { @@ -77,7 +74,7 @@ Phaser.Animation.FrameData.prototype = { * Get a Frame by its frame name. * * @method getFrameByName - * @param {String} name The name of the frame you want to get. + * @param {string} name - The name of the frame you want to get. * @return {Phaser.Animation.Frame} The frame, if found. */ getFrameByName: function (name) { @@ -95,8 +92,8 @@ Phaser.Animation.FrameData.prototype = { * Check if there is a Frame with the given name. * * @method checkFrameName - * @param {String} name The name of the frame you want to check. - * @return {Boolean} True if the frame is found, otherwise false. + * @param {string} name - The name of the frame you want to check. + * @return {boolean} True if the frame is found, otherwise false. */ checkFrameName: function (name) { @@ -113,9 +110,9 @@ Phaser.Animation.FrameData.prototype = { * Returns a range of frames based on the given start and end frame indexes and returns them in an Array. * * @method getFrameRange - * @param {Number} start The starting frame index. - * @param {Number} end The ending frame index. - * @param {Array} [output] Optional array. If given the results will be appended to the end of this Array. + * @param {number} start - The starting frame index. + * @param {number} end - The ending frame index. + * @param {Array} [output] - If given the results will be appended to the end of this array otherwise a new array will be created. * @return {Array} An array of Frames between the start and end index values, or an empty array if none were found. */ getFrameRange: function (start, end, output) { @@ -136,9 +133,9 @@ Phaser.Animation.FrameData.prototype = { * The frames are returned in the output array, or if none is provided in a new Array object. * * @method getFrames - * @param {Array} frames An Array containing the indexes of the frames to retrieve. If the array is empty then all frames in the FrameData are returned. - * @param {Boolean} [useNumericIndex=true] Are the given frames using numeric indexes (default) or strings? (false) - * @param {Array} [output] Optional array. If given the results will be appended to the end of this Array, otherwise a new array is created. + * @param {Array} frames - An Array containing the indexes of the frames to retrieve. If the array is empty then all frames in the FrameData are returned. + * @param {boolean} [useNumericIndex=true] - Are the given frames using numeric indexes (default) or strings? (false) + * @param {Array} [output] - If given the results will be appended to the end of this array otherwise a new array will be created. * @return {Array} An array of all Frames in this FrameData set matching the given names or IDs. */ getFrames: function (frames, useNumericIndex, output) { @@ -183,9 +180,9 @@ Phaser.Animation.FrameData.prototype = { * The frames indexes are returned in the output array, or if none is provided in a new Array object. * * @method getFrameIndexes - * @param {Array} frames An Array containing the indexes of the frames to retrieve. If the array is empty then all frames in the FrameData are returned. - * @param {Boolean} [useNumericIndex=true] Are the given frames using numeric indexes (default) or strings? (false) - * @param {Array} [output] Optional array. If given the results will be appended to the end of this Array, otherwise a new array is created. + * @param {Array} frames - An Array containing the indexes of the frames to retrieve. If the array is empty then all frames in the FrameData are returned. + * @param {boolean} [useNumericIndex=true] - Are the given frames using numeric indexes (default) or strings? (false) + * @param {Array} [output] - If given the results will be appended to the end of this array otherwise a new array will be created. * @return {Array} An array of all Frame indexes matching the given names or IDs. */ getFrameIndexes: function (frames, useNumericIndex, output) { diff --git a/src/animation/Parser.js b/src/animation/Parser.js index 46df1d6a..6341db1c 100644 --- a/src/animation/Parser.js +++ b/src/animation/Parser.js @@ -1,23 +1,26 @@ +/** +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} +* @module Phaser.Animation.Parser +*/ + /** * Responsible for parsing sprite sheet and JSON data into the internal FrameData format that Phaser uses for animations. * -* @author Richard Davey -* @copyright 2013 Photon Storm Ltd. -* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License -* @module Phaser.Animation +* @class Phaser.Animation.Parser */ - Phaser.Animation.Parser = { /** * Parse a Sprite Sheet and extract the animation frame data from it. * * @method spriteSheet - * @param {Phaser.Game} game A reference to the currently running game. - * @param {String} key The Game.Cache asset key of the Sprite Sheet image. - * @param {Number} frameWidth The fixed width of each frame of the animation. If negative, indicates how many columns there are. - * @param {Number} frameHeight The fixed height of each frame of the animation. If negative, indicates how many rows there are. - * @param {Number} [frameMax=-1] The total number of animation frames to extact from the Sprite Sheet. The default value of -1 means "extract all frames". + * @param {Phaser.Game} game - A reference to the currently running game. + * @param {string} key - The Game.Cache asset key of the Sprite Sheet image. + * @param {number} frameWidth - The fixed width of each frame of the animation. + * @param {number} frameHeight - The fixed height of each frame of the animation. + * @param {number} [frameMax=-1] - The total number of animation frames to extact from the Sprite Sheet. The default value of -1 means "extract all frames". * @return {Phaser.Animation.FrameData} A FrameData object containing the parsed frames. */ spriteSheet: function (game, key, frameWidth, frameHeight, frameMax) { @@ -32,14 +35,17 @@ Phaser.Animation.Parser = { var width = img.width; var height = img.height; + if (frameWidth <= 0) { - frameWidth = Math.floor(-width/Math.min(-1, frameWidth)); + frameWidth = Math.floor(-width / Math.min(-1, frameWidth)); } + if (frameHeight <= 0) { - frameHeight = Math.floor(-height/Math.min(-1, frameHeight)); + frameHeight = Math.floor(-height / Math.min(-1, frameHeight)); } + var row = Math.round(width / frameWidth); var column = Math.round(height / frameHeight); var total = row * column; @@ -91,9 +97,9 @@ Phaser.Animation.Parser = { * Parse the JSON data and extract the animation frame data from it. * * @method JSONData - * @param {Phaser.Game} game A reference to the currently running game. - * @param {Object} json The JSON data from the Texture Atlas. Must be in Array format. - * @param {String} cacheKey The Game.Cache asset key of the texture image. + * @param {Phaser.Game} game - A reference to the currently running game. + * @param {Object} json - The JSON data from the Texture Atlas. Must be in Array format. + * @param {string} cacheKey - The Game.Cache asset key of the texture image. * @return {Phaser.Animation.FrameData} A FrameData object containing the parsed frames. */ JSONData: function (game, json, cacheKey) { @@ -162,9 +168,9 @@ Phaser.Animation.Parser = { * Parse the JSON data and extract the animation frame data from it. * * @method JSONDataHash - * @param {Phaser.Game} game A reference to the currently running game. - * @param {Object} json The JSON data from the Texture Atlas. Must be in JSON Hash format. - * @param {String} cacheKey The Game.Cache asset key of the texture image. + * @param {Phaser.Game} game - A reference to the currently running game. + * @param {Object} json - The JSON data from the Texture Atlas. Must be in JSON Hash format. + * @param {string} cacheKey - The Game.Cache asset key of the texture image. * @return {Phaser.Animation.FrameData} A FrameData object containing the parsed frames. */ JSONDataHash: function (game, json, cacheKey) { @@ -236,9 +242,9 @@ Phaser.Animation.Parser = { * Parse the XML data and extract the animation frame data from it. * * @method XMLData - * @param {Phaser.Game} game A reference to the currently running game. - * @param {Object} xml The XML data from the Texture Atlas. Must be in Starling XML format. - * @param {String} cacheKey The Game.Cache asset key of the texture image. + * @param {Phaser.Game} game - A reference to the currently running game. + * @param {Object} xml - The XML data from the Texture Atlas. Must be in Starling XML format. + * @param {string} cacheKey - The Game.Cache asset key of the texture image. * @return {Phaser.Animation.FrameData} A FrameData object containing the parsed frames. */ XMLData: function (game, xml, cacheKey) { diff --git a/src/core/Camera.js b/src/core/Camera.js index e5da9e26..c2ee4286 100644 --- a/src/core/Camera.js +++ b/src/core/Camera.js @@ -1,7 +1,7 @@ /** * @author Richard Davey * @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; } diff --git a/src/core/Game.js b/src/core/Game.js index bf73da33..6492b9d1 100644 --- a/src/core/Game.js +++ b/src/core/Game.js @@ -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 -* @copyright 2013 Photon Storm Ltd. -* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License +* @author Richard Davey +* @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 Phaser.Game 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. +*

"Hell, there are no rules here - we're trying to accomplish something."


+* 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 () { diff --git a/src/core/Group.js b/src/core/Group.js index 62910ffd..4e17ff85 100644 --- a/src/core/Group.js +++ b/src/core/Group.js @@ -1,3 +1,21 @@ +/** +* @author Richard Davey +* @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 () { diff --git a/src/core/LinkedList.js b/src/core/LinkedList.js index 23eb1d1c..8f440aff 100644 --- a/src/core/LinkedList.js +++ b/src/core/LinkedList.js @@ -1,16 +1,59 @@ +/** +* @author Richard Davey +* @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; diff --git a/src/core/Plugin.js b/src/core/Plugin.js index ef1a967a..4b5374d3 100644 --- a/src/core/Plugin.js +++ b/src/core/Plugin.js @@ -1,19 +1,67 @@ /** -* Phaser - Plugin -* -* This is a base Plugin template to use for any Phaser plugin development +* @author Richard Davey +* @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; }; diff --git a/src/core/PluginManager.js b/src/core/PluginManager.js index a4074f7a..0e7558b1 100644 --- a/src/core/PluginManager.js +++ b/src/core/PluginManager.js @@ -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 +* @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; diff --git a/src/core/Signal.js b/src/core/Signal.js index cc5f4383..5502d0ec 100644 --- a/src/core/Signal.js +++ b/src/core/Signal.js @@ -1,23 +1,40 @@ /** -* Phaser.Signal -* +* @author Richard Davey +* @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. - * @private - */ + * @property {Array.} _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. - *

IMPORTANT: 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.

- * @type boolean - */ + * If Signal is active and should broadcast events. + *

IMPORTANT: 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.

+ * @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. - *

IMPORTANT: should be called only during signal dispatch, calling it before/after dispatch won't affect signal broadcast.

- * @see Signal.prototype.disable - */ + * Stop propagation of the event, blocking the dispatch to next listeners on the queue. + *

IMPORTANT: should be called only during signal dispatch, calling it before/after dispatch won't affect signal broadcast.

+ * @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; diff --git a/src/core/SignalBinding.js b/src/core/SignalBinding.js index 3617838d..e61b31a2 100644 --- a/src/core/SignalBinding.js +++ b/src/core/SignalBinding.js @@ -1,3 +1,11 @@ +/** +* @author Richard Davey +* @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 @@ *
- This is an internal constructor and shouldn't be called by regular users. *
- 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. - *

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.

- * @param {Array} [paramsArr] Array of parameters that should be passed to the listener - * @return {*} Value returned by the listener. - */ + * Call listener passing arbitrary parameters. + *

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.

+ * @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. + *

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 + ']'; } diff --git a/src/core/Stage.js b/src/core/Stage.js index c4deb68c..269243b2 100644 --- a/src/core/Stage.js +++ b/src/core/Stage.js @@ -1,7 +1,7 @@ /** * @author Richard Davey * @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 element - * @property canvas - * @public - * @type {HTMLCanvasElement} + * @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%'; /** - * 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; diff --git a/src/core/State.js b/src/core/State.js index 42fb59e6..0613d8f5 100644 --- a/src/core/State.js +++ b/src/core/State.js @@ -1,30 +1,101 @@ /** -* State -* +* @author Richard Davey +* @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 -* @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 () { } diff --git a/src/core/StateManager.js b/src/core/StateManager.js index da190432..3bbf58d2 100644 --- a/src/core/StateManager.js +++ b/src/core/StateManager.js @@ -1,7 +1,30 @@ +/** +* @author Richard Davey +* @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 () { diff --git a/src/core/World.js b/src/core/World.js index 5f100a6d..585be20d 100644 --- a/src/core/World.js +++ b/src/core/World.js @@ -1,71 +1,55 @@ /** * @author Richard Davey * @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 - * + *

* 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); } diff --git a/src/gameobjects/BitmapText.js b/src/gameobjects/BitmapText.js index 42dfaf11..0f5ec0a4 100644 --- a/src/gameobjects/BitmapText.js +++ b/src/gameobjects/BitmapText.js @@ -1,37 +1,98 @@ +/** +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} +* @module Phaser.BitmapText +*/ + +/** +* 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. +* +* @class Phaser.BitmapText +* @constructor +* @param {Phaser.Game} game - A reference to the currently running game. +* @param {number} x - X position of Description. +* @param {number} y - Y position of Description. +* @param {string} text - Description. +* @param {string} style - Description. +*/ Phaser.BitmapText = function (game, x, y, text, style) { x = x || 0; y = y || 0; + text = text || ''; style = style || ''; - // If exists = false then the Sprite isn't updated by the core game loop or physics subsystem at all + /** + * @property {bool} exists - If exists = false then the Sprite isn't updated by the core game loop or physics subsystem at all. + * @default + */ this.exists = true; - // This is a handy little var your game can use to determine if a sprite is alive or not, it doesn't effect rendering + /** + * @property {bool} alive - This is a handy little var your game can use to determine if a sprite is alive or not, it doesn't effect rendering. + * @default + */ this.alive = true; + /** + * @property {Description} group - Description. + * @default + */ this.group = null; + /** + * @property {string} name - Description. + * @default + */ this.name = ''; + /** + * @property {Phaser.Game} game - A reference to the currently running Game. + */ this.game = game; PIXI.BitmapText.call(this, text, style); + /** + * @property {Description} type - Description. + */ this.type = Phaser.BITMAPTEXT; + /** + * @property {number} position.x - Description. + */ this.position.x = x; + + /** + * @property {number} position.y - Description. + */ this.position.y = y; // Replaces the PIXI.Point with a slightly more flexible one + /** + * @property {Phaser.Point} anchor - Description. + */ this.anchor = new Phaser.Point(); + + /** + * @property {Phaser.Point} scale - Description. + */ this.scale = new Phaser.Point(1, 1); // Influence of camera movement upon the position + /** + * @property {Phaser.Point} scrollFactor - Description. + */ this.scrollFactor = new Phaser.Point(1, 1); // A mini cache for storing all of the calculated values + /** + * @property {function} _cache - Description. + * @private + */ this._cache = { dirty: false, @@ -50,6 +111,10 @@ Phaser.BitmapText = function (game, x, y, text, style) { this._cache.x = this.x - (this.game.world.camera.x * this.scrollFactor.x); this._cache.y = this.y - (this.game.world.camera.y * this.scrollFactor.y); + /** + * @property {bool} renderable - Description. + * @private + */ this.renderable = true; }; @@ -59,8 +124,9 @@ Phaser.BitmapText.prototype = Object.create(PIXI.BitmapText.prototype); Phaser.BitmapText.prototype.constructor = Phaser.BitmapText; /** - * Automatically called by World.update - */ +* Automatically called by World.update +* @method Phaser.BitmapText.prototype.update +*/ Phaser.BitmapText.prototype.update = function() { if (!this.exists) @@ -85,6 +151,13 @@ Phaser.BitmapText.prototype.update = function() { } +/** +* Get +* @returns {Description} +*//** +* Set +* @param {Description} value - Description +*/ Object.defineProperty(Phaser.BitmapText.prototype, 'angle', { get: function() { @@ -97,6 +170,13 @@ Object.defineProperty(Phaser.BitmapText.prototype, 'angle', { }); +/** +* Get +* @returns {Description} +*//** +* Set +* @param {Description} value - Description +*/ Object.defineProperty(Phaser.BitmapText.prototype, 'x', { get: function() { @@ -109,6 +189,13 @@ Object.defineProperty(Phaser.BitmapText.prototype, 'x', { }); +/** +* Get +* @returns {Description} +*//** +* Set +* @param {Description} value - Description +*/ Object.defineProperty(Phaser.BitmapText.prototype, 'y', { get: function() { diff --git a/src/gameobjects/Button.js b/src/gameobjects/Button.js index 0ed5c731..9173f4fd 100644 --- a/src/gameobjects/Button.js +++ b/src/gameobjects/Button.js @@ -1,13 +1,14 @@ /** * @author Richard Davey * @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.Button */ + /** * Create a new Button object. -* @class Button +* @class Phaser.Button * @constructor * * @param {Phaser.Game} game Current game instance. @@ -22,7 +23,6 @@ */ Phaser.Button = function (game, x, y, key, callback, callbackContext, overFrame, outFrame, downFrame) { - x = x || 0; y = y || 0; key = key || null; @@ -31,21 +31,86 @@ Phaser.Button = function (game, x, y, key, callback, callbackContext, overFrame, Phaser.Sprite.call(this, game, x, y, key, outFrame); + /** + * @property {Description} type - Description. + */ this.type = Phaser.BUTTON; + /** + * @property {Description} _onOverFrameName - Description. + * @private + * @default + */ this._onOverFrameName = null; + + /** + * @property {Description} _onOutFrameName - Description. + * @private + * @default + */ this._onOutFrameName = null; + + /** + * @property {Description} _onDownFrameName - Description. + * @private + * @default + */ this._onDownFrameName = null; + + /** + * @property {Description} _onUpFrameName - Description. + * @private + * @default + */ this._onUpFrameName = null; + + /** + * @property {Description} _onOverFrameID - Description. + * @private + * @default + */ this._onOverFrameID = null; + + /** + * @property {Description} _onOutFrameID - Description. + * @private + * @default + */ this._onOutFrameID = null; + + /** + * @property {Description} _onDownFrameID - Description. + * @private + * @default + */ this._onDownFrameID = null; + + /** + * @property {Description} _onUpFrameID - Description. + * @private + * @default + */ this._onUpFrameID = null; // These are the signals the game will subscribe to + /** + * @property {Phaser.Signal} onInputOver - Description. + */ this.onInputOver = new Phaser.Signal; + + /** + * @property {Phaser.Signal} onInputOut - Description. + */ this.onInputOut = new Phaser.Signal; + + /** + * @property {Phaser.Signal} onInputDown - Description. + */ this.onInputDown = new Phaser.Signal; + + /** + * @property {Phaser.Signal} onInputUp - Description. + */ this.onInputUp = new Phaser.Signal; this.setFrames(overFrame, outFrame, downFrame); @@ -70,12 +135,12 @@ Phaser.Button.prototype.constructor = Phaser.Button; /** * Used to manually set the frames that will be used for the different states of the button -* exactly like setting them in the constructor +* exactly like setting them in the constructor. * -* @method setFrames -* @param {string|number} [overFrame] This is the frame or frameName that will be set when this button is in an over state. Give either a number to use a frame ID or a string for a frame name. -* @param {string|number} [outFrame] This is the frame or frameName that will be set when this button is in an out state. Give either a number to use a frame ID or a string for a frame name. -* @param {string|number} [downFrame] This is the frame or frameName that will be set when this button is in a down state. Give either a number to use a frame ID or a string for a frame name. +* @method Phaser.Button.prototype.setFrames +* @param {string|number} [overFrame] - This is the frame or frameName that will be set when this button is in an over state. Give either a number to use a frame ID or a string for a frame name. +* @param {string|number} [outFrame] - This is the frame or frameName that will be set when this button is in an out state. Give either a number to use a frame ID or a string for a frame name. +* @param {string|number} [downFrame] - This is the frame or frameName that will be set when this button is in a down state. Give either a number to use a frame ID or a string for a frame name. */ Phaser.Button.prototype.setFrames = function (overFrame, outFrame, downFrame) { @@ -149,6 +214,12 @@ Phaser.Button.prototype.setFrames = function (overFrame, outFrame, downFrame) { }; +/** +* Description. +* +* @method Phaser.Button.prototype.onInputOverHandler +* @param {Description} pointer - Description. +*/ Phaser.Button.prototype.onInputOverHandler = function (pointer) { if (this._onOverFrameName != null) @@ -166,6 +237,12 @@ Phaser.Button.prototype.onInputOverHandler = function (pointer) { } }; +/** +* Description. +* +* @method Phaser.Button.prototype.onInputOutHandler +* @param {Description} pointer - Description. +*/ Phaser.Button.prototype.onInputOutHandler = function (pointer) { if (this._onOutFrameName != null) @@ -181,9 +258,14 @@ Phaser.Button.prototype.onInputOutHandler = function (pointer) { { this.onInputOut.dispatch(this, pointer); } - }; +/** +* Description. +* +* @method Phaser.Button.prototype.onInputDownHandler +* @param {Description} pointer - Description. +*/ Phaser.Button.prototype.onInputDownHandler = function (pointer) { if (this._onDownFrameName != null) @@ -201,6 +283,12 @@ Phaser.Button.prototype.onInputDownHandler = function (pointer) { } }; +/** +* Description. +* +* @method Phaser.Button.prototype.onInputUpHandler +* @param {Description} pointer - Description. +*/ Phaser.Button.prototype.onInputUpHandler = function (pointer) { if (this._onUpFrameName != null) diff --git a/src/gameobjects/Events.js b/src/gameobjects/Events.js index 09329ef9..e1e3c85d 100644 --- a/src/gameobjects/Events.js +++ b/src/gameobjects/Events.js @@ -1,6 +1,18 @@ +/** +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} +* @module Phaser.Events +*/ + + /** * The Events component is a collection of events fired by the parent game object and its components. -* @param parent The game object using this Input component +* +* @class Phaser.Events +* @constructor +* +* @param {Phaser.Sprite} sprite - A reference to Description. */ Phaser.Events = function (sprite) { diff --git a/src/gameobjects/GameObjectFactory.js b/src/gameobjects/GameObjectFactory.js index 7ce7cf5b..b5d671c9 100644 --- a/src/gameobjects/GameObjectFactory.js +++ b/src/gameobjects/GameObjectFactory.js @@ -1,15 +1,51 @@ +/** +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} +* @module Phaser.GameObjectFactory +*/ + +/** +* Description. +* +* @class Phaser.GameObjectFactory +* @constructor +* @param {Phaser.Game} game - A reference to the currently running game. +*/ Phaser.GameObjectFactory = function (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 = this.game.world; }; Phaser.GameObjectFactory.prototype = { + /** + * @property {Phaser.Game} game - A reference to the currently running Game. + * @default + */ game: null, + + /** + * @property {Phaser.World} world - A reference to the game world. + * @default + */ world: null, + /** + * Description. + * @method existing. + * @param {object} - Description. + * @return {bool} Description. + */ existing: function (object) { return this.world.group.add(object); @@ -19,11 +55,12 @@ Phaser.GameObjectFactory.prototype = { /** * Create a new Sprite with specific position and sprite sheet key. * - * @param x {number} X position of the new sprite. - * @param y {number} Y position of the new sprite. - * @param [key] {string|RenderTexture} The image key as defined in the Game.Cache to use as the texture for this sprite OR a RenderTexture - * @param [frame] {string|number} If the sprite uses an image from a texture atlas or sprite sheet you can pass the frame here. Either a number for a frame ID or a string for a frame name. - * @returns {Sprite} The newly created sprite object. + * @method sprite + * @param {number} x - X position of the new sprite. + * @param {number} y - Y position of the new sprite. + * @param {string|RenderTexture} [key] - The image key as defined in the Game.Cache to use as the texture for this sprite OR a RenderTexture. + * @param {string|number} [frame] - If the sprite uses an image from a texture atlas or sprite sheet you can pass the frame here. Either a number for a frame ID or a string for a frame name. + * @returns {Description} Description. */ sprite: function (x, y, key, frame) { @@ -34,11 +71,12 @@ Phaser.GameObjectFactory.prototype = { /** * Create a new Sprite with specific position and sprite sheet key that will automatically be added as a child of the given parent. * - * @param x {number} X position of the new sprite. - * @param y {number} Y position of the new sprite. - * @param [key] {string|RenderTexture} The image key as defined in the Game.Cache to use as the texture for this sprite OR a RenderTexture - * @param [frame] {string|number} If the sprite uses an image from a texture atlas or sprite sheet you can pass the frame here. Either a number for a frame ID or a string for a frame name. - * @returns {Sprite} The newly created sprite object. + * @method child + * @param {number} x - X position of the new sprite. + * @param {number} y - Y position of the new sprite. + * @param {string|RenderTexture} [key] - The image key as defined in the Game.Cache to use as the texture for this sprite OR a RenderTexture. + * @param {string|number} [frame] - If the sprite uses an image from a texture atlas or sprite sheet you can pass the frame here. Either a number for a frame ID or a string for a frame name. + * @returns {Description} Description. */ child: function (parent, x, y, key, frame) { @@ -51,8 +89,9 @@ Phaser.GameObjectFactory.prototype = { /** * Create a tween object for a specific object. The object can be any JavaScript object or Phaser object such as Sprite. * - * @param obj {object} Object the tween will be run on. - * @return {Phaser.Tween} The newly created tween object. + * @method tween + * @param {object} obj - Object the tween will be run on. + * @return {Description} Description. */ tween: function (obj) { @@ -60,60 +99,159 @@ Phaser.GameObjectFactory.prototype = { }, + /** + * Description. + * + * @method group + * @param {Description} parent - Description. + * @param {Description} name - Description. + * @return {Description} Description. + */ group: function (parent, name) { return new Phaser.Group(this.game, parent, name); }, + /** + * Description. + * + * @method audio + * @param {Description} key - Description. + * @param {Description} volume - Description. + * @param {Description} loop - Description. + * @return {Description} Description. + */ audio: function (key, volume, loop) { return this.game.sound.add(key, volume, loop); }, + /** + * Description. + * + * @method tileSprite + * @param {Description} x - Description. + * @param {Description} y - Description. + * @param {Description} width - Description. + * @param {Description} height - Description. + * @param {Description} key - Description. + * @param {Description} frame - Description. + * @return {Description} Description. + */ tileSprite: function (x, y, width, height, key, frame) { return this.world.group.add(new Phaser.TileSprite(this.game, x, y, width, height, key, frame)); }, + /** + * Description. + * + * @method text + * @param {Description} x - Description. + * @param {Description} y - Description. + * @param {Description} text - Description. + * @param {Description} style - Description. + */ text: function (x, y, text, style) { return this.world.group.add(new Phaser.Text(this.game, x, y, text, style)); }, + /** + * Description. + * + * @method button + * @param {Description} x - Description. + * @param {Description} y - Description. + * @param {Description} callback - Description. + * @param {Description} callbackContext - Description. + * @param {Description} overFrame - Description. + * @param {Description} outFrame - Description. + * @param {Description} downFrame - Description. + * @return {Description} Description. + */ button: function (x, y, key, callback, callbackContext, overFrame, outFrame, downFrame) { return this.world.group.add(new Phaser.Button(this.game, x, y, key, callback, callbackContext, overFrame, outFrame, downFrame)); }, + /** + * Description. + * + * @method graphics + * @param {Description} x - Description. + * @param {Description} y - Description. + * @return {Description} Description. + */ graphics: function (x, y) { return this.world.group.add(new Phaser.Graphics(this.game, x, y)); }, + /** + * Description. + * + * @method emitter + * @param {Description} x - Description. + * @param {Description} y - Description. + * @param {Description} maxParticles - Description. + * @return {Description} Description. + */ emitter: function (x, y, maxParticles) { return this.game.particles.add(new Phaser.Particles.Arcade.Emitter(this.game, x, y, maxParticles)); }, + /** + * Description. + * + * @method bitmapText + * @param {Description} x - Description. + * @param {Description} y - Description. + * @param {Description} text - Description. + * @param {Description} style - Description. + * @return {Description} Description. + */ bitmapText: function (x, y, text, style) { return this.world.group.add(new Phaser.BitmapText(this.game, x, y, text, style)); }, + /** + * Description. + * + * @method tilemap + * @param {Description} x - Description. + * @param {Description} y - Description. + * @param {Description} key - Description. + * @param {Description} resizeWorld - Description. + * @param {Description} tileWidth - Description. + * @param {Description} tileHeight - Description. + * @return {Description} Description. + */ tilemap: function (x, y, key, resizeWorld, tileWidth, tileHeight) { return this.world.group.add(new Phaser.Tilemap(this.game, key, x, y, resizeWorld, tileWidth, tileHeight)); }, + /** + * Description. + * + * @method renderTexture + * @param {Description} key - Description. + * @param {Description} width - Description. + * @param {Description} height - Description. + * @return {Description} Description. + */ renderTexture: function (key, width, height) { var texture = new Phaser.RenderTexture(this.game, key, width, height); diff --git a/src/gameobjects/Graphics.js b/src/gameobjects/Graphics.js index 9bafc76b..cf399254 100644 --- a/src/gameobjects/Graphics.js +++ b/src/gameobjects/Graphics.js @@ -1,9 +1,27 @@ +/** +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} +* @module Phaser.Graphics +*/ + +/** +* Description. +* +* @class Phaser.Graphics +* @constructor +* +* @param {Phaser.Game} game Current game instance. +* @param {number} [x] X position of Description. +* @param {number} [y] Y position of Description. +*/ Phaser.Graphics = function (game, x, y) { PIXI.Graphics.call(this); - Phaser.Sprite.call(this, game, x, y); - + /** + * @property {Description} type - Description. + */ this.type = Phaser.GRAPHICS; }; diff --git a/src/gameobjects/RenderTexture.js b/src/gameobjects/RenderTexture.js index 10d8560a..e9d154cd 100644 --- a/src/gameobjects/RenderTexture.js +++ b/src/gameobjects/RenderTexture.js @@ -1,20 +1,58 @@ +/** +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} +* @module Phaser.RenderTexture +*/ + +/** +* Description of constructor. +* @class Phaser.RenderTexture +* @classdesc Description of class. +* @constructor +* @param {Phaser.Game} game - Current game instance. +* @param {string} key - Description. +* @param {number} width - Description. +* @param {number} height - Description. +*/ Phaser.RenderTexture = function (game, key, width, height) { + /** + * @property {Phaser.Game} game - A reference to the currently running game. + */ this.game = game; + /** + * @property {Description} name - Description. + */ this.name = key; PIXI.EventTarget.call( this ); + /** + * @property {number} width - Description. + */ this.width = width || 100; + + /** + * @property {number} height - Description. + */ this.height = height || 100; - // I know this has a typo in it, but it's because the PIXI.RenderTexture does and we need to pair-up with it - // once they update pixi to fix the typo, we'll fix it here too :) + /** I know this has a typo in it, but it's because the PIXI.RenderTexture does and we need to pair-up with it + * once they update pixi to fix the typo, we'll fix it here too :) + * @property {Description} indetityMatrix - Description. + */ this.indetityMatrix = PIXI.mat3.create(); + /** + * @property {Description} frame - Description. + */ this.frame = new PIXI.Rectangle(0, 0, this.width, this.height); + /** + * @property {Description} type - Description. + */ this.type = Phaser.RENDERTEXTURE; if (PIXI.gl) diff --git a/src/gameobjects/Sprite.js b/src/gameobjects/Sprite.js index dbb2337a..58be67f6 100644 --- a/src/gameobjects/Sprite.js +++ b/src/gameobjects/Sprite.js @@ -1,48 +1,94 @@ +/** +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} +* @module Phaser.Sprite +*/ + +/** +* Create a new Sprite. +* @class Phaser.Sprite +* @classdesc Description of class. +* @constructor +* @param {Phaser.Game} game - Current game instance. +* @param {Description} x - Description. +* @param {Description} y - Description. +* @param {string} key - Description. +* @param {Description} frame - Description. +*/ Phaser.Sprite = function (game, x, y, key, frame) { x = x || 0; y = y || 0; key = key || null; frame = frame || null; - + + /** + * @property {Phaser.Game} game - A reference to the currently running Game. + */ this.game = game; - - // If exists = false then the Sprite isn't updated by the core game loop or physics subsystem at all + + /** + * @property {bool} exists - If exists = false then the Sprite isn't updated by the core game loop or physics subsystem at all. + * @default + */ this.exists = true; - // This is a handy little var your game can use to determine if a sprite is alive or not, it doesn't effect rendering + /** + * @property {bool} alive - This is a handy little var your game can use to determine if a sprite is alive or not, it doesn't effect rendering. + * @default + */ this.alive = true; + /** + * @property {Description} group - Description. + * @default + */ this.group = null; + /** + * @property {string} name - The user defined name given to this Sprite. + * @default + */ this.name = ''; + /** + * @property {Description} type - Description. + */ this.type = Phaser.SPRITE; + /** + * @property {number} renderOrderID - Description. + * @default + */ this.renderOrderID = -1; - // If you would like the Sprite to have a lifespan once 'born' you can set this to a positive value. Handy for particles, bullets, etc. - // The lifespan is decremented by game.time.elapsed each update, once it reaches zero the kill() function is called. + /** + * If you would like the Sprite to have a lifespan once 'born' you can set this to a positive value. Handy for particles, bullets, etc. + * The lifespan is decremented by game.time.elapsed each update, once it reaches zero the kill() function is called. + * @property {number} lifespan + * @default + */ this.lifespan = 0; /** - * The Signals you can subscribe to that are dispatched when certain things happen on this Sprite or its components - * @type Events - */ + * @property {Events} events - The Signals you can subscribe to that are dispatched when certain things happen on this Sprite or its components + */ this.events = new Phaser.Events(this); /** - * This manages animations of the sprite. You can modify animations through it. (see AnimationManager) - * @type AnimationManager - */ + * @property {AnimationManager} animations - This manages animations of the sprite. You can modify animations through it. (see AnimationManager) + */ this.animations = new Phaser.AnimationManager(this); /** - * The Input Handler Component - * @type InputHandler - */ + * @property {InputHandler} input - The Input Handler Component. + */ this.input = new Phaser.InputHandler(this); + /** + * @property {Description} key - Description. + */ this.key = key; if (key instanceof Phaser.RenderTexture) @@ -83,46 +129,70 @@ Phaser.Sprite = function (game, x, y, key, frame) { } /** - * The anchor sets the origin point of the texture. - * The default is 0,0 this means the textures origin is the top left - * Setting than anchor to 0.5,0.5 means the textures origin is centered - * Setting the anchor to 1,1 would mean the textures origin points will be the bottom right - * - * @property anchor - * @type Point - */ + * The anchor sets the origin point of the texture. + * The default is 0,0 this means the textures origin is the top left + * Setting than anchor to 0.5,0.5 means the textures origin is centered + * Setting the anchor to 1,1 would mean the textures origin points will be the bottom right + * + * @property {Phaser.Point} anchor + */ this.anchor = new Phaser.Point(); + /** + * @property {Description} _cropUUID - Description. + * @private + * @default + */ this._cropUUID = null; + + /** + * @property {Description} _cropUUID - Description. + * @private + * @default + */ this._cropRect = null; + /** + * @property {number} x - Description. + */ this.x = x; + + /** + * @property {number} y - Description. + */ this.y = y; - this.prevX = x; - this.prevY = y; - + /** + * @property {Description} position - Description. + */ this.position.x = x; this.position.y = y; /** - * Should this Sprite be automatically culled if out of range of the camera? - * A culled sprite has its visible property set to 'false'. - * Note that this check doesn't look at this Sprites children, which may still be in camera range. - * So you should set autoCull to false if the Sprite will have children likely to still be in camera range. - * - * @property autoCull - * @type Boolean - */ + * Should this Sprite be automatically culled if out of range of the camera? + * A culled sprite has its visible property set to 'false'. + * Note that this check doesn't look at this Sprites children, which may still be in camera range. + * So you should set autoCull to false if the Sprite will have children likely to still be in camera range. + * + * @property {bool} autoCull + * @default + */ this.autoCull = false; - // Replaces the PIXI.Point with a slightly more flexible one + /** + * @property {Phaser.Point} scale - Replaces the PIXI.Point with a slightly more flexible one. + */ this.scale = new Phaser.Point(1, 1); - // Influence of camera movement upon the position + /** + * @property {Phaser.Point} scrollFactor - Influence of camera movement upon the position. + */ this.scrollFactor = new Phaser.Point(1, 1); - // A mini cache for storing all of the calculated values + /** + * @property {Phaser.Point} _cache - A mini cache for storing all of the calculated values. + * @private + */ this._cache = { dirty: false, @@ -157,25 +227,73 @@ Phaser.Sprite = function (game, x, y, key, frame) { cameraVisible: true }; - - // Corner point defaults + + /** + * @property {Phaser.Point} offset - Corner point defaults. + */ this.offset = new Phaser.Point; + + /** + * @property {Phaser.Point} center - Description. + */ this.center = new Phaser.Point(x + Math.floor(this._cache.width / 2), y + Math.floor(this._cache.height / 2)); + + /** + * @property {Phaser.Point} topLeft - Description. + */ this.topLeft = new Phaser.Point(x, y); + + /** + * @property {Phaser.Point} topRight - Description. + */ this.topRight = new Phaser.Point(x + this._cache.width, y); + + /** + * @property {Phaser.Point} bottomRight - Description. + */ this.bottomRight = new Phaser.Point(x + this._cache.width, y + this._cache.height); + + /** + * @property {Phaser.Point} bottomLeft - Description. + */ this.bottomLeft = new Phaser.Point(x, y + this._cache.height); + + /** + * @property {Phaser.Rectangle} bounds - Description. + */ this.bounds = new Phaser.Rectangle(x, y, this._cache.width, this._cache.height); - - // Set-up the physics body + + /** + * @property {Phaser.Physics.Arcade.Body} body - Set-up the physics body. + */ this.body = new Phaser.Physics.Arcade.Body(this); + /** + * @property {Description} velocity - Description. + */ this.velocity = this.body.velocity; + + /** + * @property {Description} acceleration - Description. + */ this.acceleration = this.body.acceleration; - // World bounds check + /** + * @property {Description} inWorld - World bounds check. + */ this.inWorld = Phaser.Rectangle.intersects(this.bounds, this.game.world.bounds); + + /** + * @property {number} inWorldThreshold - World bounds check. + * @default + */ this.inWorldThreshold = 0; + + /** + * @property {bool} _outOfBoundsFired - Description. + * @private + * @default + */ this._outOfBoundsFired = false; }; @@ -185,8 +303,9 @@ Phaser.Sprite.prototype = Object.create(PIXI.Sprite.prototype); Phaser.Sprite.prototype.constructor = Phaser.Sprite; /** - * Automatically called by World.update. You can create your own update in Objects that extend Phaser.Sprite. - */ +* Automatically called by World.update. You can create your own update in Objects that extend Phaser.Sprite. +* @method Phaser.Sprite.prototype.preUpdate +*/ Phaser.Sprite.prototype.preUpdate = function() { if (!this.exists) @@ -331,9 +450,13 @@ Phaser.Sprite.prototype.deltaY = function () { } /** - * Moves the sprite so its center is located on the given x and y coordinates. - * Doesn't change the origin of the sprite. - */ +* Moves the sprite so its center is located on the given x and y coordinates. +* Doesn't change the origin of the sprite. +* +* @method Phaser.Sprite.prototype.centerOn +* @param {number} x - Description. +* @param {number} y - Description. +*/ Phaser.Sprite.prototype.centerOn = function(x, y) { this.x = x + (this.x - this.center.x); @@ -341,6 +464,11 @@ Phaser.Sprite.prototype.centerOn = function(x, y) { } +/** +* Description. +* +* @method Phaser.Sprite.prototype.revive +*/ Phaser.Sprite.prototype.revive = function() { this.alive = true; @@ -350,6 +478,11 @@ Phaser.Sprite.prototype.revive = function() { } +/** +* Description. +* +* @method Phaser.Sprite.prototype.kill +*/ Phaser.Sprite.prototype.kill = function() { this.alive = false; @@ -359,6 +492,11 @@ Phaser.Sprite.prototype.kill = function() { } +/** +* Description. +* +* @method Phaser.Sprite.prototype.reset +*/ Phaser.Sprite.prototype.reset = function(x, y) { this.x = x; @@ -373,6 +511,11 @@ Phaser.Sprite.prototype.reset = function(x, y) { } +/** +* Description. +* +* @method Phaser.Sprite.prototype.updateBounds +*/ Phaser.Sprite.prototype.updateBounds = function() { // Update the edge points @@ -421,6 +564,15 @@ Phaser.Sprite.prototype.updateBounds = function() { } +/** +* Description. +* +* @method Phaser.Sprite.prototype.getLocalPosition +* @param {Description} p - Description. +* @param {number} x - Description. +* @param {number} y - Description. +* @return {Description} Description. +*/ Phaser.Sprite.prototype.getLocalPosition = function(p, x, y) { p.x = ((this._cache.a11 * this._cache.id * x + -this._cache.a01 * this._cache.id * y + (this._cache.a12 * this._cache.a01 - this._cache.a02 * this._cache.a11) * this._cache.id) * this._cache.scaleX) + this._cache.a02; @@ -430,6 +582,15 @@ Phaser.Sprite.prototype.getLocalPosition = function(p, x, y) { } +/** +* Description. +* +* @method Phaser.Sprite.prototype.getLocalUnmodifiedPosition +* @param {Description} p - Description. +* @param {number} x - Description. +* @param {number} y - Description. +* @return {Description} Description. +*/ Phaser.Sprite.prototype.getLocalUnmodifiedPosition = function(p, x, y) { p.x = this._cache.a11 * this._cache.idi * x + -this._cache.i01 * this._cache.idi * y + (this._cache.a12 * this._cache.i01 - this._cache.a02 * this._cache.a11) * this._cache.idi; @@ -439,6 +600,11 @@ Phaser.Sprite.prototype.getLocalUnmodifiedPosition = function(p, x, y) { } +/** +* Description. +* +* @method Phaser.Sprite.prototype.bringToTop +*/ Phaser.Sprite.prototype.bringToTop = function() { if (this.group) @@ -452,6 +618,13 @@ Phaser.Sprite.prototype.bringToTop = function() { } +/** +* Description. +* +* @method Phaser.Sprite.prototype.bringToTop +* @param {Phaser.Rectangle} rect - Description. +* @return {Phaser.Rectangle} Description. +*/ Phaser.Sprite.prototype.getBounds = function(rect) { rect = rect || new Phaser.Rectangle; @@ -501,67 +674,71 @@ Object.defineProperty(Phaser.Sprite.prototype, 'angle', { }); +/** +* Get the animation frame number. +* @returns {Description} +*//** +* Set the animation frame by frame number. +* @param {Description} value - Description +*/ Object.defineProperty(Phaser.Sprite.prototype, "frame", { - /** - * Get the animation frame number. - */ get: function () { return this.animations.frame; }, - /** - * Set the animation frame by frame number. - */ set: function (value) { this.animations.frame = value; } }); +/** +* Get the animation frame name. +* @returns {Description} +*//** +* Set the animation frame by frame name. +* @param {Description} value - Description +*/ Object.defineProperty(Phaser.Sprite.prototype, "frameName", { - /** - * Get the animation frame name. - */ get: function () { return this.animations.frameName; }, - /** - * Set the animation frame by frame name. - */ set: function (value) { this.animations.frameName = value; } }); +/** +* Is this sprite visible to the camera or not? +* @returns {bool} +*/ Object.defineProperty(Phaser.Sprite.prototype, "inCamera", { - /** - * Is this sprite visible to the camera or not? - */ get: function () { return this._cache.cameraVisible; } }); +/** +* Get the input enabled state of this Sprite. +* @returns {Description} +*//** +* Set the ability for this sprite to receive input events. +* @param {Description} value - Description +*/ Object.defineProperty(Phaser.Sprite.prototype, "crop", { - /** - * Get the input enabled state of this Sprite. - */ get: function () { return this._cropRect; }, - /** - * Set the ability for this sprite to receive input events. - */ set: function (value) { if (value instanceof Phaser.Rectangle) @@ -590,20 +767,21 @@ Object.defineProperty(Phaser.Sprite.prototype, "crop", { }); +/** +* Get the input enabled state of this Sprite. +* @returns {Description} +*//** +* Set the ability for this sprite to receive input events. +* @param {Description} value - Description +*/ Object.defineProperty(Phaser.Sprite.prototype, "inputEnabled", { - /** - * Get the input enabled state of this Sprite. - */ get: function () { return (this.input.enabled); }, - /** - * Set the ability for this sprite to receive input events. - */ set: function (value) { if (value) diff --git a/src/gameobjects/Text.js b/src/gameobjects/Text.js index f3ba4472..41bbd9f3 100644 --- a/src/gameobjects/Text.js +++ b/src/gameobjects/Text.js @@ -1,3 +1,21 @@ +/** +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} +* @module Phaser.Text +*/ + +/** +* Create a new Text. +* @class Phaser.Text +* @classdesc Description of class. +* @constructor +* @param {Phaser.Game} game - Current game instance. +* @param {Description} x - Description. +* @param {Description} y - Description. +* @param {string} text - Description. +* @param {string} style - Description. +*/ Phaser.Text = function (game, x, y, text, style) { x = x || 0; @@ -6,15 +24,34 @@ Phaser.Text = function (game, x, y, text, style) { style = style || ''; // If exists = false then the Sprite isn't updated by the core game loop or physics subsystem at all + /** + * @property {bool} exists - Description. + * @default + */ this.exists = true; // This is a handy little var your game can use to determine if a sprite is alive or not, it doesn't effect rendering + /** + * @property {bool} alive - Description. + * @default + */ this.alive = true; + /** + * @property {Description} group - Description. + * @default + */ this.group = null; + /** + * @property {string} name - Description. + * @default + */ this.name = ''; + /** + * @property {Phaser.Game} game - A reference to the currently running game. + */ this.game = game; this._text = text; @@ -22,19 +59,39 @@ Phaser.Text = function (game, x, y, text, style) { PIXI.Text.call(this, text, style); + /** + * @property {Description} type - Description. + */ this.type = Phaser.TEXT; + /** + * @property {Description} position - Description. + */ this.position.x = this.x = x; this.position.y = this.y = y; // Replaces the PIXI.Point with a slightly more flexible one + /** + * @property {Phaser.Point} anchor - Description. + */ this.anchor = new Phaser.Point(); + + /** + * @property {Phaser.Point} scale - Description. + */ this.scale = new Phaser.Point(1, 1); // Influence of camera movement upon the position + /** + * @property {Phaser.Point} scrollFactor - Description. + */ this.scrollFactor = new Phaser.Point(1, 1); // A mini cache for storing all of the calculated values + /** + * @property {Description} _cache - Description. + * @private + */ this._cache = { dirty: false, @@ -53,6 +110,9 @@ Phaser.Text = function (game, x, y, text, style) { this._cache.x = this.x - (this.game.world.camera.x * this.scrollFactor.x); this._cache.y = this.y - (this.game.world.camera.y * this.scrollFactor.y); + /** + * @property {bool} renderable - Description. + */ this.renderable = true; }; @@ -60,7 +120,11 @@ Phaser.Text = function (game, x, y, text, style) { Phaser.Text.prototype = Object.create(PIXI.Text.prototype); Phaser.Text.prototype.constructor = Phaser.Text; -// Automatically called by World.update + +/** +* Automatically called by World.update. +* @method Phaser.Text.prototype.update +*/ Phaser.Text.prototype.update = function() { if (!this.exists) @@ -82,6 +146,13 @@ Phaser.Text.prototype.update = function() { } +/** +* Get +* @returns {Description} +*//** +* Set +* @param {Description} value - Description +*/ Object.defineProperty(Phaser.Text.prototype, 'angle', { get: function() { diff --git a/src/gameobjects/TileSprite.js b/src/gameobjects/TileSprite.js index d578f736..f274940f 100644 --- a/src/gameobjects/TileSprite.js +++ b/src/gameobjects/TileSprite.js @@ -1,3 +1,23 @@ +/** +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} +* @module Phaser.TileSprite +*/ + +/** +* Create a new TileSprite. +* @class Phaser.Tilemap +* @classdesc Class description. +* @constructor +* @param {Phaser.Game} game - Current game instance. +* @param {object} x - Description. +* @param {object} y - Description. +* @param {number} width - Description. +* @param {number} height - Description. +* @param {string} key - Description. +* @param {Description} frame - Description. +*/ Phaser.TileSprite = function (game, x, y, width, height, key, frame) { x = x || 0; @@ -9,26 +29,26 @@ Phaser.TileSprite = function (game, x, y, width, height, key, frame) { Phaser.Sprite.call(this, game, x, y, key, frame); + /** + * @property {Description} texture - Description. + */ this.texture = PIXI.TextureCache[key]; PIXI.TilingSprite.call(this, this.texture, width, height); + /** + * @property {Description} type - Description. + */ this.type = Phaser.TILESPRITE; /** - * The scaling of the image that is being tiled - * - * @property tileScale - * @type Point - */ + * @property {Point} tileScale - The scaling of the image that is being tiled. + */ this.tileScale = new Phaser.Point(1, 1); /** - * The offset position of the image that is being tiled - * - * @property tilePosition - * @type Point - */ + * @property {Point} tilePosition - The offset position of the image that is being tiled. + */ this.tilePosition = new Phaser.Point(0, 0); }; diff --git a/src/geom/Circle.js b/src/geom/Circle.js index ada013d1..e8e93b0b 100644 --- a/src/geom/Circle.js +++ b/src/geom/Circle.js @@ -1,13 +1,19 @@ /** -* Phaser - Circle -* +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} +* @module Phaser.Circle +*/ + +/** * Creates a new Circle object with the center coordinate specified by the x and y parameters and the diameter specified by the diameter parameter. If you call this function without parameters, a circle with x, y, diameter and radius properties set to 0 is created. * @class Circle +* @classdesc Phaser - Circle * @constructor -* @param {Number} [x] The x coordinate of the center of the circle. -* @param {Number} [y] The y coordinate of the center of the circle. -* @param {Number} [diameter] The diameter of the circle. -* @return {Circle} This circle object +* @param {number} [x] The x coordinate of the center of the circle. +* @param {number} [y] The y coordinate of the center of the circle. +* @param {number} [diameter] The diameter of the circle. +* @return {Phaser.Circle} This circle object **/ Phaser.Circle = function (x, y, diameter) { @@ -16,23 +22,27 @@ Phaser.Circle = function (x, y, diameter) { diameter = diameter || 0; /** - * The x coordinate of the center of the circle - * @property x - * @type Number + * @property {number} x - The x coordinate of the center of the circle. **/ this.x = x; /** - * The y coordinate of the center of the circle - * @property y - * @type Number + * @property {number} y - The y coordinate of the center of the circle. **/ this.y = y; + /** + * @property {number} _diameter - The diameter of the circle. + * @private + **/ this._diameter = diameter; if (diameter > 0) { + /** + * @property {number} _radius - The radius of the circle. + * @private + **/ this._radius = diameter * 0.5; } else @@ -47,7 +57,7 @@ Phaser.Circle.prototype = { /** * The circumference of the circle. * @method circumference - * @return {Number} + * @return {number} **/ circumference: function () { return 2 * (Math.PI * this._radius); @@ -56,10 +66,10 @@ Phaser.Circle.prototype = { /** * Sets the members of Circle to the specified values. * @method setTo - * @param {Number} x The x coordinate of the center of the circle. - * @param {Number} y The y coordinate of the center of the circle. - * @param {Number} diameter The diameter of the circle in pixels. - * @return {Circle} This circle object + * @param {number} x - The x coordinate of the center of the circle. + * @param {number} y - The y coordinate of the center of the circle. + * @param {number} diameter - The diameter of the circle in pixels. + * @return {Circle} This circle object. **/ setTo: function (x, y, diameter) { this.x = x; @@ -96,9 +106,9 @@ Phaser.Circle.prototype = { * Returns the distance from the center of the Circle object to the given object * (can be Circle, Point or anything with x/y properties) * @method distance - * @param {object} dest The target object. Must have visible x and y properties that represent the center of the object. - * @param {bool} [optional] round Round the distance to the nearest integer (default false) - * @return {Number} The distance between this Point object and the destination Point object. + * @param {object} dest - The target object. Must have visible x and y properties that represent the center of the object. + * @param {bool} [round] - Round the distance to the nearest integer (default false). + * @return {number} The distance between this Point object and the destination Point object. */ distance: function (dest, round) { @@ -118,7 +128,7 @@ Phaser.Circle.prototype = { /** * Returns a new Circle object with the same values for the x, y, width, and height properties as this Circle object. * @method clone - * @param {Phaser.Circle} out Optional Circle object. If given the values will be set into the object, otherwise a brand new Circle object will be created and returned. + * @param {Phaser.Circle} out - Optional Circle object. If given the values will be set into the object, otherwise a brand new Circle object will be created and returned. * @return {Phaser.Circle} The cloned Circle object. */ clone: function(out) { @@ -132,8 +142,8 @@ Phaser.Circle.prototype = { /** * Return true if the given x/y coordinates are within this Circle object. * @method contains - * @param {Number} x The X value of the coordinate to test. - * @param {Number} y The Y value of the coordinate to test. + * @param {number} x - The X value of the coordinate to test. + * @param {number} y - The Y value of the coordinate to test. * @return {bool} True if the coordinates are within this circle, otherwise false. */ contains: function (x, y) { @@ -143,9 +153,9 @@ Phaser.Circle.prototype = { /** * Returns a Point object containing the coordinates of a point on the circumference of the Circle based on the given angle. * @method circumferencePoint - * @param {Number} angle The angle in radians (unless asDegrees is true) to return the point from. - * @param {bool} asDegrees Is the given angle in radians (false) or degrees (true)? - * @param {Phaser.Point} [optional] output An optional Point object to put the result in to. If none specified a new Point object will be created. + * @param {number} angle - The angle in radians (unless asDegrees is true) to return the point from. + * @param {bool} asDegrees - Is the given angle in radians (false) or degrees (true)? + * @param {Phaser.Point} [out] - An optional Point object to put the result in to. If none specified a new Point object will be created. * @return {Phaser.Point} The Point object holding the result. */ circumferencePoint: function (angle, asDegrees, out) { @@ -155,8 +165,8 @@ Phaser.Circle.prototype = { /** * Adjusts the location of the Circle object, as determined by its center coordinate, by the specified amounts. * @method offset - * @param {Number} dx Moves the x value of the Circle object by this amount. - * @param {Number} dy Moves the y value of the Circle object by this amount. + * @param {number} dx - Moves the x value of the Circle object by this amount. + * @param {number} dy - Moves the y value of the Circle object by this amount. * @return {Circle} This Circle object. **/ offset: function (dx, dy) { @@ -188,13 +198,15 @@ Phaser.Circle.prototype = { // Getters / Setters +/** +* Get the diameter of the circle. The largest distance between any two points on the circle. The same as the radius * 2. +* @return {number} +*//** +* Set the diameter of the circle. The largest distance between any two points on the circle. The same as the radius * 2. +* @param {number} value - The diameter of the circle. +*/ Object.defineProperty(Phaser.Circle.prototype, "diameter", { - /** - * The diameter of the circle. The largest distance between any two points on the circle. The same as the radius * 2. - * @method diameter - * @return {Number} - **/ get: function () { return this._diameter; }, @@ -213,22 +225,19 @@ Object.defineProperty(Phaser.Circle.prototype, "diameter", { }); +/** +* Get the radius of the circle. The length of a line extending from the center of the circle to any point on the circle itself. The same as half the diameter. +* @return {number} +*//** +* Set +* @param {number} value - The radius of the circle. The length of a line extending from the center of the circle to any point on the circle itself. The same as half the diameter. +*/ Object.defineProperty(Phaser.Circle.prototype, "radius", { - /** - * The radius of the circle. The length of a line extending from the center of the circle to any point on the circle itself. The same as half the diameter. - * @method radius - * @return {Number} - **/ get: function () { return this._radius; }, - /** - * The radius of the circle. The length of a line extending from the center of the circle to any point on the circle itself. The same as half the diameter. - * @method radius - * @param {Number} The radius of the circle. - **/ set: function (value) { if (value > 0) { this._radius = value; @@ -238,22 +247,19 @@ Object.defineProperty(Phaser.Circle.prototype, "radius", { }); +/** +* Get the x coordinate of the leftmost point of the circle. Changing the left property of a Circle object has no effect on the x and y properties. However it does affect the diameter, whereas changing the x value does not affect the diameter property. +* @return {number} The x coordinate of the leftmost point of the circle. +*//** +* Set the x coordinate of the leftmost point of the circle. Changing the left property of a Circle object has no effect on the x and y properties. However it does affect the diameter, whereas changing the x value does not affect the diameter property. +* @param {number} value - The value to adjust the position of the leftmost point of the circle by. +*/ Object.defineProperty(Phaser.Circle.prototype, "left", { - /** - * The x coordinate of the leftmost point of the circle. Changing the left property of a Circle object has no effect on the x and y properties. However it does affect the diameter, whereas changing the x value does not affect the diameter property. - * @method left - * @return {Number} The x coordinate of the leftmost point of the circle. - **/ get: function () { return this.x - this._radius; }, - /** - * The x coordinate of the leftmost point of the circle. Changing the left property of a Circle object has no effect on the x and y properties. However it does affect the diameter, whereas changing the x value does not affect the diameter property. - * @method left - * @param {Number} The value to adjust the position of the leftmost point of the circle by. - **/ set: function (value) { if (value > this.x) { this._radius = 0; @@ -265,22 +271,19 @@ Object.defineProperty(Phaser.Circle.prototype, "left", { }); +/** +* Get the x coordinate of the rightmost point of the circle. Changing the right property of a Circle object has no effect on the x and y properties. However it does affect the diameter, whereas changing the x value does not affect the diameter property. +* @return {number} The x coordinate of the rightmost point of the circle. +*//** +* Set the x coordinate of the rightmost point of the circle. Changing the right property of a Circle object has no effect on the x and y properties. However it does affect the diameter, whereas changing the x value does not affect the diameter property. +* @param {number} value - The amount to adjust the diameter of the circle by. +*/ Object.defineProperty(Phaser.Circle.prototype, "right", { - /** - * The x coordinate of the rightmost point of the circle. Changing the right property of a Circle object has no effect on the x and y properties. However it does affect the diameter, whereas changing the x value does not affect the diameter property. - * @method right - * @return {Number} - **/ get: function () { return this.x + this._radius; }, - /** - * The x coordinate of the rightmost point of the circle. Changing the right property of a Circle object has no effect on the x and y properties. However it does affect the diameter, whereas changing the x value does not affect the diameter property. - * @method right - * @param {Number} The amount to adjust the diameter of the circle by. - **/ set: function (value) { if (value < this.x) { this._radius = 0; @@ -292,22 +295,19 @@ Object.defineProperty(Phaser.Circle.prototype, "right", { }); +/** +* Get the sum of the y minus the radius property. Changing the top property of a Circle object has no effect on the x and y properties, but does change the diameter. +* @return {number} +*//** +* The sum of the y minus the radius property. Changing the top property of a Circle object has no effect on the x and y properties, but does change the diameter. +* @param {number} value - The amount to adjust the height of the circle by. +*/ Object.defineProperty(Phaser.Circle.prototype, "top", { - /** - * The sum of the y minus the radius property. Changing the top property of a Circle object has no effect on the x and y properties, but does change the diameter. - * @method bottom - * @return {Number} - **/ get: function () { return this.y - this._radius; }, - /** - * The sum of the y minus the radius property. Changing the top property of a Circle object has no effect on the x and y properties, but does change the diameter. - * @method bottom - * @param {Number} The amount to adjust the height of the circle by. - **/ set: function (value) { if (value > this.y) { this._radius = 0; @@ -319,22 +319,19 @@ Object.defineProperty(Phaser.Circle.prototype, "top", { }); +/** +* Get the sum of the y and radius properties. Changing the bottom property of a Circle object has no effect on the x and y properties, but does change the diameter. +* @return {number} +*//** +* Set the sum of the y and radius properties. Changing the bottom property of a Circle object has no effect on the x and y properties, but does change the diameter. +* @param {number} value - The value to adjust the height of the circle by. +*/ Object.defineProperty(Phaser.Circle.prototype, "bottom", { - /** - * The sum of the y and radius properties. Changing the bottom property of a Circle object has no effect on the x and y properties, but does change the diameter. - * @method bottom - * @return {Number} - **/ get: function () { return this.y + this._radius; }, - /** - * The sum of the y and radius properties. Changing the bottom property of a Circle object has no effect on the x and y properties, but does change the diameter. - * @method bottom - * @param {Number} The value to adjust the height of the circle by. - **/ set: function (value) { if (value < this.y) { @@ -347,13 +344,12 @@ Object.defineProperty(Phaser.Circle.prototype, "bottom", { }); +/** +* Gets the area of this Circle. +* @return {number} This area of this circle. +*/ Object.defineProperty(Phaser.Circle.prototype, "area", { - /** - * Gets the area of this Circle. - * @method area - * @return {Number} This area of this circle. - **/ get: function () { if (this._radius > 0) { return Math.PI * this._radius * this._radius; @@ -364,19 +360,21 @@ Object.defineProperty(Phaser.Circle.prototype, "area", { }); +/** +* Determines whether or not this Circle object is empty. +* @return {bool} A value of true if the Circle objects diameter is less than or equal to 0; otherwise false. +*//** +* Sets all of the Circle objects properties to 0. A Circle object is empty if its diameter is less than or equal to 0. +* @param {Description} value - Description. +*/ Object.defineProperty(Phaser.Circle.prototype, "empty", { - /** - * Determines whether or not this Circle object is empty. - * @method empty - * @return {bool} A value of true if the Circle objects diameter is less than or equal to 0; otherwise false. - **/ get: function () { return (this._diameter == 0); }, /** - * Sets all of the Circle objects properties to 0. A Circle object is empty if its diameter is less than or equal to 0. + * * @method setEmpty * @return {Circle} This Circle object **/ @@ -391,9 +389,9 @@ Object.defineProperty(Phaser.Circle.prototype, "empty", { /** * Return true if the given x/y coordinates are within the Circle object. * @method contains -* @param {Phaser.Circle} a The Circle to be checked. -* @param {Number} x The X value of the coordinate to test. -* @param {Number} y The Y value of the coordinate to test. +* @param {Phaser.Circle} a - The Circle to be checked. +* @param {number} x - The X value of the coordinate to test. +* @param {number} y - The Y value of the coordinate to test. * @return {bool} True if the coordinates are within this circle, otherwise false. */ Phaser.Circle.contains = function (a, x, y) { @@ -415,8 +413,8 @@ Phaser.Circle.contains = function (a, x, y) { /** * Determines whether the two Circle objects match. This method compares the x, y and diameter properties. * @method equals -* @param {Phaser.Circle} a The first Circle object. -* @param {Phaser.Circle} b The second Circle object. +* @param {Phaser.Circle} a - The first Circle object. +* @param {Phaser.Circle} b - The second Circle object. * @return {bool} A value of true if the object has exactly the same values for the x, y and diameter properties as this Circle object; otherwise false. */ Phaser.Circle.equals = function (a, b) { @@ -427,8 +425,8 @@ Phaser.Circle.equals = function (a, b) { * Determines whether the two Circle objects intersect. * This method checks the radius distances between the two Circle objects to see if they intersect. * @method intersects -* @param {Phaser.Circle} a The first Circle object. -* @param {Phaser.Circle} b The second Circle object. +* @param {Phaser.Circle} a - The first Circle object. +* @param {Phaser.Circle} b - The second Circle object. * @return {bool} A value of true if the specified object intersects with this Circle object; otherwise false. */ Phaser.Circle.intersects = function (a, b) { @@ -438,10 +436,10 @@ Phaser.Circle.intersects = function (a, b) { /** * Returns a Point object containing the coordinates of a point on the circumference of the Circle based on the given angle. * @method circumferencePoint -* @param {Phaser.Circle} a The first Circle object. -* @param {Number} angle The angle in radians (unless asDegrees is true) to return the point from. -* @param {bool} asDegrees Is the given angle in radians (false) or degrees (true)? -* @param {Phaser.Point} [optional] output An optional Point object to put the result in to. If none specified a new Point object will be created. +* @param {Phaser.Circle} a - The first Circle object. +* @param {number} angle - The angle in radians (unless asDegrees is true) to return the point from. +* @param {bool} asDegrees - Is the given angle in radians (false) or degrees (true)? +* @param {Phaser.Point} [out] - An optional Point object to put the result in to. If none specified a new Point object will be created. * @return {Phaser.Point} The Point object holding the result. */ Phaser.Circle.circumferencePoint = function (a, angle, asDegrees, out) { @@ -463,8 +461,8 @@ Phaser.Circle.circumferencePoint = function (a, angle, asDegrees, out) { /** * Checks if the given Circle and Rectangle objects intersect. * @method intersectsRectangle -* @param {Phaser.Circle} c The Circle object to test. -* @param {Phaser.Rectangle} r The Rectangle object to test. +* @param {Phaser.Circle} c - The Circle object to test. +* @param {Phaser.Rectangle} r - The Rectangle object to test. * @return {bool} True if the two objects intersect, otherwise false. */ Phaser.Circle.intersectsRectangle = function (c, r) { diff --git a/src/geom/Point.js b/src/geom/Point.js index d6adb21a..4133584a 100644 --- a/src/geom/Point.js +++ b/src/geom/Point.js @@ -1,17 +1,14 @@ /** -* Phaser - Point -* -* The Point object represents a location in a two-dimensional coordinate system, where x represents the horizontal axis and y represents the vertical axis. -* * @author Richard Davey * @copyright 2013 Photon Storm Ltd. -* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License -* @module Phaser +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} +* @module Phaser.Point */ /** * Creates a new Point. If you pass no parameters a Point is created set to (0,0). * @class Point +* @classdesc The Point object represents a location in a two-dimensional coordinate system, where x represents the horizontal axis and y represents the vertical axis. * @constructor * @param {Number} x The horizontal position of this Point (default 0) * @param {Number} y The vertical position of this Point (default 0) @@ -21,7 +18,14 @@ Phaser.Point = function (x, y) { x = x || 0; y = y || 0; + /** + * @property {number} x - The x coordinate of the point. + **/ this.x = x; + + /** + * @property {number} y - The y coordinate of the point. + **/ this.y = y; }; @@ -50,8 +54,8 @@ Phaser.Point.prototype = { /** * Sets the x and y values of this Point object to the given coordinates. * @method setTo - * @param {Number} x - The horizontal position of this point. - * @param {Number} y - The vertical position of this point. + * @param {number} x - The horizontal position of this point. + * @param {number} y - The vertical position of this point. * @return {Point} This Point object. Useful for chaining method calls. **/ setTo: function (x, y) { @@ -93,10 +97,10 @@ Phaser.Point.prototype = { }, /** - * Clamps the x value of this Point to be between the given min and max + * Clamps the x value of this Point to be between the given min and max. * @method clampX - * @param {Number} min The minimum value to clamp this Point to - * @param {Number} max The maximum value to clamp this Point to + * @param {number} min - The minimum value to clamp this Point to. + * @param {number} max - The maximum value to clamp this Point to. * @return {Phaser.Point} This Point object. */ clampX: function (min, max) { @@ -109,8 +113,8 @@ Phaser.Point.prototype = { /** * Clamps the y value of this Point to be between the given min and max * @method clampY - * @param {Number} min The minimum value to clamp this Point to - * @param {Number} max The maximum value to clamp this Point to + * @param {number} min - The minimum value to clamp this Point to. + * @param {number} max - The maximum value to clamp this Point to. * @return {Phaser.Point} This Point object. */ clampY: function (min, max) { @@ -121,10 +125,10 @@ Phaser.Point.prototype = { }, /** - * Clamps this Point object values to be between the given min and max + * Clamps this Point object values to be between the given min and max. * @method clamp - * @param {Number} min The minimum value to clamp this Point to - * @param {Number} max The maximum value to clamp this Point to + * @param {number} min - The minimum value to clamp this Point to. + * @param {number} max - The maximum value to clamp this Point to. * @return {Phaser.Point} This Point object. */ clamp: function (min, max) { @@ -138,7 +142,7 @@ Phaser.Point.prototype = { /** * Creates a copy of the given Point. * @method clone - * @param {Phaser.Point} output Optional Point object. If given the values will be set into this object, otherwise a brand new Point object will be created and returned. + * @param {Phaser.Point} [output] Optional Point object. If given the values will be set into this object, otherwise a brand new Point object will be created and returned. * @return {Phaser.Point} The new Point object. */ clone: function (output) { @@ -177,9 +181,9 @@ Phaser.Point.prototype = { /** * Returns the distance of this Point object to the given object (can be a Circle, Point or anything with x/y properties) * @method distance - * @param {object} dest The target object. Must have visible x and y properties that represent the center of the object. - * @param {bool} [optional] round Round the distance to the nearest integer (default false) - * @return {Number} The distance between this Point object and the destination Point object. + * @param {object} dest - The target object. Must have visible x and y properties that represent the center of the object. + * @param {bool} [round] - Round the distance to the nearest integer (default false). + * @return {number} The distance between this Point object and the destination Point object. */ distance: function (dest, round) { @@ -190,7 +194,7 @@ Phaser.Point.prototype = { /** * Determines whether the given objects x/y values are equal to this Point object. * @method equals - * @param {Phaser.Point} a The first object to compare. + * @param {Phaser.Point} a - The first object to compare. * @return {bool} A value of true if the Points are equal, otherwise false. */ equals: function (a) { @@ -200,12 +204,12 @@ Phaser.Point.prototype = { /** * Rotates this Point around the x/y coordinates given to the desired angle. * @method rotate - * @param {Number} x The x coordinate of the anchor point - * @param {Number} y The y coordinate of the anchor point - * @param {Number} angle The angle in radians (unless asDegrees is true) to rotate the Point to. - * @param {bool} asDegrees Is the given rotation in radians (false) or degrees (true)? - * @param {Number} distance An optional distance constraint between the Point and the anchor. - * @return {Phaser.Point} The modified point object + * @param {number} x - The x coordinate of the anchor point + * @param {number} y - The y coordinate of the anchor point + * @param {number} angle - The angle in radians (unless asDegrees is true) to rotate the Point to. + * @param {bool} asDegrees - Is the given rotation in radians (false) or degrees (true)? + * @param {number} [distance] - An optional distance constraint between the Point and the anchor. + * @return {Phaser.Point} The modified point object. */ rotate: function (x, y, angle, asDegrees, distance) { return Phaser.Point.rotate(this, x, y, angle, asDegrees, distance); @@ -214,7 +218,7 @@ Phaser.Point.prototype = { /** * Returns a string representation of this object. * @method toString - * @return {string} a string representation of the instance. + * @return {string} A string representation of the instance. **/ toString: function () { return '[{Point (x=' + this.x + ' y=' + this.y + ')}]'; @@ -227,9 +231,9 @@ Phaser.Point.prototype = { /** * Adds the coordinates of two points together to create a new point. * @method add -* @param {Phaser.Point} a The first Point object. -* @param {Phaser.Point} b The second Point object. -* @param {Phaser.Point} out Optional Point to store the value in, if not supplied a new Point object will be created. +* @param {Phaser.Point} a - The first Point object. +* @param {Phaser.Point} b - The second Point object. +* @param {Phaser.Point} [out] - Optional Point to store the value in, if not supplied a new Point object will be created. * @return {Phaser.Point} The new Point object. */ Phaser.Point.add = function (a, b, out) { @@ -246,9 +250,9 @@ Phaser.Point.add = function (a, b, out) { /** * Subtracts the coordinates of two points to create a new point. * @method subtract -* @param {Phaser.Point} a The first Point object. -* @param {Phaser.Point} b The second Point object. -* @param {Phaser.Point} out Optional Point to store the value in, if not supplied a new Point object will be created. +* @param {Phaser.Point} a - The first Point object. +* @param {Phaser.Point} b - The second Point object. +* @param {Phaser.Point} [out] - Optional Point to store the value in, if not supplied a new Point object will be created. * @return {Phaser.Point} The new Point object. */ Phaser.Point.subtract = function (a, b, out) { @@ -265,9 +269,9 @@ Phaser.Point.subtract = function (a, b, out) { /** * Multiplies the coordinates of two points to create a new point. * @method subtract -* @param {Phaser.Point} a The first Point object. -* @param {Phaser.Point} b The second Point object. -* @param {Phaser.Point} out Optional Point to store the value in, if not supplied a new Point object will be created. +* @param {Phaser.Point} a - The first Point object. +* @param {Phaser.Point} b - The second Point object. +* @param {Phaser.Point} [out] - Optional Point to store the value in, if not supplied a new Point object will be created. * @return {Phaser.Point} The new Point object. */ Phaser.Point.multiply = function (a, b, out) { @@ -284,9 +288,9 @@ Phaser.Point.multiply = function (a, b, out) { /** * Divides the coordinates of two points to create a new point. * @method subtract -* @param {Phaser.Point} a The first Point object. -* @param {Phaser.Point} b The second Point object. -* @param {Phaser.Point} out Optional Point to store the value in, if not supplied a new Point object will be created. +* @param {Phaser.Point} a - The first Point object. +* @param {Phaser.Point} b - The second Point object. +* @param {Phaser.Point} [out] - Optional Point to store the value in, if not supplied a new Point object will be created. * @return {Phaser.Point} The new Point object. */ Phaser.Point.divide = function (a, b, out) { @@ -303,8 +307,8 @@ Phaser.Point.divide = function (a, b, out) { /** * Determines whether the two given Point objects are equal. They are considered equal if they have the same x and y values. * @method equals -* @param {Phaser.Point} a The first Point object. -* @param {Phaser.Point} b The second Point object. +* @param {Phaser.Point} a - The first Point object. +* @param {Phaser.Point} b - The second Point object. * @return {bool} A value of true if the Points are equal, otherwise false. */ Phaser.Point.equals = function (a, b) { @@ -312,11 +316,11 @@ Phaser.Point.equals = function (a, b) { }; /** -* Returns the distance of this Point object to the given object (can be a Circle, Point or anything with x/y properties) +* Returns the distance of this Point object to the given object (can be a Circle, Point or anything with x/y properties). * @method distance -* @param {object} a The target object. Must have visible x and y properties that represent the center of the object. -* @param {object} b The target object. Must have visible x and y properties that represent the center of the object. -* @param {bool} [optional] round Round the distance to the nearest integer (default false) +* @param {object} a - The target object. Must have visible x and y properties that represent the center of the object. +* @param {object} b - The target object. Must have visible x and y properties that represent the center of the object. +* @param {bool} [round] - Round the distance to the nearest integer (default false). * @return {Number} The distance between this Point object and the destination Point object. */ Phaser.Point.distance = function (a, b, round) { @@ -337,13 +341,13 @@ Phaser.Point.distance = function (a, b, round) { /** * Rotates a Point around the x/y coordinates given to the desired angle. * @method rotate -* @param {Phaser.Point} a The Point object to rotate. -* @param {Number} x The x coordinate of the anchor point -* @param {Number} y The y coordinate of the anchor point -* @param {Number} angle The angle in radians (unless asDegrees is true) to rotate the Point to. -* @param {bool} asDegrees Is the given rotation in radians (false) or degrees (true)? -* @param {Number} distance An optional distance constraint between the Point and the anchor. -* @return {Phaser.Point} The modified point object +* @param {Phaser.Point} a - The Point object to rotate. +* @param {number} x - The x coordinate of the anchor point +* @param {number} y - The y coordinate of the anchor point +* @param {number} angle - The angle in radians (unless asDegrees is true) to rotate the Point to. +* @param {bool} asDegrees - Is the given rotation in radians (false) or degrees (true)? +* @param {number} distance - An optional distance constraint between the Point and the anchor. +* @return {Phaser.Point} The modified point object. */ Phaser.Point.rotate = function (a, x, y, angle, asDegrees, distance) { diff --git a/src/geom/Rectangle.js b/src/geom/Rectangle.js index ca7de4f6..1a7894c5 100644 --- a/src/geom/Rectangle.js +++ b/src/geom/Rectangle.js @@ -1,13 +1,21 @@ +/** +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} +* @module Phaser.Rectangle +*/ + + /** * Creates a new Rectangle object with the top-left corner specified by the x and y parameters and with the specified width and height parameters. If you call this function without parameters, a Rectangle with x, y, width, and height properties set to 0 is created. * -* @class Rectangle +* @class Phaser.Rectangle * @constructor -* @param {Number} x The x coordinate of the top-left corner of the Rectangle. -* @param {Number} y The y coordinate of the top-left corner of the Rectangle. -* @param {Number} width The width of the Rectangle in pixels. -* @param {Number} height The height of the Rectangle in pixels. -* @return {Rectangle} This Rectangle object +* @param {number} x - The x coordinate of the top-left corner of the Rectangle. +* @param {number} y - The y coordinate of the top-left corner of the Rectangle. +* @param {number} width - The width of the Rectangle in pixels. +* @param {number} height - The height of the Rectangle in pixels. +* @return {Rectangle} This Rectangle object. **/ Phaser.Rectangle = function (x, y, width, height) { @@ -17,31 +25,23 @@ Phaser.Rectangle = function (x, y, width, height) { height = height || 0; /** - * @property x - * @type Number - * @default 0 - */ + * @property {number} x - Description. + */ this.x = x; /** - * @property y - * @type Number - * @default 0 - */ + * @property {number} y - Description. + */ this.y = y; /** - * @property width - * @type Number - * @default 0 - */ + * @property {number} width - Description. + */ this.width = width; /** - * @property height - * @type Number - * @default 0 - */ + * @property {number} height - Description. + */ this.height = height; }; @@ -51,8 +51,8 @@ Phaser.Rectangle.prototype = { /** * Adjusts the location of the Rectangle object, as determined by its top-left corner, by the specified amounts. * @method offset - * @param {Number} dx Moves the x value of the Rectangle object by this amount. - * @param {Number} dy Moves the y value of the Rectangle object by this amount. + * @param {number} dx - Moves the x value of the Rectangle object by this amount. + * @param {number} dy - Moves the y value of the Rectangle object by this amount. * @return {Rectangle} This Rectangle object. **/ offset: function (dx, dy) { @@ -67,7 +67,7 @@ Phaser.Rectangle.prototype = { /** * Adjusts the location of the Rectangle object using a Point object as a parameter. This method is similar to the Rectangle.offset() method, except that it takes a Point object as a parameter. * @method offsetPoint - * @param {Point} point A Point object to use to offset this Rectangle object. + * @param {Point} point - A Point object to use to offset this Rectangle object. * @return {Rectangle} This Rectangle object. **/ offsetPoint: function (point) { @@ -77,10 +77,10 @@ Phaser.Rectangle.prototype = { /** * Sets the members of Rectangle to the specified values. * @method setTo - * @param {Number} x The x coordinate of the top-left corner of the Rectangle. - * @param {Number} y The y coordinate of the top-left corner of the Rectangle. - * @param {Number} width The width of the Rectangle in pixels. - * @param {Number} height The height of the Rectangle in pixels. + * @param {number} x - The x coordinate of the top-left corner of the Rectangle. + * @param {number} y - The y coordinate of the top-left corner of the Rectangle. + * @param {number} width - The width of the Rectangle in pixels. + * @param {number} height - The height of the Rectangle in pixels. * @return {Rectangle} This Rectangle object **/ setTo: function (x, y, width, height) { @@ -135,8 +135,8 @@ Phaser.Rectangle.prototype = { /** * Increases the size of the Rectangle object by the specified amounts. The center point of the Rectangle object stays the same, and its size increases to the left and right by the dx value, and to the top and the bottom by the dy value. * @method inflate - * @param {Number} dx The amount to be added to the left side of the Rectangle. - * @param {Number} dy The amount to be added to the bottom side of the Rectangle. + * @param {number} dx - The amount to be added to the left side of the Rectangle. + * @param {number} dy - The amount to be added to the bottom side of the Rectangle. * @return {Phaser.Rectangle} This Rectangle object. */ inflate: function (dx, dy) { @@ -146,8 +146,8 @@ Phaser.Rectangle.prototype = { /** * The size of the Rectangle object, expressed as a Point object with the values of the width and height properties. * @method size - * @param {Phaser.Point} output Optional Point object. If given the values will be set into the object, otherwise a brand new Point object will be created and returned. - * @return {Phaser.Point} The size of the Rectangle object + * @param {Phaser.Point} [output] - Optional Point object. If given the values will be set into the object, otherwise a brand new Point object will be created and returned. + * @return {Phaser.Point} The size of the Rectangle object. */ size: function (output) { return Phaser.Rectangle.size(this, output); @@ -156,8 +156,8 @@ Phaser.Rectangle.prototype = { /** * Returns a new Rectangle object with the same values for the x, y, width, and height properties as the original Rectangle object. * @method clone - * @param {Phaser.Rectangle} output Optional Rectangle object. If given the values will be set into the object, otherwise a brand new Rectangle object will be created and returned. - * @return {Phaser.Rectangle} + * @param {Phaser.Rectangle} [output] - Optional Rectangle object. If given the values will be set into the object, otherwise a brand new Rectangle object will be created and returned. + * @return {Phaser.Rectangle} */ clone: function (output) { return Phaser.Rectangle.clone(this, output); @@ -166,8 +166,8 @@ Phaser.Rectangle.prototype = { /** * Determines whether the specified coordinates are contained within the region defined by this Rectangle object. * @method contains - * @param {Number} x The x coordinate of the point to test. - * @param {Number} y The y coordinate of the point to test. + * @param {number} x - The x coordinate of the point to test. + * @param {number} y - The y coordinate of the point to test. * @return {bool} A value of true if the Rectangle object contains the specified point; otherwise false. */ contains: function (x, y) { @@ -178,7 +178,7 @@ Phaser.Rectangle.prototype = { * Determines whether the first Rectangle object is fully contained within the second Rectangle object. * A Rectangle object is said to contain another if the second Rectangle object falls entirely within the boundaries of the first. * @method containsRect - * @param {Phaser.Rectangle} b The second Rectangle object. + * @param {Phaser.Rectangle} b - The second Rectangle object. * @return {bool} A value of true if the Rectangle object contains the specified point; otherwise false. */ containsRect: function (b) { @@ -189,7 +189,7 @@ Phaser.Rectangle.prototype = { * Determines whether the two Rectangles are equal. * This method compares the x, y, width and height properties of each Rectangle. * @method equals - * @param {Phaser.Rectangle} b The second Rectangle object. + * @param {Phaser.Rectangle} b - The second Rectangle object. * @return {bool} A value of true if the two Rectangles have exactly the same values for the x, y, width and height properties; otherwise false. */ equals: function (b) { @@ -199,8 +199,8 @@ Phaser.Rectangle.prototype = { /** * If the Rectangle object specified in the toIntersect parameter intersects with this Rectangle object, returns the area of intersection as a Rectangle object. If the Rectangles do not intersect, this method returns an empty Rectangle object with its properties set to 0. * @method intersection - * @param {Phaser.Rectangle} b The second Rectangle object. - * @param {Phaser.Rectangle} output Optional Rectangle object. If given the intersection values will be set into this object, otherwise a brand new Rectangle object will be created and returned. + * @param {Phaser.Rectangle} b - The second Rectangle object. + * @param {Phaser.Rectangle} out - Optional Rectangle object. If given the intersection values will be set into this object, otherwise a brand new Rectangle object will be created and returned. * @return {Phaser.Rectangle} A Rectangle object that equals the area of intersection. If the Rectangles do not intersect, this method returns an empty Rectangle object; that is, a Rectangle with its x, y, width, and height properties set to 0. */ intersection: function (b, out) { @@ -211,8 +211,8 @@ Phaser.Rectangle.prototype = { * Determines whether the two Rectangles intersect with each other. * This method checks the x, y, width, and height properties of the Rectangles. * @method intersects - * @param {Phaser.Rectangle} b The second Rectangle object. - * @param {Number} tolerance A tolerance value to allow for an intersection test with padding, default to 0 + * @param {Phaser.Rectangle} b - The second Rectangle object. + * @param {number} tolerance - A tolerance value to allow for an intersection test with padding, default to 0. * @return {bool} A value of true if the specified object intersects with this Rectangle object; otherwise false. */ intersects: function (b, tolerance) { @@ -222,11 +222,11 @@ Phaser.Rectangle.prototype = { /** * Determines whether the object specified intersects (overlaps) with the given values. * @method intersectsRaw - * @param {Number} left - * @param {Number} right - * @param {Number} top - * @param {Number} bottomt - * @param {Number} tolerance A tolerance value to allow for an intersection test with padding, default to 0 + * @param {number} left - Description. + * @param {number} right - Description. + * @param {number} top - Description. + * @param {number} bottomt - Description. + * @param {number} tolerance - A tolerance value to allow for an intersection test with padding, default to 0 * @return {bool} A value of true if the specified object intersects with the Rectangle; otherwise false. */ intersectsRaw: function (left, right, top, bottom, tolerance) { @@ -236,8 +236,8 @@ Phaser.Rectangle.prototype = { /** * Adds two Rectangles together to create a new Rectangle object, by filling in the horizontal and vertical space between the two Rectangles. * @method union - * @param {Phaser.Rectangle} b The second Rectangle object. - * @param {Phaser.Rectangle} output Optional Rectangle object. If given the new values will be set into this object, otherwise a brand new Rectangle object will be created and returned. + * @param {Phaser.Rectangle} b - The second Rectangle object. + * @param {Phaser.Rectangle} [out] - Optional Rectangle object. If given the new values will be set into this object, otherwise a brand new Rectangle object will be created and returned. * @return {Phaser.Rectangle} A Rectangle object that is the union of the two Rectangles. */ union: function (b, out) { @@ -247,7 +247,7 @@ Phaser.Rectangle.prototype = { /** * Returns a string representation of this object. * @method toString - * @return {string} a string representation of the instance. + * @return {string} A string representation of the instance. **/ toString: function () { return "[{Rectangle (x=" + this.x + " y=" + this.y + " width=" + this.width + " height=" + this.height + " empty=" + this.empty + ")}]"; @@ -257,48 +257,43 @@ Phaser.Rectangle.prototype = { // Getters / Setters +/** +* Get half of the width of the Rectangle. +* @return {number} +*/ Object.defineProperty(Phaser.Rectangle.prototype, "halfWidth", { - /** - * Half of the width of the Rectangle - * @property halfWidth - * @type Number - **/ get: function () { return Math.round(this.width / 2); } }); +/** +* Get galf of the height of the Rectangle. +* @return {number} +*/ Object.defineProperty(Phaser.Rectangle.prototype, "halfHeight", { - /** - * Half of the height of the Rectangle - * @property halfHeight - * @type Number - **/ get: function () { return Math.round(this.height / 2); } }); +/** +* The sum of the y and height properties. Changing the bottom property of a Rectangle object has no effect on the x, y and width properties, but does change the height property. +* @return {number} +*//** +* The sum of the y and height properties. Changing the bottom property of a Rectangle object has no effect on the x, y and width properties, but does change the height property. +* @param {number} value +*/ Object.defineProperty(Phaser.Rectangle.prototype, "bottom", { - /** - * The sum of the y and height properties. Changing the bottom property of a Rectangle object has no effect on the x, y and width properties, but does change the height property. - * @method bottom - * @return {Number} - **/ get: function () { return this.y + this.height; }, - - /** - * The sum of the y and height properties. Changing the bottom property of a Rectangle object has no effect on the x, y and width properties, but does change the height property. - * @method bottom - * @param {Number} value - **/ + set: function (value) { if (value <= this.y) { this.height = 0; @@ -309,21 +304,19 @@ Object.defineProperty(Phaser.Rectangle.prototype, "bottom", { }); +/** +* Get the location of the Rectangles bottom right corner as a Point object. +* @return {Phaser.Point} +*//** +* Sets the bottom-right corner of the Rectangle, determined by the values of the given Point object. +* @param {Phaser.Point} value +*/ Object.defineProperty(Phaser.Rectangle.prototype, "bottomRight", { - /** - * Get the location of the Rectangles bottom right corner as a Point object. - * @return {Phaser.Point} The new Point object. - */ get: function () { return new Phaser.Point(this.right, this.bottom); }, - /** - * Sets the bottom-right corner of the Rectangle, determined by the values of the given Point object. - * @method bottomRight - * @param {Point} value - **/ set: function (value) { this.right = value.x; this.bottom = value.y; @@ -331,23 +324,19 @@ Object.defineProperty(Phaser.Rectangle.prototype, "bottomRight", { }); +/** +* The x coordinate of the left of the Rectangle. Changing the left property of a Rectangle object has no effect on the y and height properties. However it does affect the width property, whereas changing the x value does not affect the width property. +* @return {number} +*//** +* The x coordinate of the left of the Rectangle. Changing the left property of a Rectangle object has no effect on the y and height properties.* However it does affect the width, whereas changing the x value does not affect the width property. +* @param {number} value +*/ Object.defineProperty(Phaser.Rectangle.prototype, "left", { - - /** - * The x coordinate of the left of the Rectangle. Changing the left property of a Rectangle object has no effect on the y and height properties. However it does affect the width property, whereas changing the x value does not affect the width property. - * @method left - * @ return {number} - **/ + get: function () { return this.x; }, - /** - * The x coordinate of the left of the Rectangle. Changing the left property of a Rectangle object has no effect on the y and height properties. - * However it does affect the width, whereas changing the x value does not affect the width property. - * @method left - * @param {Number} value - **/ set: function (value) { if (value >= this.right) { this.width = 0; @@ -359,24 +348,21 @@ Object.defineProperty(Phaser.Rectangle.prototype, "left", { }); +/** +* The sum of the x and width properties. Changing the right property of a Rectangle object has no effect on the x, y and height properties. +* However it does affect the width property. +* @return {number} +*//** +* The sum of the x and width properties. Changing the right property of a Rectangle object has no effect on the x, y and height properties. +* However it does affect the width property. +* @param {number} value +*/ Object.defineProperty(Phaser.Rectangle.prototype, "right", { - - /** - * The sum of the x and width properties. Changing the right property of a Rectangle object has no effect on the x, y and height properties. - * However it does affect the width property. - * @method right - * @return {Number} - **/ + get: function () { return this.x + this.width; }, - /** - * The sum of the x and width properties. Changing the right property of a Rectangle object has no effect on the x, y and height properties. - * However it does affect the width property. - * @method right - * @param {Number} value - **/ set: function (value) { if (value <= this.x) { this.width = 0; @@ -387,94 +373,83 @@ Object.defineProperty(Phaser.Rectangle.prototype, "right", { }); +/** +* The volume of the Rectangle derived from width * height. +* @return {number} +*/ Object.defineProperty(Phaser.Rectangle.prototype, "volume", { - - /** - * The volume of the Rectangle derived from width * height - * @method volume - * @return {Number} - **/ + get: function () { return this.width * this.height; } }); +/** +* The perimeter size of the Rectangle. This is the sum of all 4 sides. +* @return {number} +*/ Object.defineProperty(Phaser.Rectangle.prototype, "perimeter", { - /** - * The perimeter size of the Rectangle. This is the sum of all 4 sides. - * @method perimeter - * @return {Number} - **/ get: function () { return (this.width * 2) + (this.height * 2); } }); +/** +* The x coordinate of the center of the Rectangle. +* @return {number} +*//** +* The x coordinate of the center of the Rectangle. +* @param {number} value +*/ Object.defineProperty(Phaser.Rectangle.prototype, "centerX", { - /** - * The x coordinate of the center of the Rectangle. - * @method centerX - * @return {Number} - **/ get: function () { return this.x + this.halfWidth; }, - /** - * The x coordinate of the center of the Rectangle. - * @method centerX - * @param {Number} value - **/ set: function (value) { this.x = value - this.halfWidth; } }); +/** +* The y coordinate of the center of the Rectangle. +* @return {number} +*//** +* The y coordinate of the center of the Rectangle. +* @param {number} value +*/ Object.defineProperty(Phaser.Rectangle.prototype, "centerY", { - /** - * The y coordinate of the center of the Rectangle. - * @method centerY - * @return {Number} - **/ get: function () { return this.y + this.halfHeight; }, - /** - * The y coordinate of the center of the Rectangle. - * @method centerY - * @param {Number} value - **/ set: function (value) { this.y = value - this.halfHeight; } }); +/** +* The y coordinate of the top of the Rectangle. Changing the top property of a Rectangle object has no effect on the x and width properties. +* However it does affect the height property, whereas changing the y value does not affect the height property. +* @return {number} +*//** +* The y coordinate of the top of the Rectangle. Changing the top property of a Rectangle object has no effect on the x and width properties. + * However it does affect the height property, whereas changing the y value does not affect the height property. +* @param {number} value +*/ Object.defineProperty(Phaser.Rectangle.prototype, "top", { - /** - * The y coordinate of the top of the Rectangle. Changing the top property of a Rectangle object has no effect on the x and width properties. - * However it does affect the height property, whereas changing the y value does not affect the height property. - * @method top - * @return {Number} - **/ get: function () { return this.y; }, - /** - * The y coordinate of the top of the Rectangle. Changing the top property of a Rectangle object has no effect on the x and width properties. - * However it does affect the height property, whereas changing the y value does not affect the height property. - * @method top - * @param {Number} value - **/ set: function (value) { if (value >= this.bottom) { this.height = 0; @@ -486,21 +461,19 @@ Object.defineProperty(Phaser.Rectangle.prototype, "top", { }); +/** +* Get the location of the Rectangles top left corner as a Point object. +* @return {Phaser.Point} +*//** +* The location of the Rectangles top-left corner, determined by the x and y coordinates of the Point. +* @param {Phaser.Point} value - Description. +*/ Object.defineProperty(Phaser.Rectangle.prototype, "topLeft", { - /** - * Get the location of the Rectangles top left corner as a Point object. - * @return {Phaser.Point} The new Point object. - */ get: function () { return new Phaser.Point(this.x, this.y); }, - - /** - * The location of the Rectangles top-left corner, determined by the x and y coordinates of the Point. - * @method topLeft - * @param {Point} value - **/ + set: function (value) { this.x = value.x; this.y = value.y; @@ -508,22 +481,19 @@ Object.defineProperty(Phaser.Rectangle.prototype, "topLeft", { }); +/** +* Determines whether or not this Rectangle object is empty. +* @return {bool} +*//** +* Sets all of the Rectangle object's properties to 0. A Rectangle object is empty if its width or height is less than or equal to 0. +* @param {Description} value +*/ Object.defineProperty(Phaser.Rectangle.prototype, "empty", { - /** - * Determines whether or not this Rectangle object is empty. - * @method isEmpty - * @return {bool} A value of true if the Rectangle objects width or height is less than or equal to 0; otherwise false. - **/ get: function () { return (!this.width || !this.height); }, - /** - * Sets all of the Rectangle object's properties to 0. A Rectangle object is empty if its width or height is less than or equal to 0. - * @method setEmpty - * @return {Rectangle} This Rectangle object - **/ set: function (value) { this.setTo(0, 0, 0, 0); } @@ -535,9 +505,9 @@ Object.defineProperty(Phaser.Rectangle.prototype, "empty", { /** * Increases the size of the Rectangle object by the specified amounts. The center point of the Rectangle object stays the same, and its size increases to the left and right by the dx value, and to the top and the bottom by the dy value. * @method inflate -* @param {Phaser.Rectangle} a The Rectangle object. -* @param {Number} dx The amount to be added to the left side of the Rectangle. -* @param {Number} dy The amount to be added to the bottom side of the Rectangle. +* @param {Phaser.Rectangle} a - The Rectangle object. +* @param {Number} dx - The amount to be added to the left side of the Rectangle. +* @param {Number} dy - The amount to be added to the bottom side of the Rectangle. * @return {Phaser.Rectangle} This Rectangle object. */ Phaser.Rectangle.inflate = function (a, dx, dy) { @@ -551,8 +521,8 @@ Phaser.Rectangle.inflate = function (a, dx, dy) { /** * Increases the size of the Rectangle object. This method is similar to the Rectangle.inflate() method except it takes a Point object as a parameter. * @method inflatePoint -* @param {Phaser.Rectangle} a The Rectangle object. -* @param {Phaser.Point} point The x property of this Point object is used to increase the horizontal dimension of the Rectangle object. The y property is used to increase the vertical dimension of the Rectangle object. +* @param {Phaser.Rectangle} a - The Rectangle object. +* @param {Phaser.Point} point - The x property of this Point object is used to increase the horizontal dimension of the Rectangle object. The y property is used to increase the vertical dimension of the Rectangle object. * @return {Phaser.Rectangle} The Rectangle object. */ Phaser.Rectangle.inflatePoint = function (a, point) { @@ -562,8 +532,8 @@ Phaser.Rectangle.inflatePoint = function (a, point) { /** * The size of the Rectangle object, expressed as a Point object with the values of the width and height properties. * @method size -* @param {Phaser.Rectangle} a The Rectangle object. -* @param {Phaser.Point} output Optional Point object. If given the values will be set into the object, otherwise a brand new Point object will be created and returned. +* @param {Phaser.Rectangle} a - The Rectangle object. +* @param {Phaser.Point} [output] - Optional Point object. If given the values will be set into the object, otherwise a brand new Point object will be created and returned. * @return {Phaser.Point} The size of the Rectangle object */ Phaser.Rectangle.size = function (a, output) { @@ -574,8 +544,8 @@ Phaser.Rectangle.size = function (a, output) { /** * Returns a new Rectangle object with the same values for the x, y, width, and height properties as the original Rectangle object. * @method clone -* @param {Phaser.Rectangle} a The Rectangle object. -* @param {Phaser.Rectangle} output Optional Rectangle object. If given the values will be set into the object, otherwise a brand new Rectangle object will be created and returned. +* @param {Phaser.Rectangle} a - The Rectangle object. +* @param {Phaser.Rectangle} [output] - Optional Rectangle object. If given the values will be set into the object, otherwise a brand new Rectangle object will be created and returned. * @return {Phaser.Rectangle} */ Phaser.Rectangle.clone = function (a, output) { @@ -586,9 +556,9 @@ Phaser.Rectangle.clone = function (a, output) { /** * Determines whether the specified coordinates are contained within the region defined by this Rectangle object. * @method contains -* @param {Phaser.Rectangle} a The Rectangle object. -* @param {Number} x The x coordinate of the point to test. -* @param {Number} y The y coordinate of the point to test. +* @param {Phaser.Rectangle} a - The Rectangle object. +* @param {number} x - The x coordinate of the point to test. +* @param {number} y - The y coordinate of the point to test. * @return {bool} A value of true if the Rectangle object contains the specified point; otherwise false. */ Phaser.Rectangle.contains = function (a, x, y) { @@ -598,8 +568,8 @@ Phaser.Rectangle.contains = function (a, x, y) { /** * Determines whether the specified point is contained within the rectangular region defined by this Rectangle object. This method is similar to the Rectangle.contains() method, except that it takes a Point object as a parameter. * @method containsPoint -* @param {Phaser.Rectangle} a The Rectangle object. -* @param {Phaser.Point} point The point object being checked. Can be Point or any object with .x and .y values. +* @param {Phaser.Rectangle} a - The Rectangle object. +* @param {Phaser.Point} point - The point object being checked. Can be Point or any object with .x and .y values. * @return {bool} A value of true if the Rectangle object contains the specified point; otherwise false. */ Phaser.Rectangle.containsPoint = function (a, point) { @@ -610,8 +580,8 @@ Phaser.Rectangle.containsPoint = function (a, point) { * Determines whether the first Rectangle object is fully contained within the second Rectangle object. * A Rectangle object is said to contain another if the second Rectangle object falls entirely within the boundaries of the first. * @method containsRect -* @param {Phaser.Rectangle} a The first Rectangle object. -* @param {Phaser.Rectangle} b The second Rectangle object. +* @param {Phaser.Rectangle} a - The first Rectangle object. +* @param {Phaser.Rectangle} b - The second Rectangle object. * @return {bool} A value of true if the Rectangle object contains the specified point; otherwise false. */ Phaser.Rectangle.containsRect = function (a, b) { @@ -630,8 +600,8 @@ Phaser.Rectangle.containsRect = function (a, b) { * Determines whether the two Rectangles are equal. * This method compares the x, y, width and height properties of each Rectangle. * @method equals -* @param {Phaser.Rectangle} a The first Rectangle object. -* @param {Phaser.Rectangle} b The second Rectangle object. +* @param {Phaser.Rectangle} a - The first Rectangle object. +* @param {Phaser.Rectangle} b - The second Rectangle object. * @return {bool} A value of true if the two Rectangles have exactly the same values for the x, y, width and height properties; otherwise false. */ Phaser.Rectangle.equals = function (a, b) { @@ -641,14 +611,14 @@ Phaser.Rectangle.equals = function (a, b) { /** * If the Rectangle object specified in the toIntersect parameter intersects with this Rectangle object, returns the area of intersection as a Rectangle object. If the Rectangles do not intersect, this method returns an empty Rectangle object with its properties set to 0. * @method intersection -* @param {Phaser.Rectangle} a The first Rectangle object. -* @param {Phaser.Rectangle} b The second Rectangle object. -* @param {Phaser.Rectangle} output Optional Rectangle object. If given the intersection values will be set into this object, otherwise a brand new Rectangle object will be created and returned. +* @param {Phaser.Rectangle} a - The first Rectangle object. +* @param {Phaser.Rectangle} b - The second Rectangle object. +* @param {Phaser.Rectangle} [out] - Optional Rectangle object. If given the intersection values will be set into this object, otherwise a brand new Rectangle object will be created and returned. * @return {Phaser.Rectangle} A Rectangle object that equals the area of intersection. If the Rectangles do not intersect, this method returns an empty Rectangle object; that is, a Rectangle with its x, y, width, and height properties set to 0. */ Phaser.Rectangle.intersection = function (a, b, out) { - out = out || new Phaser.Rectangle; + out = out || new Phaser.Rectangle; if (Phaser.Rectangle.intersects(a, b)) { @@ -666,9 +636,9 @@ Phaser.Rectangle.intersection = function (a, b, out) { * Determines whether the two Rectangles intersect with each other. * This method checks the x, y, width, and height properties of the Rectangles. * @method intersects -* @param {Phaser.Rectangle} a The first Rectangle object. -* @param {Phaser.Rectangle} b The second Rectangle object. -* @param {Number} tolerance A tolerance value to allow for an intersection test with padding, default to 0 +* @param {Phaser.Rectangle} a - The first Rectangle object. +* @param {Phaser.Rectangle} b - The second Rectangle object. +* @param {number} tolerance - A tolerance value to allow for an intersection test with padding, default to 0 * @return {bool} A value of true if the specified object intersects with this Rectangle object; otherwise false. */ Phaser.Rectangle.intersects = function (a, b, tolerance) { @@ -682,11 +652,11 @@ Phaser.Rectangle.intersects = function (a, b, tolerance) { /** * Determines whether the object specified intersects (overlaps) with the given values. * @method intersectsRaw -* @param {Number} left -* @param {Number} right -* @param {Number} top -* @param {Number} bottomt -* @param {Number} tolerance A tolerance value to allow for an intersection test with padding, default to 0 +* @param {number} left - Description. +* @param {number} right - Description. +* @param {number} top - Description. +* @param {number} bottom - Description. +* @param {number} tolerance - A tolerance value to allow for an intersection test with padding, default to 0 * @return {bool} A value of true if the specified object intersects with the Rectangle; otherwise false. */ Phaser.Rectangle.intersectsRaw = function (a, left, right, top, bottom, tolerance) { @@ -700,9 +670,9 @@ Phaser.Rectangle.intersectsRaw = function (a, left, right, top, bottom, toleranc /** * Adds two Rectangles together to create a new Rectangle object, by filling in the horizontal and vertical space between the two Rectangles. * @method union -* @param {Phaser.Rectangle} a The first Rectangle object. -* @param {Phaser.Rectangle} b The second Rectangle object. -* @param {Phaser.Rectangle} output Optional Rectangle object. If given the new values will be set into this object, otherwise a brand new Rectangle object will be created and returned. +* @param {Phaser.Rectangle} a - The first Rectangle object. +* @param {Phaser.Rectangle} b - The second Rectangle object. +* @param {Phaser.Rectangle} [out] - Optional Rectangle object. If given the new values will be set into this object, otherwise a brand new Rectangle object will be created and returned. * @return {Phaser.Rectangle} A Rectangle object that is the union of the two Rectangles. */ Phaser.Rectangle.union = function (a, b, out) { diff --git a/src/input/Input.js b/src/input/Input.js index a4075192..9a1ec1ef 100644 --- a/src/input/Input.js +++ b/src/input/Input.js @@ -1,14 +1,35 @@ /** -* Phaser.Input -* -* A game specific Input manager that looks after the mouse, keyboard and touch objects. +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} +* @module Phaser.Input +*/ + +/** +* Constructor for Phaser Input. +* @class Phaser.Input +* @classdesc A game specific Input manager that looks after the mouse, keyboard and touch objects. * This is updated by the core game loop. +* @constructor +* @param {Phaser.Game} game - Current game instance. */ Phaser.Input = function (game) { + /** + * @property {Phaser.Game} game - A reference to the currently running game. + */ this.game = game; + /** + * @property {Description} hitCanvas - Description. + * @default + */ this.hitCanvas = null; + + /** + * @property {Description} hitContext - Description. + * @default + */ this.hitContext = null; }; @@ -19,124 +40,141 @@ Phaser.Input.MOUSE_TOUCH_COMBINE = 2; Phaser.Input.prototype = { + /** + * @property {Phaser.Game} game + */ game: null, /** * How often should the input pointers be checked for updates? * A value of 0 means every single frame (60fps), a value of 1 means every other frame (30fps) and so on. - * @type {number} + * @property {number} pollRate + * @default */ pollRate: 0, + + /** + * @property {number} _pollCounter - Description. + * @private + * @default + */ _pollCounter: 0, /** * A vector object representing the previous position of the Pointer. - * @property vector - * @type {Vec2} + * @property {Vec2} vector + * @default **/ _oldPosition: null, /** * X coordinate of the most recent Pointer event - * @type {Number} + * @property {number} _x * @private + * @default */ _x: 0, /** - * X coordinate of the most recent Pointer event - * @type {Number} + * Y coordinate of the most recent Pointer event + * @property {number} _y * @private + * @default */ _y: 0, /** * You can disable all Input by setting Input.disabled: true. While set all new input related events will be ignored. * If you need to disable just one type of input, for example mouse, use Input.mouse.disabled: true instead - * @type {bool} + * @property {bool} disabled + * @default */ disabled: false, /** - * Controls the expected behaviour when using a mouse and touch together on a multi-input device + * Controls the expected behaviour when using a mouse and touch together on a multi-input device. + * @property {Description} multiInputOverride */ multiInputOverride: Phaser.Input.MOUSE_TOUCH_COMBINE, /** * A vector object representing the current position of the Pointer. - * @property vector - * @type {Vec2} + * @property {Vec2} position + * @default **/ position: null, /** * A vector object representing the speed of the Pointer. Only really useful in single Pointer games, * otherwise see the Pointer objects directly. - * @property vector - * @type {Vec2} + * @property {Vec2} speed + * @default **/ speed: null, /** * A Circle object centered on the x/y screen coordinates of the Input. * Default size of 44px (Apples recommended "finger tip" size) but can be changed to anything - * @property circle - * @type {Circle} + * @property {Circle} circle + * @default **/ circle: null, /** * The scale by which all input coordinates are multiplied, calculated by the StageScaleMode. * In an un-scaled game the values will be x: 1 and y: 1. - * @type {Vec2} + * @property {Vec2} scale + * @default */ scale: null, /** * The maximum number of Pointers allowed to be active at any one time. - * For lots of games it's useful to set this to 1 - * @type {Number} + * For lots of games it's useful to set this to 1. + * @property {number} maxPointers + * @default */ maxPointers: 10, /** * The current number of active Pointers. - * @type {Number} + * @property {number} currentPointers + * @default */ currentPointers: 0, /** - * The number of milliseconds that the Pointer has to be pressed down and then released to be considered a tap or click - * @property tapRate - * @type {Number} + * The number of milliseconds that the Pointer has to be pressed down and then released to be considered a tap or clicke + * @property {number} tapRate + * @default **/ tapRate: 200, /** * The number of milliseconds between taps of the same Pointer for it to be considered a double tap / click - * @property doubleTapRate - * @type {Number} + * @property {number} doubleTapRate + * @default **/ doubleTapRate: 300, /** * The number of milliseconds that the Pointer has to be pressed down for it to fire a onHold event - * @property holdRate - * @type {Number} + * @property {number} holdRate + * @default **/ holdRate: 2000, /** * The number of milliseconds below which the Pointer is considered justPressed - * @property justPressedRate - * @type {Number} + * @property {number} justPressedRate + * @default **/ justPressedRate: 200, /** - * The number of milliseconds below which the Pointer is considered justReleased - * @property justReleasedRate - * @type {Number} + * The number of milliseconds below which the Pointer is considered justReleased + * @property {number} justReleasedRate + * @default **/ justReleasedRate: 200, @@ -144,120 +182,162 @@ Phaser.Input.prototype = { * Sets if the Pointer objects should record a history of x/y coordinates they have passed through. * The history is cleared each time the Pointer is pressed down. * The history is updated at the rate specified in Input.pollRate - * @property recordPointerHistory - * @type {bool} + * @property {bool} recordPointerHistory + * @default **/ recordPointerHistory: false, /** * The rate in milliseconds at which the Pointer objects should update their tracking history - * @property recordRate - * @type {Number} + * @property {number} recordRate + * @default */ recordRate: 100, /** * The total number of entries that can be recorded into the Pointer objects tracking history. * If the Pointer is tracking one event every 100ms, then a trackLimit of 100 would store the last 10 seconds worth of history. - * @property recordLimit - * @type {Number} + * @property {number} recordLimit + * @default */ recordLimit: 100, /** * A Pointer object - * @property pointer1 - * @type {Pointer} + * @property {Pointer} pointer1 **/ pointer1: null, /** * A Pointer object - * @property pointer2 - * @type {Pointer} + * @property {Pointer} pointer2 **/ pointer2: null, /** - * A Pointer object - * @property pointer3 - * @type {Pointer} + * A Pointer object + * @property {Pointer} pointer3 **/ pointer3: null, /** * A Pointer object - * @property pointer4 - * @type {Pointer} + * @property {Pointer} pointer4 **/ pointer4: null, /** * A Pointer object - * @property pointer5 - * @type {Pointer} + * @property {Pointer} pointer5 **/ pointer5: null, /** * A Pointer object - * @property pointer6 - * @type {Pointer} + * @property {Pointer} pointer6 **/ pointer6: null, /** - * A Pointer object - * @property pointer7 - * @type {Pointer} + * A Pointer object + * @property {Pointer} pointer7 **/ pointer7: null, /** * A Pointer object - * @property pointer8 - * @type {Pointer} + * @property {Pointer} pointer8 **/ pointer8: null, /** * A Pointer object - * @property pointer9 - * @type {Pointer} - **/ + * @property {Pointer} pointer9 + **/ pointer9: null, /** - * A Pointer object - * @property pointer10 - * @type {Pointer} + * A Pointer object. + * @property {Pointer} pointer10 **/ pointer10: null, /** * The most recently active Pointer object. * When you've limited max pointers to 1 this will accurately be either the first finger touched or mouse. - * @property activePointer - * @type {Pointer} + * @property {Pointer} activePointer + * @default **/ activePointer: null, + /** + * Description. + * @property {Pointer} mousePointer + * @default + **/ mousePointer: null, + + /** + * Description. + * @property {Description} mouse + * @default + **/ mouse: null, + + /** + * Description. + * @property {Description} keyboard + * @default + **/ keyboard: null, + + /** + * Description. + * @property {Description} touch + * @default + **/ touch: null, + + /** + * Description. + * @property {Description} mspointer + * @default + **/ mspointer: null, + /** + * Description. + * @property {Description} onDown + * @default + **/ onDown: null, + + /** + * Description. + * @property {Description} onUp + * @default + **/ onUp: null, + + /** + * Description. + * @property {Description} onTap + * @default + **/ onTap: null, + + /** + * Description. + * @property {Description} onHold + * @default + **/ onHold: null, // A linked list of interactive objects, the InputHandler components (belong to Sprites) register themselves with this interactiveItems: new Phaser.LinkedList(), /** - * Starts the Input Manager running + * Starts the Input Manager running. * @method start **/ boot: function () { @@ -303,7 +383,7 @@ Phaser.Input.prototype = { * Add a new Pointer object to the Input Manager. By default Input creates 2 pointer objects for you. If you need more * use this to create a new one, up to a maximum of 10. * @method addPointer - * @return {Pointer} A reference to the new Pointer object + * @return {Pointer} A reference to the new Pointer object. **/ addPointer: function () { @@ -361,13 +441,12 @@ Phaser.Input.prototype = { if (this.pointer10) { this.pointer10.update(); } this._pollCounter = 0; - }, /** * Reset all of the Pointers and Input states * @method reset - * @param hard {bool} A soft reset (hard = false) won't reset any signals that might be bound. A hard reset will. + * @param {bool} hard - A soft reset (hard = false) won't reset any signals that might be bound. A hard reset will. **/ reset: function (hard) { @@ -420,8 +499,8 @@ Phaser.Input.prototype = { /** * Find the first free Pointer object and start it, passing in the event data. * @method startPointer - * @param {Any} event The event data from the Touch event - * @return {Pointer} The Pointer object that was started or null if no Pointer object is available + * @param {Any} event - The event data from the Touch event. + * @return {Pointer} The Pointer object that was started or null if no Pointer object is available. **/ startPointer: function (event) { @@ -456,8 +535,8 @@ Phaser.Input.prototype = { /** * Updates the matching Pointer object, passing in the event data. * @method updatePointer - * @param {Any} event The event data from the Touch event - * @return {Pointer} The Pointer object that was updated or null if no Pointer object is available + * @param {Any} event - The event data from the Touch event. + * @return {Pointer} The Pointer object that was updated or null if no Pointer object is available. **/ updatePointer: function (event) { @@ -487,8 +566,8 @@ Phaser.Input.prototype = { /** * Stops the matching Pointer object, passing in the event data. * @method stopPointer - * @param {Any} event The event data from the Touch event - * @return {Pointer} The Pointer object that was stopped or null if no Pointer object is available + * @param {Any} event - The event data from the Touch event. + * @return {Pointer} The Pointer object that was stopped or null if no Pointer object is available. **/ stopPointer: function (event) { @@ -518,7 +597,7 @@ Phaser.Input.prototype = { /** * Get the next Pointer object whos active property matches the given state * @method getPointer - * @param {bool} state The state the Pointer should be in (false for inactive, true for active) + * @param {bool} state - The state the Pointer should be in (false for inactive, true for active). * @return {Pointer} A Pointer object or null if no Pointer object matches the requested state. **/ getPointer: function (state) { @@ -549,9 +628,9 @@ Phaser.Input.prototype = { }, /** - * Get the Pointer object whos identified property matches the given identifier value + * Get the Pointer object whos identified property matches the given identifier value. * @method getPointerFromIdentifier - * @param {Number} identifier The Pointer.identifier value to search for + * @param {number} identifier - The Pointer.identifier value to search for. * @return {Pointer} A Pointer object or null if no Pointer object matches the requested identifier. **/ getPointerFromIdentifier: function (identifier) { @@ -580,20 +659,22 @@ Phaser.Input.prototype = { }, /** - * Get the distance between two Pointer objects + * Get the distance between two Pointer objects. * @method getDistance * @param {Pointer} pointer1 * @param {Pointer} pointer2 + * @return {Description} Description. **/ getDistance: function (pointer1, pointer2) { // return Phaser.Vec2Utils.distance(pointer1.position, pointer2.position); }, /** - * Get the angle between two Pointer objects + * Get the angle between two Pointer objects. * @method getAngle * @param {Pointer} pointer1 * @param {Pointer} pointer2 + * @return {Description} Description. **/ getAngle: function (pointer1, pointer2) { // return Phaser.Vec2Utils.angle(pointer1.position, pointer2.position); @@ -603,14 +684,16 @@ Phaser.Input.prototype = { // Getters / Setters +/** +* The X coordinate of the most recently active pointer. +* This value takes game scaling into account automatically. See Pointer.screenX/clientX for source values. +* @return {number} +*//** +* Set +* @param {number} value - Description. +*/ Object.defineProperty(Phaser.Input.prototype, "x", { - /** - * The X coordinate of the most recently active pointer. - * This value takes game scaling into account automatically. See Pointer.screenX/clientX for source values. - * @property x - * @type {Number} - **/ get: function () { return this._x; }, @@ -621,14 +704,16 @@ Object.defineProperty(Phaser.Input.prototype, "x", { }); +/** +* The Y coordinate of the most recently active pointer. + * This value takes game scaling into account automatically. See Pointer.screenY/clientY for source values. +* @return {number} +*//** +* Set +* @param {number} value - Description. +*/ Object.defineProperty(Phaser.Input.prototype, "y", { - /** - * The Y coordinate of the most recently active pointer. - * This value takes game scaling into account automatically. See Pointer.screenY/clientY for source values. - * @property y - * @type {Number} - **/ get: function () { return this._y; }, @@ -639,6 +724,10 @@ Object.defineProperty(Phaser.Input.prototype, "y", { }); +/** +* Get +* @return {Description} Description. +*/ Object.defineProperty(Phaser.Input.prototype, "pollLocked", { get: function () { @@ -647,26 +736,24 @@ Object.defineProperty(Phaser.Input.prototype, "pollLocked", { }); +/** +* Get the total number of inactive Pointers +* @return {number} The number of Pointers currently inactive. +*/ Object.defineProperty(Phaser.Input.prototype, "totalInactivePointers", { - /** - * Get the total number of inactive Pointers - * @method totalInactivePointers - * @return {Number} The number of Pointers currently inactive - **/ get: function () { return 10 - this.currentPointers; } }); +/** +* Recalculates the total number of active Pointers +* @return {number} The number of Pointers currently active. +*/ Object.defineProperty(Phaser.Input.prototype, "totalActivePointers", { - /** - * Recalculates the total number of active Pointers - * @method totalActivePointers - * @return {Number} The number of Pointers currently active - **/ get: function () { this.currentPointers = 0; @@ -685,6 +772,10 @@ Object.defineProperty(Phaser.Input.prototype, "totalActivePointers", { }); +/** +* Get +* @return {Description} +*/ Object.defineProperty(Phaser.Input.prototype, "worldX", { get: function () { @@ -693,6 +784,10 @@ Object.defineProperty(Phaser.Input.prototype, "worldX", { }); +/** +* Get +* @return {Description} +*/ Object.defineProperty(Phaser.Input.prototype, "worldY", { get: function () { diff --git a/src/input/InputHandler.js b/src/input/InputHandler.js index 2430d12a..4a55dc60 100644 --- a/src/input/InputHandler.js +++ b/src/input/InputHandler.js @@ -1,71 +1,174 @@ +/** +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} +* @module Phaser.InputHandler +*/ + +/** +* Constructor for Phaser InputHandler. +* @class Phaser.InputHandler +* @classdesc Description. +* @constructor +* @param {Phaser.Sprite} game - Description. +*/ Phaser.InputHandler = function (sprite) { + /** + * @property {Phaser.Game} game - A reference to the currently running game. + */ this.game = sprite.game; + + /** + * @property {Phaser.Sprite} sprite - Description. + */ this.sprite = sprite; + /** + * @property {bool} enabled - Description. + * @default + */ this.enabled = false; // Linked list references + /** + * @property {Description} parent - Description. + * @default + */ this.parent = null; + + /** + * @property {Description} next - Description. + * @default + */ this.next = null; + + /** + * @property {Description} prev - Description. + * @default + */ this.prev = null; + + /** + * @property {Description} last - Description. + * @default + */ this.last = this; + + /** + * @property {Description} first - Description. + * @default + */ this.first = this; - /** - * The PriorityID controls which Sprite receives an Input event first if they should overlap. - */ + /** + * @property {number} priorityID - The PriorityID controls which Sprite receives an Input event first if they should overlap. + * @default + */ this.priorityID = 0; + + /** + * @property {bool} useHandCursor - Description. + * @default + */ this.useHandCursor = false; + /** + * @property {bool} isDragged - Description. + * @default + */ this.isDragged = false; + + /** + * @property {bool} allowHorizontalDrag - Description. + * @default + */ this.allowHorizontalDrag = true; + + /** + * @property {bool} allowVerticalDrag - Description. + * @default + */ this.allowVerticalDrag = true; + + /** + * @property {bool} bringToTop - Description. + * @default + */ this.bringToTop = false; + /** + * @property {Description} snapOffset - Description. + * @default + */ this.snapOffset = null; + + /** + * @property {bool} snapOnDrag - Description. + * @default + */ this.snapOnDrag = false; + + /** + * @property {bool} snapOnRelease - Description. + * @default + */ this.snapOnRelease = false; + + /** + * @property {number} snapX - Description. + * @default + */ this.snapX = 0; + + /** + * @property {number} snapY - Description. + * @default + */ this.snapY = 0; - /** - * Should we use pixel perfect hit detection? Warning: expensive. Only enable if you really need it! - * @default false - */ + /** + * @property {number} pixelPerfect - Should we use pixel perfect hit detection? Warning: expensive. Only enable if you really need it! + * @default + */ this.pixelPerfect = false; /** - * The alpha tolerance threshold. If the alpha value of the pixel matches or is above this value, it's considered a hit. - * @default 255 + * @property {number} pixelPerfectAlpha - The alpha tolerance threshold. If the alpha value of the pixel matches or is above this value, it's considered a hit. + * @default */ this.pixelPerfectAlpha = 255; /** - * Is this sprite allowed to be dragged by the mouse? true = yes, false = no - * @default false + * @property {bool} draggable - Is this sprite allowed to be dragged by the mouse? true = yes, false = no + * @default */ this.draggable = false; /** - * A region of the game world within which the sprite is restricted during drag - * @default null + * @property {Description} boundsRect - A region of the game world within which the sprite is restricted during drag. + * @default */ this.boundsRect = null; /** - * An Sprite the bounds of which this sprite is restricted during drag - * @default null + * @property {Description} boundsSprite - A Sprite the bounds of which this sprite is restricted during drag. + * @default */ this.boundsSprite = null; /** * If this object is set to consume the pointer event then it will stop all propogation from this object on. * For example if you had a stack of 6 sprites with the same priority IDs and one consumed the event, none of the others would receive it. - * @type {bool} + * @property {bool} consumePointerEvent + * @default */ this.consumePointerEvent = false; + /** + * @property {Phaser.Point} _tempPoint - Description. + * @private + */ this._tempPoint = new Phaser.Point; this._pointerData = []; @@ -90,6 +193,13 @@ Phaser.InputHandler = function (sprite) { Phaser.InputHandler.prototype = { + /** + * Description. + * @method start + * @param {number} priority - Description. + * @param {bool} useHandCursor - Description. + * @return {Phaser.Sprite} Description. + */ start: function (priority, useHandCursor) { priority = priority || 0; @@ -141,6 +251,10 @@ Phaser.InputHandler.prototype = { }, + /** + * Description. + * @method reset + */ reset: function () { this.enabled = false; @@ -165,6 +279,10 @@ Phaser.InputHandler.prototype = { } }, + /** + * Description. + * @method stop + */ stop: function () { // Turning off @@ -182,8 +300,9 @@ Phaser.InputHandler.prototype = { }, /** - * Clean up memory. - */ + * Clean up memory. + * @method destroy + */ destroy: function () { if (this.enabled) @@ -198,7 +317,9 @@ Phaser.InputHandler.prototype = { /** * The x coordinate of the Input pointer, relative to the top-left of the parent Sprite. * This value is only set when the pointer is over this Sprite. - * @type {number} + * @method pointerX + * @param {Pointer} pointer + * @return {number} The x coordinate of the Input pointer. */ pointerX: function (pointer) { @@ -211,7 +332,9 @@ Phaser.InputHandler.prototype = { /** * The y coordinate of the Input pointer, relative to the top-left of the parent Sprite * This value is only set when the pointer is over this Sprite. - * @type {number} + * @method pointerY + * @param {Pointer} pointer + * @return {number} The y coordinate of the Input pointer. */ pointerY: function (pointer) { @@ -222,10 +345,11 @@ Phaser.InputHandler.prototype = { }, /** - * If the Pointer is touching the touchscreen, or the mouse button is held down, isDown is set to true - * @property isDown - * @type {bool} - **/ + * If the Pointer is touching the touchscreen, or the mouse button is held down, isDown is set to true. + * @method pointerDown + * @param {Pointer} pointer + * @return {bool} + */ pointerDown: function (pointer) { pointer = pointer || 0; @@ -236,9 +360,10 @@ Phaser.InputHandler.prototype = { /** * If the Pointer is not touching the touchscreen, or the mouse button is up, isUp is set to true - * @property isUp - * @type {bool} - **/ + * @method pointerUp + * @param {Pointer} pointer + * @return {bool} + */ pointerUp: function (pointer) { pointer = pointer || 0; @@ -249,9 +374,10 @@ Phaser.InputHandler.prototype = { /** * A timestamp representing when the Pointer first touched the touchscreen. - * @property timeDown - * @type {Number} - **/ + * @method pointerTimeDown + * @param {Pointer} pointer + * @return {number} + */ pointerTimeDown: function (pointer) { pointer = pointer || 0; @@ -262,9 +388,10 @@ Phaser.InputHandler.prototype = { /** * A timestamp representing when the Pointer left the touchscreen. - * @property timeUp - * @type {Number} - **/ + * @method pointerTimeUp + * @param {Pointer} pointer + * @return {number} + */ pointerTimeUp: function (pointer) { pointer = pointer || 0; @@ -274,10 +401,11 @@ Phaser.InputHandler.prototype = { }, /** - * Is the Pointer over this Sprite - * @property isOver - * @type {bool} - **/ + * Is the Pointer over this Sprite? + * @method pointerOver + * @param {Pointer} pointer + * @return {bool + */ pointerOver: function (pointer) { pointer = pointer || 0; @@ -287,10 +415,11 @@ Phaser.InputHandler.prototype = { }, /** - * Is the Pointer outside of this Sprite - * @property isOut - * @type {bool} - **/ + * Is the Pointer outside of this Sprite? + * @method pointerOut + * @param {Pointer} pointer + * @return {bool} + */ pointerOut: function (pointer) { pointer = pointer || 0; @@ -301,9 +430,10 @@ Phaser.InputHandler.prototype = { /** * A timestamp representing when the Pointer first touched the touchscreen. - * @property timeDown - * @type {Number} - **/ + * @method pointerTimeOver + * @param {Pointer} pointer + * @return {number} + */ pointerTimeOver: function (pointer) { pointer = pointer || 0; @@ -314,9 +444,10 @@ Phaser.InputHandler.prototype = { /** * A timestamp representing when the Pointer left the touchscreen. - * @property timeUp - * @type {Number} - **/ + * @method pointerTimeOut + * @param {Pointer} pointer + * @return {number} + */ pointerTimeOut: function (pointer) { pointer = pointer || 0; @@ -327,7 +458,9 @@ Phaser.InputHandler.prototype = { /** * Is this sprite being dragged by the mouse or not? - * @default false + * @method pointerTimeOut + * @param {Pointer} pointer + * @return {number} */ pointerDragged: function (pointer) { @@ -339,6 +472,9 @@ Phaser.InputHandler.prototype = { /** * Checks if the given pointer is over this Sprite. + * @method checkPointerOver + * @param {Pointer} pointer + * @return {bool} */ checkPointerOver: function (pointer) { @@ -372,6 +508,13 @@ Phaser.InputHandler.prototype = { }, + /** + * Description. + * @method checkPixel + * @param {Description} x - Description. + * @param {Description} y - Description. + * @return {bool} + */ checkPixel: function (x, y) { x += (this.sprite.texture.frame.width * this.sprite.anchor.x); @@ -399,7 +542,9 @@ Phaser.InputHandler.prototype = { }, /** - * Update + * Update. + * @method update + * @param {Pointer} pointer */ update: function (pointer) { @@ -429,6 +574,12 @@ Phaser.InputHandler.prototype = { } }, + /** + * Description. + * @method _pointerOverHandler + * @private + * @param {Pointer} pointer + */ _pointerOverHandler: function (pointer) { if (this._pointerData[pointer.id].isOver == false) @@ -448,6 +599,12 @@ Phaser.InputHandler.prototype = { } }, + /** + * Description. + * @method _pointerOutHandler + * @private + * @param {Pointer} pointer + */ _pointerOutHandler: function (pointer) { this._pointerData[pointer.id].isOver = false; @@ -463,6 +620,12 @@ Phaser.InputHandler.prototype = { }, + /** + * Description. + * @method _touchedHandler + * @private + * @param {Pointer} pointer + */ _touchedHandler: function (pointer) { if (this._pointerData[pointer.id].isDown == false && this._pointerData[pointer.id].isOver == true) @@ -489,6 +652,12 @@ Phaser.InputHandler.prototype = { }, + /** + * Description. + * @method _releasedHandler + * @private + * @param {Pointer} pointer + */ _releasedHandler: function (pointer) { // If was previously touched by this Pointer, check if still is AND still over this item @@ -525,6 +694,9 @@ Phaser.InputHandler.prototype = { /** * Updates the Pointer drag on this Sprite. + * @method updateDrag + * @param {Pointer} pointer + * @return {bool} */ updateDrag: function (pointer) { @@ -566,8 +738,10 @@ Phaser.InputHandler.prototype = { /** * Returns true if the pointer has entered the Sprite within the specified delay time (defaults to 500ms, half a second) - * @param delay The time below which the pointer is considered as just over. - * @returns {bool} + * @method justOver + * @param {Pointer} pointer + * @param {number} delay - The time below which the pointer is considered as just over. + * @return {bool} */ justOver: function (pointer, delay) { @@ -580,8 +754,10 @@ Phaser.InputHandler.prototype = { /** * Returns true if the pointer has left the Sprite within the specified delay time (defaults to 500ms, half a second) - * @param delay The time below which the pointer is considered as just out. - * @returns {bool} + * @method justOut + * @param {Pointer} pointer + * @param {number} delay - The time below which the pointer is considered as just out. + * @return {bool} */ justOut: function (pointer, delay) { @@ -594,8 +770,10 @@ Phaser.InputHandler.prototype = { /** * Returns true if the pointer has entered the Sprite within the specified delay time (defaults to 500ms, half a second) - * @param delay The time below which the pointer is considered as just over. - * @returns {bool} + * @method justPressed + * @param {Pointer} pointer + * @param {number} delay - The time below which the pointer is considered as just over. + * @return {bool} */ justPressed: function (pointer, delay) { @@ -608,8 +786,10 @@ Phaser.InputHandler.prototype = { /** * Returns true if the pointer has left the Sprite within the specified delay time (defaults to 500ms, half a second) - * @param delay The time below which the pointer is considered as just out. - * @returns {bool} + * @method justReleased + * @param {Pointer} pointer + * @param {number} delay - The time below which the pointer is considered as just out. + * @return {bool} */ justReleased: function (pointer, delay) { @@ -622,7 +802,9 @@ Phaser.InputHandler.prototype = { /** * If the pointer is currently over this Sprite this returns how long it has been there for in milliseconds. - * @returns {number} The number of milliseconds the pointer has been over the Sprite, or -1 if not over. + * @method overDuration + * @param {Pointer} pointer + * @return {number} The number of milliseconds the pointer has been over the Sprite, or -1 if not over. */ overDuration: function (pointer) { @@ -639,7 +821,9 @@ Phaser.InputHandler.prototype = { /** * If the pointer is currently over this Sprite this returns how long it has been there for in milliseconds. - * @returns {number} The number of milliseconds the pointer has been pressed down on the Sprite, or -1 if not over. + * @method downDuration + * @param {Pointer} pointer + * @return {number} The number of milliseconds the pointer has been pressed down on the Sprite, or -1 if not over. */ downDuration: function (pointer) { @@ -656,7 +840,7 @@ Phaser.InputHandler.prototype = { /** * Make this Sprite draggable by the mouse. You can also optionally set mouseStartDragCallback and mouseStopDragCallback - * + * @method enableDrag * @param lockCenter If false the Sprite will drag from where you click it minus the dragOffset. If true it will center itself to the tip of the mouse pointer. * @param bringToTop If true the Sprite will be bought to the top of the rendering list in its current Group. * @param pixelPerfect If true it will use a pixel perfect test to see if you clicked the Sprite. False uses the bounding box. @@ -697,6 +881,7 @@ Phaser.InputHandler.prototype = { /** * Stops this sprite from being able to be dragged. If it is currently the target of an active drag it will be stopped immediately. Also disables any set callbacks. + * @method disableDrag */ disableDrag: function () { @@ -716,6 +901,7 @@ Phaser.InputHandler.prototype = { /** * Called by Pointer when drag starts on this Sprite. Should not usually be called directly. + * @method startDrag */ startDrag: function (pointer) { @@ -746,6 +932,7 @@ Phaser.InputHandler.prototype = { /** * Called by Pointer when drag is stopped on this Sprite. Should not usually be called directly. + * @method stopDrag */ stopDrag: function (pointer) { @@ -766,7 +953,7 @@ Phaser.InputHandler.prototype = { /** * Restricts this sprite to drag movement only on the given axis. Note: If both are set to false the sprite will never move! - * + * @method setDragLock * @param allowHorizontal To enable the sprite to be dragged horizontally set to true, otherwise false * @param allowVertical To enable the sprite to be dragged vertically set to true, otherwise false */ @@ -783,7 +970,7 @@ Phaser.InputHandler.prototype = { /** * Make this Sprite snap to the given grid either during drag or when it's released. * For example 16x16 as the snapX and snapY would make the sprite snap to every 16 pixels. - * + * @method enableSnap * @param snapX The width of the grid cell in pixels * @param snapY The height of the grid cell in pixels * @param onDrag If true the sprite will snap to the grid while being dragged @@ -803,6 +990,7 @@ Phaser.InputHandler.prototype = { /** * Stops the sprite from snapping to a grid during drag or release. + * @method disableSnap */ disableSnap: function () { @@ -813,6 +1001,7 @@ Phaser.InputHandler.prototype = { /** * Bounds Rect check for the sprite drag + * @method checkBoundsRect */ checkBoundsRect: function () { @@ -837,7 +1026,8 @@ Phaser.InputHandler.prototype = { }, /** - * Parent Sprite Bounds check for the sprite drag + * Parent Sprite Bounds check for the sprite drag. + * @method checkBoundsSprite */ checkBoundsSprite: function () { diff --git a/src/input/Keyboard.js b/src/input/Keyboard.js index c19ad892..a65e3f14 100644 --- a/src/input/Keyboard.js +++ b/src/input/Keyboard.js @@ -1,8 +1,36 @@ +/** +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} +* @module Phaser.Keyboard +*/ + + +/** +* Phaser - Keyboard constructor. +* +* @class Phaser.Keyboard +* @classdesc A Keyboard object Description. +* @constructor +* @param {Phaser.Game} game - A reference to the currently running game. +*/ Phaser.Keyboard = function (game) { + /** + * @property {Phaser.Game} game - Local reference to game. + */ this.game = game; + + /** + * @property {Description} _keys - Description. + * @private + */ this._keys = {}; - this._hotkeys = {}; + + /** + * @property {Description} _capture - Description. + * @private + */ this._capture = {}; this.callbackContext = this; @@ -16,42 +44,38 @@ Phaser.Keyboard = function (game) { Phaser.Keyboard.prototype = { + /** + * @property {Phaser.Game} game - Local reference to game. + */ game: null, /** * You can disable all Input by setting disabled = true. While set all new input related events will be ignored. - * @type {bool} + * @default + * @property {bool} disabled */ disabled: false, + /** + * Description. + * @property {Description} _onKeyDown + * @private + * @default + */ _onKeyDown: null, + + /** + * Description. + * @property {Description} _onKeyUp + * @private + * @default + */ _onKeyUp: null, - addCallbacks: function (context, onDown, onUp) { - - this.callbackContext = context; - this.onDownCallback = onDown; - - if (typeof onUp !== 'undefined') - { - this.onUpCallback = onUp; - } - - }, - - addKey: function (keycode) { - - this._hotkeys[keycode] = new Phaser.Key(this.game, keycode); - return this._hotkeys[keycode]; - - }, - - removeKey: function (keycode) { - - delete (this._hotkeys[keycode]); - - }, - + /** + * Description. + * @method start + */ start: function () { var _this = this; @@ -69,6 +93,10 @@ Phaser.Keyboard.prototype = { }, + /** + * Description. + * @method stop + */ stop: function () { document.body.removeEventListener('keydown', this._onKeyDown); @@ -81,6 +109,7 @@ Phaser.Keyboard.prototype = { * There are some keys this can be annoying for, like the arrow keys or space bar, which make the browser window scroll. * You can use addKeyCapture to consume the keyboard event for specific keys so it doesn't bubble up to the the browser. * Pass in either a single keycode or an array/hash of keycodes. + * @method addKeyCapture * @param {Any} keycode */ addKeyCapture: function (keycode) { @@ -99,7 +128,9 @@ Phaser.Keyboard.prototype = { }, /** - * @param {Number} keycode + * Description. + * @method removeKeyCapture + * @param {number} keycode */ removeKeyCapture: function (keycode) { @@ -107,14 +138,19 @@ Phaser.Keyboard.prototype = { }, + /** + * Description. + * @method clearCaptures + */ clearCaptures: function () { this._capture = {}; }, - /** + * Description. + * @method processKeyDown * @param {KeyboardEvent} event */ processKeyDown: function (event) { @@ -168,6 +204,8 @@ Phaser.Keyboard.prototype = { }, /** + * Description. + * @method processKeyUp * @param {KeyboardEvent} event */ processKeyUp: function (event) { @@ -197,6 +235,10 @@ Phaser.Keyboard.prototype = { }, + /** + * Description. + * @method reset + */ reset: function () { for (var key in this._keys) @@ -207,8 +249,10 @@ Phaser.Keyboard.prototype = { }, /** - * @param {Number} keycode - * @param {Number} [duration] + * Description. + * @method justPressed + * @param {number} keycode + * @param {number} [duration] * @return {bool} */ justPressed: function (keycode, duration) { @@ -224,9 +268,11 @@ Phaser.Keyboard.prototype = { }, - /** - * @param {Number} keycode - * @param {Number} [duration] + /** + * Description. + * @method justReleased + * @param {number} keycode + * @param {number} [duration] * @return {bool} */ justReleased: function (keycode, duration) { @@ -242,8 +288,10 @@ Phaser.Keyboard.prototype = { }, - /** - * @param {Number} keycode + /** + * Description. + * @method isDown + * @param {number} keycode * @return {bool} */ isDown: function (keycode) { diff --git a/src/input/MSPointer.js b/src/input/MSPointer.js index d6ffa313..1016a098 100644 --- a/src/input/MSPointer.js +++ b/src/input/MSPointer.js @@ -1,37 +1,92 @@ /** -* Phaser.MSPointer +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} +* @module Phaser.MSPointer +*/ + + +/** +* Phaser - MSPointer constructor. * -* The MSPointer class handles touch interactions with the game and the resulting Pointer objects. +* @class Phaser.MSPointer +* @classdesc The MSPointer class handles touch interactions with the game and the resulting Pointer objects. * It will work only in Internet Explorer 10 and Windows Store or Windows Phone 8 apps using JavaScript. * http://msdn.microsoft.com/en-us/library/ie/hh673557(v=vs.85).aspx +* @constructor +* @param {Phaser.Game} game - A reference to the currently running game. */ Phaser.MSPointer = function (game) { + /** + * @property {Phaser.Game} game - Local reference to game. + */ this.game = game; + + /** + * @property {Phaser.Game} callbackContext - Description. + */ this.callbackContext = this.game; + /** + * @property {Description} mouseDownCallback - Description. + * @default + */ this.mouseDownCallback = null; + + /** + * @property {Description} mouseMoveCallback - Description. + * @default + */ this.mouseMoveCallback = null; + + /** + * @property {Description} mouseUpCallback - Description. + * @default + */ this.mouseUpCallback = null; }; Phaser.MSPointer.prototype = { + /** + * @property {Phaser.Game} game - Local reference to game. + */ game: null, /** * You can disable all Input by setting disabled = true. While set all new input related events will be ignored. - * @type {bool} + * @property {bool} disabled */ disabled: false, + /** + * Description. + * @property {Description} _onMSPointerDown + * @private + * @default + */ _onMSPointerDown: null, + + /** + * Description. + * @property {Description} _onMSPointerMove + * @private + * @default + */ _onMSPointerMove: null, + + /** + * Description. + * @property {Description} _onMSPointerUp + * @private + * @default + */ _onMSPointerUp: null, /** - * Starts the event listeners running + * Starts the event listeners running. * @method start */ start: function () { @@ -64,6 +119,7 @@ Phaser.MSPointer.prototype = { }, /** + * Description. * @method onPointerDown * @param {Any} event **/ @@ -82,6 +138,7 @@ Phaser.MSPointer.prototype = { }, /** + * Description. * @method onPointerMove * @param {Any} event **/ @@ -100,6 +157,7 @@ Phaser.MSPointer.prototype = { }, /** + * Description. * @method onPointerUp * @param {Any} event **/ @@ -118,7 +176,7 @@ Phaser.MSPointer.prototype = { }, /** - * Stop the event listeners + * Stop the event listeners. * @method stop */ stop: function () { diff --git a/src/input/Mouse.js b/src/input/Mouse.js index 2c762435..bf78e3c8 100644 --- a/src/input/Mouse.js +++ b/src/input/Mouse.js @@ -1,10 +1,47 @@ +/** +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} +* @module Phaser.Mouse +*/ + + +/** +* Phaser - Mouse constructor. +* +* @class Phaser.Mouse +* @classdesc The Mouse class +* @constructor +* @param {Phaser.Game} game - A reference to the currently running game. +*/ Phaser.Mouse = function (game) { + /** + * @property {Phaser.Game} game - Local reference to game. + */ this.game = game; + + /** + * @property {Phaser.Game} callbackContext - Description. + */ this.callbackContext = this.game; + /** + * @property {Description} mouseDownCallback - Description. + * @default + */ this.mouseDownCallback = null; + + /** + * @property {Description} mouseMoveCallback - Description. + * @default + */ this.mouseMoveCallback = null; + + /** + * @property {Description} mouseUpCallback - Description. + * @default + */ this.mouseUpCallback = null; }; @@ -15,22 +52,27 @@ Phaser.Mouse.RIGHT_BUTTON = 2; Phaser.Mouse.prototype = { + /** + * @property {Phaser.Game} game - Local reference to game. + */ game: null, /** * You can disable all Input by setting disabled = true. While set all new input related events will be ignored. - * @type {bool} + * @property {bool} disabled + * @default */ disabled: false, /** * If the mouse has been Pointer Locked successfully this will be set to true. - * @type {bool} + * @property {bool} locked + * @default */ locked: false, /** - * Starts the event listeners running + * Starts the event listeners running. * @method start */ start: function () { @@ -62,6 +104,8 @@ Phaser.Mouse.prototype = { }, /** + * Description. + * @method onMouseDown * @param {MouseEvent} event */ onMouseDown: function (event) { @@ -83,6 +127,8 @@ Phaser.Mouse.prototype = { }, /** + * Description + * @method onMouseMove * @param {MouseEvent} event */ onMouseMove: function (event) { @@ -104,6 +150,8 @@ Phaser.Mouse.prototype = { }, /** + * Description. + * @method onMouseUp * @param {MouseEvent} event */ onMouseUp: function (event) { @@ -124,6 +172,10 @@ Phaser.Mouse.prototype = { }, + /** + * Description. + * @method requestPointerLock + */ requestPointerLock: function () { if (this.game.device.pointerLock) @@ -147,6 +199,11 @@ Phaser.Mouse.prototype = { }, + /** + * Description. + * @method pointerLockChange + * @param {MouseEvent} event + */ pointerLockChange: function (event) { var element = this.game.stage.canvas; @@ -164,6 +221,10 @@ Phaser.Mouse.prototype = { }, + /** + * Description. + * @method releasePointerLock + */ releasePointerLock: function () { document.exitPointerLock = document.exitPointerLock || document.mozExitPointerLock || document.webkitExitPointerLock; @@ -177,7 +238,7 @@ Phaser.Mouse.prototype = { }, /** - * Stop the event listeners + * Stop the event listeners. * @method stop */ stop: function () { diff --git a/src/input/Pointer.js b/src/input/Pointer.js index 658385fc..dc0b4785 100644 --- a/src/input/Pointer.js +++ b/src/input/Pointer.js @@ -1,193 +1,232 @@ /** -* Phaser - Pointer +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} +* @module Phaser.Pointer +*/ + +/** +* Phaser - Pointer constructor. * -* A Pointer object is used by the Mouse, Touch and MSPoint managers and represents a single finger on the touch screen. +* @class Phaser.Pointer +* @classdesc A Pointer object is used by the Mouse, Touch and MSPoint managers and represents a single finger on the touch screen. +* @constructor +* @param {Phaser.Game} game - A reference to the currently running game. +* @param {Description} id - Description. */ Phaser.Pointer = function (game, id) { /** - * Local private variable to store the status of dispatching a hold event - * @property _holdSent - * @type {bool} + * Local private variable to store the status of dispatching a hold event. + * @property {bool} _holdSent * @private + * @default */ this._holdSent = false; /** - * Local private variable storing the short-term history of pointer movements - * @property _history - * @type {Array} + * Local private variable storing the short-term history of pointer movements. + * @property {array} _history * @private */ this._history = []; /** * Local private variable storing the time at which the next history drop should occur - * @property _lastDrop - * @type {Number} + * @property {number} _lastDrop * @private + * @default */ this._nextDrop = 0; - // Monitor events outside of a state reset loop + /** + * Monitor events outside of a state reset loop. + * @property {bool} _stateReset + * @private + * @default + */ this._stateReset = false; /** * A Vector object containing the initial position when the Pointer was engaged with the screen. - * @property positionDown - * @type {Vec2} + * @property {Vec2} positionDown + * @default **/ this.positionDown = null; /** * A Vector object containing the current position of the Pointer on the screen. - * @property position - * @type {Vec2} + * @property {Vec2} position + * @default **/ this.position = null; /** * A Circle object centered on the x/y screen coordinates of the Pointer. - * Default size of 44px (Apple's recommended "finger tip" size) - * @property circle - * @type {Circle} + * Default size of 44px (Apple's recommended "finger tip" size). + * @property {Circle} circle + * @default **/ this.circle = null; /** - * - * @property withinGame - * @type {bool} + * Description. + * @property {bool} withinGame */ this.withinGame = false; /** - * The horizontal coordinate of point relative to the viewport in pixels, excluding any scroll offset - * @property clientX - * @type {Number} + * The horizontal coordinate of point relative to the viewport in pixels, excluding any scroll offset. + * @property {number} clientX + * @default */ this.clientX = -1; /** - * The vertical coordinate of point relative to the viewport in pixels, excluding any scroll offset - * @property clientY - * @type {Number} + * The vertical coordinate of point relative to the viewport in pixels, excluding any scroll offset. + * @property {number} clientY + * @default */ this.clientY = -1; /** - * The horizontal coordinate of point relative to the viewport in pixels, including any scroll offset - * @property pageX - * @type {Number} + * The horizontal coordinate of point relative to the viewport in pixels, including any scroll offset. + * @property {number} pageX + * @default */ this.pageX = -1; /** - * The vertical coordinate of point relative to the viewport in pixels, including any scroll offset - * @property pageY - * @type {Number} + * The vertical coordinate of point relative to the viewport in pixels, including any scroll offset. + * @property {number} pageY + * @default */ this.pageY = -1; /** - * The horizontal coordinate of point relative to the screen in pixels - * @property screenX - * @type {Number} + * The horizontal coordinate of point relative to the screen in pixels. + * @property {number} screenX + * @default */ this.screenX = -1; /** - * The vertical coordinate of point relative to the screen in pixels - * @property screenY - * @type {Number} + * The vertical coordinate of point relative to the screen in pixels. + * @property {number} screenY + * @default */ this.screenY = -1; /** * The horizontal coordinate of point relative to the game element. This value is automatically scaled based on game size. - * @property x - * @type {Number} + * @property {number} x + * @default */ this.x = -1; /** * The vertical coordinate of point relative to the game element. This value is automatically scaled based on game size. - * @property y - * @type {Number} + * @property {number} y + * @default */ this.y = -1; /** - * If the Pointer is a mouse this is true, otherwise false - * @property isMouse + * If the Pointer is a mouse this is true, otherwise false. + * @property {bool} isMouse * @type {bool} - **/ + */ this.isMouse = false; /** - * If the Pointer is touching the touchscreen, or the mouse button is held down, isDown is set to true - * @property isDown - * @type {bool} - **/ + * If the Pointer is touching the touchscreen, or the mouse button is held down, isDown is set to true. + * @property {bool} isDown + * @default + */ this.isDown = false; /** - * If the Pointer is not touching the touchscreen, or the mouse button is up, isUp is set to true - * @property isUp - * @type {bool} - **/ + * If the Pointer is not touching the touchscreen, or the mouse button is up, isUp is set to true. + * @property {bool} isUp + * @default + */ this.isUp = true; /** * A timestamp representing when the Pointer first touched the touchscreen. - * @property timeDown - * @type {Number} - **/ + * @property {number} timeDown + * @default + */ this.timeDown = 0; /** * A timestamp representing when the Pointer left the touchscreen. - * @property timeUp - * @type {Number} - **/ + * @property {number} timeUp + * @default + */ this.timeUp = 0; /** - * A timestamp representing when the Pointer was last tapped or clicked - * @property previousTapTime - * @type {Number} - **/ + * A timestamp representing when the Pointer was last tapped or clicked. + * @property {number} previousTapTime + * @default + */ this.previousTapTime = 0; /** - * The total number of times this Pointer has been touched to the touchscreen - * @property totalTouches - * @type {Number} - **/ + * The total number of times this Pointer has been touched to the touchscreen. + * @property {number} totalTouches + * @default + */ this.totalTouches = 0; /** - * The number of miliseconds since the last click - * @property msSinceLastClick - * @type {Number} - **/ + * The number of miliseconds since the last click. + * @property {number} msSinceLastClick + * @default + */ this.msSinceLastClick = Number.MAX_VALUE; /** * The Game Object this Pointer is currently over / touching / dragging. - * @property targetObject - * @type {Any} - **/ + * @property {Any} targetObject + * @default + */ this.targetObject = null; + /** + * @property {Phaser.Game} game - Local reference to game. + */ this.game = game; + + /** + * @property {Description} id - Description. + */ this.id = id; + /** + * Description. + * @property {bool} isDown - Description. + * @default + */ this.active = false; + /** + * Description + * @property {Phaser.Point} position + */ this.position = new Phaser.Point(); + + /** + * Description + * @property {Phaser.Point} positionDown + */ this.positionDown = new Phaser.Point(); + /** + * Description + * @property {Phaser.Circle} circle + */ this.circle = new Phaser.Circle(0, 0, 44); if (id == 0) @@ -200,7 +239,7 @@ Phaser.Pointer = function (game, id) { Phaser.Pointer.prototype = { /** - * Called when the Pointer is pressed onto the touchscreen + * Called when the Pointer is pressed onto the touchscreen. * @method start * @param {Any} event */ @@ -264,6 +303,10 @@ Phaser.Pointer.prototype = { }, + /** + * Description. + * @method update + */ update: function () { if (this.active) @@ -438,7 +481,7 @@ Phaser.Pointer.prototype = { }, /** - * Called when the Pointer leaves the target area + * Called when the Pointer leaves the target area. * @method leave * @param {Any} event */ @@ -450,7 +493,7 @@ Phaser.Pointer.prototype = { }, /** - * Called when the Pointer leaves the touchscreen + * Called when the Pointer leaves the touchscreen. * @method stop * @param {Any} event */ @@ -529,9 +572,9 @@ Phaser.Pointer.prototype = { }, /** - * The Pointer is considered justPressed if the time it was pressed onto the touchscreen or clicked is less than justPressedRate + * The Pointer is considered justPressed if the time it was pressed onto the touchscreen or clicked is less than justPressedRate. * @method justPressed - * @param {Number} [duration]. + * @param {number} [duration] * @return {bool} */ justPressed: function (duration) { @@ -543,9 +586,9 @@ Phaser.Pointer.prototype = { }, /** - * The Pointer is considered justReleased if the time it left the touchscreen is less than justReleasedRate + * The Pointer is considered justReleased if the time it left the touchscreen is less than justReleasedRate. * @method justReleased - * @param {Number} [duration]. + * @param {number} [duration] * @return {bool} */ justReleased: function (duration) { @@ -587,7 +630,7 @@ Phaser.Pointer.prototype = { /** * Returns a string representation of this object. * @method toString - * @return {String} a string representation of the instance. + * @return {string} A string representation of the instance. **/ toString: function () { return "[{Pointer (id=" + this.id + " identifer=" + this.identifier + " active=" + this.active + " duration=" + this.duration + " withinGame=" + this.withinGame + " x=" + this.x + " y=" + this.y + " clientX=" + this.clientX + " clientY=" + this.clientY + " screenX=" + this.screenX + " screenY=" + this.screenY + " pageX=" + this.pageX + " pageY=" + this.pageY + ")}]"; @@ -595,13 +638,12 @@ Phaser.Pointer.prototype = { }; +/** +* How long the Pointer has been depressed on the touchscreen. If not currently down it returns -1. +* @return {number} +*/ Object.defineProperty(Phaser.Pointer.prototype, "duration", { - /** - * How long the Pointer has been depressed on the touchscreen. If not currently down it returns -1. - * @property duration - * @type {Number} - **/ get: function () { if (this.isUp) @@ -615,12 +657,12 @@ Object.defineProperty(Phaser.Pointer.prototype, "duration", { }); +/** + * Gets the X value of this Pointer in world coordinates based on the given camera. + * @return {Description} + */ Object.defineProperty(Phaser.Pointer.prototype, "worldX", { - /** - * Gets the X value of this Pointer in world coordinates based on the given camera. - * @param {Camera} [camera] - */ get: function () { return this.game.world.camera.x + this.x; @@ -629,12 +671,12 @@ Object.defineProperty(Phaser.Pointer.prototype, "worldX", { }); +/** + * Gets the Y value of this Pointer in world coordinates based on the given camera. + * @return {Description} + */ Object.defineProperty(Phaser.Pointer.prototype, "worldY", { - /** - * Gets the Y value of this Pointer in world coordinates based on the given camera. - * @param {Camera} [camera] - */ get: function () { return this.game.world.camera.y + this.y; diff --git a/src/input/Touch.js b/src/input/Touch.js index 155129ab..b680fc89 100644 --- a/src/input/Touch.js +++ b/src/input/Touch.js @@ -1,24 +1,75 @@ +/** +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} +* @module Phaser.Touch +*/ + /** * Phaser - Touch * -* The Touch class handles touch interactions with the game and the resulting Pointer objects. -* http://www.w3.org/TR/touch-events/ -* https://developer.mozilla.org/en-US/docs/DOM/TouchList -* http://www.html5rocks.com/en/mobile/touchandmouse/ -* Note: Android 2.x only supports 1 touch event at once, no multi-touch +* @class +* +* @classdesc The Touch class handles touch interactions with the game and the resulting Pointer objects. +* {@link http://www.w3.org/TR/touch-events/} +* {@link https://developer.mozilla.org/en-US/docs/DOM/TouchList} +* {@link http://www.html5rocks.com/en/mobile/touchandmouse/} +*

Note: Android 2.x only supports 1 touch event at once, no multi-touch. +* @constructor +* @param {Phaser.Game} game - A reference to the currently running game. */ Phaser.Touch = function (game) { + /** + * @property {Phaser.Game} game - Local reference to game. + */ this.game = game; + + /** + * @property {Phaser.Game} callbackContext - Description. + */ this.callbackContext = this.game; + /** + * @property {Phaser.Game} touchStartCallback - Description. + * @default + */ this.touchStartCallback = null; + + /** + * @property {Phaser.Game} touchMoveCallback - Description. + * @default + */ this.touchMoveCallback = null; + + /** + * @property {Phaser.Game} touchEndCallback - Description. + * @default + */ this.touchEndCallback = null; + + /** + * @property {Phaser.Game} touchEnterCallback - Description. + * @default + */ this.touchEnterCallback = null; + + /** + * @property {Phaser.Game} touchLeaveCallback - Description. + * @default + */ this.touchLeaveCallback = null; + + /** + * @property {Description} touchCancelCallback - Description. + * @default + */ this.touchCancelCallback = null; - + + /** + * @property {bool} preventDefault - Description. + * @default + */ this.preventDefault = true; }; @@ -29,7 +80,8 @@ Phaser.Touch.prototype = { /** * You can disable all Input by setting disabled = true. While set all new input related events will be ignored. - * @type {bool} + * @method disabled + * @return {bool} */ disabled: false, @@ -42,7 +94,7 @@ Phaser.Touch.prototype = { _onTouchMove: null, /** - * Starts the event listeners running + * Starts the event listeners running. * @method start */ start: function () { @@ -86,9 +138,8 @@ Phaser.Touch.prototype = { }, /** - * Consumes all touchmove events on the document (only enable this if you know you need it!) + * Consumes all touchmove events on the document (only enable this if you know you need it!). * @method consumeTouchMove - * @param {Any} event **/ consumeDocumentTouches: function () { @@ -101,7 +152,7 @@ Phaser.Touch.prototype = { }, /** - * + * Description. * @method onTouchStart * @param {Any} event **/ @@ -133,8 +184,8 @@ Phaser.Touch.prototype = { }, /** - * Touch cancel - touches that were disrupted (perhaps by moving into a plugin or browser chrome) - * Occurs for example on iOS when you put down 4 fingers and the app selector UI appears + * Touch cancel - touches that were disrupted (perhaps by moving into a plugin or browser chrome). + * Occurs for example on iOS when you put down 4 fingers and the app selector UI appears. * @method onTouchCancel * @param {Any} event **/ @@ -165,8 +216,8 @@ Phaser.Touch.prototype = { }, /** - * For touch enter and leave its a list of the touch points that have entered or left the target - * Doesn't appear to be supported by most browsers on a canvas element yet + * For touch enter and leave its a list of the touch points that have entered or left the target. + * Doesn't appear to be supported by most browsers on a canvas element yet. * @method onTouchEnter * @param {Any} event **/ @@ -195,8 +246,8 @@ Phaser.Touch.prototype = { }, /** - * For touch enter and leave its a list of the touch points that have entered or left the target - * Doesn't appear to be supported by most browsers on a canvas element yet + * For touch enter and leave its a list of the touch points that have entered or left the target. + * Doesn't appear to be supported by most browsers on a canvas element yet. * @method onTouchLeave * @param {Any} event **/ @@ -220,7 +271,7 @@ Phaser.Touch.prototype = { }, /** - * + * Description. * @method onTouchMove * @param {Any} event **/ @@ -244,7 +295,7 @@ Phaser.Touch.prototype = { }, /** - * + * Description. * @method onTouchEnd * @param {Any} event **/ @@ -271,7 +322,7 @@ Phaser.Touch.prototype = { }, /** - * Stop the event listeners + * Stop the event listeners. * @method stop */ stop: function () { diff --git a/src/loader/Cache.js b/src/loader/Cache.js index bba57f00..5998b59d 100644 --- a/src/loader/Cache.js +++ b/src/loader/Cache.js @@ -1,60 +1,68 @@ /** -* Cache +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} +* @module Phaser.Cache +*/ + +/** +* Phaser.Cache constructor. * -* A game only has one instance of a Cache and it is used to store all externally loaded assets such +* @class Phaser.Cache +* @classdesc A game only has one instance of a Cache and it is used to store all externally loaded assets such * as images, sounds and data files as a result of Loader calls. Cache items use string based keys for look-up. -* -* @package Phaser.Cache -* @author Richard Davey -* @copyright 2013 Photon Storm Ltd. -* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License +* @constructor +* @param {Phaser.Game} game - A reference to the currently running game. */ Phaser.Cache = function (game) { /** - * Local reference to Game. - */ + * @property {Phaser.Game} game - Local reference to game. + */ this.game = game; - /** - * Canvas key-value container. - * @type {object} - * @private - */ + /** + * @property {object} game - Canvas key-value container. + * @private + */ this._canvases = {}; /** - * Image key-value container. - * @type {object} - */ + * @property {object} _images - Image key-value container. + * @private + */ this._images = {}; /** - * RenderTexture key-value container. - * @type {object} - */ + * @property {object} _textures - RenderTexture key-value container. + * @private + */ this._textures = {}; /** - * Sound key-value container. - * @type {object} - */ + * @property {object} _sounds - Sound key-value container. + * @private + */ this._sounds = {}; /** - * Text key-value container. - * @type {object} - */ + * @property {object} _text - Text key-value container. + * @private + */ this._text = {}; /** - * Tilemap key-value container. - * @type {object} - */ + * @property {object} _tilemaps - Tilemap key-value container. + * @private + */ this._tilemaps = {}; + this.addDefaultImage(); + /** + * @property {Phaser.Signal} onSoundUnlock - Description. + */ this.onSoundUnlock = new Phaser.Signal; }; @@ -63,9 +71,9 @@ Phaser.Cache.prototype = { /** * Add a new canvas. - * @param key {string} Asset key for this canvas. - * @param canvas {HTMLCanvasElement} Canvas DOM element. - * @param context {CanvasRenderingContext2D} Render context of this canvas. + * @param {string} key - Asset key for this canvas. + * @param {HTMLCanvasElement} canvas - Canvas DOM element. + * @param {CanvasRenderingContext2D} context - Render context of this canvas. */ addCanvas: function (key, canvas, context) { @@ -88,12 +96,12 @@ Phaser.Cache.prototype = { /** * Add a new sprite sheet. - * @param key {string} Asset key for the sprite sheet. - * @param url {string} URL of this sprite sheet file. - * @param data {object} Extra sprite sheet data. - * @param frameWidth {number} Width of the sprite sheet. - * @param frameHeight {number} Height of the sprite sheet. - * @param frameMax {number} How many frames stored in the sprite sheet. + * @param {string} key - Asset key for the sprite sheet. + * @param {string} url - URL of this sprite sheet file. + * @param {object} data - Extra sprite sheet data. + * @param {number} frameWidth - Width of the sprite sheet. + * @param {number} frameHeight - Height of the sprite sheet. + * @param {number} frameMax - How many frames stored in the sprite sheet. */ addSpriteSheet: function (key, url, data, frameWidth, frameHeight, frameMax) { @@ -108,10 +116,10 @@ Phaser.Cache.prototype = { /** * Add a new tilemap. - * @param key {string} Asset key for the texture atlas. - * @param url {string} URL of this texture atlas file. - * @param data {object} Extra texture atlas data. - * @param atlasData {object} Texture atlas frames data. + * @param {string} key - Asset key for the texture atlas. + * @param {string} url - URL of this texture atlas file. + * @param {object} data - Extra texture atlas data. + * @param {object} atlasData - Texture atlas frames data. */ addTilemap: function (key, url, data, mapData, format) { @@ -124,10 +132,11 @@ Phaser.Cache.prototype = { /** * Add a new texture atlas. - * @param key {string} Asset key for the texture atlas. - * @param url {string} URL of this texture atlas file. - * @param data {object} Extra texture atlas data. - * @param atlasData {object} Texture atlas frames data. + * @param {string} key - Asset key for the texture atlas. + * @param {string} url - URL of this texture atlas file. + * @param {object} data - Extra texture atlas data. + * @param {object} atlasData - Texture atlas frames data. + * @param {Description} format - Description. */ addTextureAtlas: function (key, url, data, atlasData, format) { @@ -153,9 +162,9 @@ Phaser.Cache.prototype = { /** * Add a new Bitmap Font. - * @param key {string} Asset key for the font texture. - * @param url {string} URL of this font xml file. - * @param data {object} Extra font data. + * @param {string} key - Asset key for the font texture. + * @param {string} url - URL of this font xml file. + * @param {object} data - Extra font data. * @param xmlData {object} Texture atlas frames data. */ addBitmapFont: function (key, url, data, xmlData) { @@ -173,6 +182,7 @@ Phaser.Cache.prototype = { /** * Adds a default image to be used when a key is wrong / missing. * Is mapped to the key __default + * @method addDefaultImage */ addDefaultImage: function () { @@ -191,9 +201,10 @@ Phaser.Cache.prototype = { /** * Add a new image. - * @param key {string} Asset key for the image. - * @param url {string} URL of this image file. - * @param data {object} Extra image data. + * @method addImage + * @param {string} key - Asset key for the image. + * @param {string} url - URL of this image file. + * @param {object} data - Extra image data. */ addImage: function (key, url, data) { @@ -207,9 +218,10 @@ Phaser.Cache.prototype = { /** * Add a new sound. - * @param key {string} Asset key for the sound. - * @param url {string} URL of this sound file. - * @param data {object} Extra sound data. + * @method addSound + * @param {string} key - Asset key for the sound. + * @param {string} url - URL of this sound file. + * @param {object} data - Extra sound data. */ addSound: function (key, url, data, webAudio, audioTag) { @@ -228,6 +240,11 @@ Phaser.Cache.prototype = { }, + /** + * Reload a sound. + * @method reloadSound + * @param {string} key - Asset key for the sound. + */ reloadSound: function (key) { var _this = this; @@ -244,6 +261,11 @@ Phaser.Cache.prototype = { } }, + /** + * Description. + * @method reloadSoundComplete + * @param {string} key - Asset key for the sound. + */ reloadSoundComplete: function (key) { if (this._sounds[key]) @@ -254,6 +276,11 @@ Phaser.Cache.prototype = { }, + /** + * Description. + * @method updateSound + * @param {string} key - Asset key for the sound. + */ updateSound: function (key, property, value) { if (this._sounds[key]) @@ -265,8 +292,8 @@ Phaser.Cache.prototype = { /** * Add a new decoded sound. - * @param key {string} Asset key for the sound. - * @param data {object} Extra sound data. + * @param {string} key - Asset key for the sound. + * @param {object} data - Extra sound data. */ decodedSound: function (key, data) { @@ -278,9 +305,9 @@ Phaser.Cache.prototype = { /** * Add a new text data. - * @param key {string} Asset key for the text data. - * @param url {string} URL of this text data file. - * @param data {object} Extra text data. + * @param {string} key - Asset key for the text data. + * @param {string} url - URL of this text data file. + * @param {object} data - Extra text data. */ addText: function (key, url, data) { @@ -293,7 +320,7 @@ Phaser.Cache.prototype = { /** * Get canvas by key. - * @param key Asset key of the canvas you want. + * @param {string} key - Asset key of the canvas you want. * @return {object} The canvas you want. */ getCanvas: function (key) { @@ -308,8 +335,8 @@ Phaser.Cache.prototype = { /** * Checks if an image key exists. - * @param key Asset key of the image you want. - * @return {boolean} True if the key exists, otherwise false. + * @param {string} key - Asset key of the image you want. + * @return {bool} True if the key exists, otherwise false. */ checkImageKey: function (key) { @@ -324,7 +351,7 @@ Phaser.Cache.prototype = { /** * Get image data by key. - * @param key Asset key of the image you want. + * @param {string} key - Asset key of the image you want. * @return {object} The image data you want. */ getImage: function (key) { @@ -339,7 +366,7 @@ Phaser.Cache.prototype = { /** * Get tilemap data by key. - * @param key Asset key of the tilemap you want. + * @param {string} key - Asset key of the tilemap you want. * @return {object} The tilemap data. The tileset image is in the data property, the map data in mapData. */ getTilemap: function (key) { @@ -354,7 +381,7 @@ Phaser.Cache.prototype = { /** * Get frame data by key. - * @param key Asset key of the frame data you want. + * @param {string} key - Asset key of the frame data you want. * @return {object} The frame data you want. */ getFrameData: function (key) { @@ -369,7 +396,7 @@ Phaser.Cache.prototype = { /** * Get a single frame out of a frameData set by key. - * @param key Asset key of the frame data you want. + * @param {string} key - Asset key of the frame data you want. * @return {object} The frame data you want. */ getFrameByIndex: function (key, frame) { @@ -384,7 +411,7 @@ Phaser.Cache.prototype = { /** * Get a single frame out of a frameData set by key. - * @param key Asset key of the frame data you want. + * @param {string} key - Asset key of the frame data you want. * @return {object} The frame data you want. */ getFrameByName: function (key, frame) { @@ -399,7 +426,7 @@ Phaser.Cache.prototype = { /** * Get a single frame by key. You'd only do this to get the default Frame created for a non-atlas/spritesheet image. - * @param key Asset key of the frame data you want. + * @param {string} key - Asset key of the frame data you want. * @return {object} The frame data you want. */ getFrame: function (key) { @@ -414,7 +441,7 @@ Phaser.Cache.prototype = { /** * Get a single frame by key. You'd only do this to get the default Frame created for a non-atlas/spritesheet image. - * @param key Asset key of the frame data you want. + * @param {string} key - Asset key of the frame data you want. * @return {object} The frame data you want. */ getTextureFrame: function (key) { @@ -429,7 +456,7 @@ Phaser.Cache.prototype = { /** * Get a RenderTexture by key. - * @param key Asset key of the RenderTexture you want. + * @param {string} key - Asset key of the RenderTexture you want. * @return {object} The RenderTexture you want. */ getTexture: function (key) { @@ -445,7 +472,7 @@ Phaser.Cache.prototype = { /** * Get sound by key. - * @param key Asset key of the sound you want. + * @param {string} key - Asset key of the sound you want. * @return {object} The sound you want. */ getSound: function (key) { @@ -461,7 +488,7 @@ Phaser.Cache.prototype = { /** * Get sound data by key. - * @param key Asset key of the sound you want. + * @param {string} key - Asset key of the sound you want. * @return {object} The sound data you want. */ getSoundData: function (key) { @@ -477,7 +504,7 @@ Phaser.Cache.prototype = { /** * Check whether an asset is decoded sound. - * @param key Asset key of the sound you want. + * @param {string} key - Asset key of the sound you want. * @return {object} The sound data you want. */ isSoundDecoded: function (key) { @@ -491,7 +518,7 @@ Phaser.Cache.prototype = { /** * Check whether an asset is decoded sound. - * @param key Asset key of the sound you want. + * @param {string} key - Asset key of the sound you want. * @return {object} The sound data you want. */ isSoundReady: function (key) { @@ -502,7 +529,7 @@ Phaser.Cache.prototype = { /** * Check whether an asset is sprite sheet. - * @param key Asset key of the sprite sheet you want. + * @param {string} key - Asset key of the sprite sheet you want. * @return {object} The sprite sheet data you want. */ isSpriteSheet: function (key) { @@ -518,7 +545,7 @@ Phaser.Cache.prototype = { /** * Get text data by key. - * @param key Asset key of the text data you want. + * @param {string} key - Asset key of the text data you want. * @return {object} The text data you want. */ getText: function (key) { @@ -572,24 +599,41 @@ Phaser.Cache.prototype = { return this.getKeys(this._text); }, + /** + * Description. + * @method removeCanvas + */ removeCanvas: function (key) { delete this._canvases[key]; }, + /** + * Description. + * @method removeImage + */ removeImage: function (key) { delete this._images[key]; }, + /** + * Description. + * @method removeSound + */ removeSound: function (key) { delete this._sounds[key]; }, + /** + * Description. + * @method removeText + */ removeText: function (key) { delete this._text[key]; }, /** * Clean up cache memory. + * @method destroy */ destroy: function () { diff --git a/src/loader/Loader.js b/src/loader/Loader.js index 25777679..b4364d0e 100644 --- a/src/loader/Loader.js +++ b/src/loader/Loader.js @@ -1,71 +1,86 @@ /** -* Phaser.Loader -* +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} +* @module Phaser.Loader +*/ + +/** +* Phaser loader constructor. * The Loader handles loading all external content such as Images, Sounds, Texture Atlases and data files. * It uses a combination of Image() loading and xhr and provides progress and completion callbacks. +* @class Phaser.Loader +* @classdesc The Loader handles loading all external content such as Images, Sounds, Texture Atlases and data files. +* It uses a combination of Image() loading and xhr and provides progress and completion callbacks. +* @constructor +* @param {Phaser.Game} game - A reference to the currently running game. */ Phaser.Loader = function (game) { /** - * Local reference to Game. + * @property {Phaser.Game} game - Local reference to game. */ this.game = game; /** - * Array stores assets keys. So you can get that asset by its unique key. - */ + * @property {array} _keys - Array stores assets keys. So you can get that asset by its unique key. + * @private + */ this._keys = []; /** - * Contains all the assets file infos. - */ + * @property {Description} _fileList - Contains all the assets file infos. + * @private + */ this._fileList = {}; /** - * Indicates assets loading progress. (from 0 to 100) - * @type {number} + * @property {number} _progressChunk - Indicates assets loading progress. (from 0 to 100) + * @private + * @default */ this._progressChunk = 0; /** - * An XMLHttpRequest object used for loading text and audio data - * @type {XMLHttpRequest} + * @property {XMLHttpRequest} - An XMLHttpRequest object used for loading text and audio data. + * @private */ this._xhr = new XMLHttpRequest(); - /** - * Length of assets queue. - * @type {number} + /** + * @property {number} - Length of assets queue. + * @default */ this.queueSize = 0; /** - * True if the Loader is in the process of loading the queue. - * @type {bool} + * @property {bool} isLoading - True if the Loader is in the process of loading the queue. + * @default */ this.isLoading = false; /** - * True if all assets in the queue have finished loading. - * @type {bool} + * @property {bool} hasLoaded - True if all assets in the queue have finished loading. + * @default */ this.hasLoaded = false; /** - * The Load progress percentage value (from 0 to 100) - * @type {number} + * @property {number} progress - The Load progress percentage value (from 0 to 100) + * @default */ this.progress = 0; /** * You can optionally link a sprite to the preloader. * If you do so the Sprite's width or height will be cropped based on the percentage loaded. + * @property {Description} preloadSprite + * @default */ this.preloadSprite = null; /** - * The crossOrigin value applied to loaded images - * @type {string} + * @property {string} crossOrigin - The crossOrigin value applied to loaded images */ this.crossOrigin = ''; @@ -73,16 +88,29 @@ Phaser.Loader = function (game) { * If you want to append a URL before the path of any asset you can set this here. * Useful if you need to allow an asset url to be configured outside of the game code. * MUST have / on the end of it! - * @type {string} + * @property {string} baseURL + * @default */ this.baseURL = ''; /** - * Event Signals - */ + * @property {Phaser.Signal} onFileComplete - Event signal. + */ this.onFileComplete = new Phaser.Signal; + + /** + * @property {Phaser.Signal} onFileError - Event signal. + */ this.onFileError = new Phaser.Signal; + + /** + * @property {Phaser.Signal} onLoadStart - Event signal. + */ this.onLoadStart = new Phaser.Signal; + + /** + * @property {Phaser.Signal} onLoadComplete - Event signal. + */ this.onLoadComplete = new Phaser.Signal; }; @@ -95,7 +123,13 @@ Phaser.Loader.TEXTURE_ATLAS_JSON_HASH = 1; Phaser.Loader.TEXTURE_ATLAS_XML_STARLING = 2; Phaser.Loader.prototype = { - + /** + * Description. + * + * @method setPreloadSprite + * @param {Phaser.Sprite} sprite - Description. + * @param {number} direction - Description. + */ setPreloadSprite: function (sprite, direction) { direction = direction || 0; @@ -119,7 +153,8 @@ Phaser.Loader.prototype = { /** * Check whether asset exists with a specific key. - * @param key {string} Key of the asset you want to check. + * @method checkKeyExists + * @param {string} key - Key of the asset you want to check. * @return {bool} Return true if exists, otherwise return false. */ checkKeyExists: function (key) { @@ -136,8 +171,9 @@ Phaser.Loader.prototype = { }, /** - * Reset loader, this will remove all loaded assets. - */ + * Reset loader, this will remove all loaded assets. + * @method reset + */ reset: function () { this.preloadSprite = null; @@ -148,6 +184,11 @@ Phaser.Loader.prototype = { /** * Internal function that adds a new entry to the file list. + * @method addToFileList + * @param {Description} type - Description. + * @param {string} key - Description. + * @param {string} url - URL of Description. + * @param {Description} properties - Description. */ addToFileList: function (type, key, url, properties) { @@ -178,9 +219,10 @@ Phaser.Loader.prototype = { /** * Add an image to the Loader. - * @param key {string} Unique asset key of this image file. - * @param url {string} URL of image file. - * @param overwrite {boolean} If an entry with a matching key already exists this will over-write it + * @method image + * @param {string} key - Unique asset key of this image file. + * @param {string} url - URL of image file. + * @param {boolean} overwrite - If an entry with a matching key already exists this will over-write it */ image: function (key, url, overwrite) { @@ -195,8 +237,10 @@ Phaser.Loader.prototype = { /** * Add a text file to the Loader. - * @param key {string} Unique asset key of the text file. - * @param url {string} URL of the text file. + * @method text + * @param {string} key - Unique asset key of the text file. + * @param {string} url - URL of the text file. + * @param {bool} overwrite - True if Description. */ text: function (key, url, overwrite) { @@ -211,11 +255,12 @@ Phaser.Loader.prototype = { /** * Add a new sprite sheet loading request. - * @param key {string} Unique asset key of the sheet file. - * @param url {string} URL of sheet file. - * @param frameWidth {number} Width of each single frame. - * @param frameHeight {number} Height of each single frame. - * @param frameMax {number} How many frames in this sprite sheet. + * @method spritesheet + * @param {string} key - Unique asset key of the sheet file. + * @param {string} url - URL of the sheet file. + * @param {number} frameWidth - Width of each single frame. + * @param {number} frameHeight - Height of each single frame. + * @param {number} frameMax - How many frames in this sprite sheet. */ spritesheet: function (key, url, frameWidth, frameHeight, frameMax) { @@ -230,9 +275,10 @@ Phaser.Loader.prototype = { /** * Add a new audio file loading request. - * @param key {string} Unique asset key of the audio file. - * @param urls {Array} An array containing the URLs of the audio files, i.e.: [ 'jump.mp3', 'jump.ogg', 'jump.m4a' ] - * @param autoDecode {bool} When using Web Audio the audio files can either be decoded at load time or run-time. They can't be played until they are decoded, but this let's you control when that happens. Decoding is a non-blocking async process. + * @method audio + * @param {string} key - Unique asset key of the audio file. + * @param {Array} urls - An array containing the URLs of the audio files, i.e.: [ 'jump.mp3', 'jump.ogg', 'jump.m4a' ]. + * @param {bool} autoDecode - When using Web Audio the audio files can either be decoded at load time or run-time. They can't be played until they are decoded, but this let's you control when that happens. Decoding is a non-blocking async process. */ audio: function (key, urls, autoDecode) { @@ -247,11 +293,12 @@ Phaser.Loader.prototype = { /** * Add a new tilemap loading request. - * @param key {string} Unique asset key of the tilemap data. - * @param tilesetURL {string} The url of the tile set image file. - * @param [mapDataURL] {string} The url of the map data file (csv/json) - * @param [mapData] {object} An optional JSON data object (can be given in place of a URL). - * @param [format] {string} The format of the map data. + * @method tilemap + * @param {string} key - Unique asset key of the tilemap data. + * @param {string} tilesetURL - The url of the tile set image file. + * @param {string} [mapDataURL] - The url of the map data file (csv/json) + * @param {object} [mapData] - An optional JSON data object (can be given in place of a URL). + * @param {string} [format] - The format of the map data. */ tilemap: function (key, tilesetURL, mapDataURL, mapData, format) { @@ -293,10 +340,11 @@ Phaser.Loader.prototype = { /** * Add a new bitmap font loading request. - * @param key {string} Unique asset key of the bitmap font. - * @param textureURL {string} The url of the font image file. - * @param [xmlURL] {string} The url of the font data file (xml/fnt) - * @param [xmlData] {object} An optional XML data object. + * @method bitmapFont + * @param {string} key - Unique asset key of the bitmap font. + * @param {string} textureURL - The url of the font image file. + * @param {string} [xmlURL] - The url of the font data file (xml/fnt) + * @param {object} [xmlData] - An optional XML data object. */ bitmapFont: function (key, textureURL, xmlURL, xmlData) { @@ -349,18 +397,39 @@ Phaser.Loader.prototype = { }, + /** + * Description. + * @method atlasJSONArray + * @param {string} key - Unique asset key of the bitmap font. + * @param {Description} atlasURL - The url of the Description. + * @param {Description} atlasData - Description. + */ atlasJSONArray: function (key, textureURL, atlasURL, atlasData) { this.atlas(key, textureURL, atlasURL, atlasData, Phaser.Loader.TEXTURE_ATLAS_JSON_ARRAY); }, + /** + * Description. + * @method atlasJSONHash + * @param {string} key - Unique asset key of the bitmap font. + * @param {Description} atlasURL - The url of the Description. + * @param {Description} atlasData - Description. + */ atlasJSONHash: function (key, textureURL, atlasURL, atlasData) { this.atlas(key, textureURL, atlasURL, atlasData, Phaser.Loader.TEXTURE_ATLAS_JSON_HASH); }, + /** + * Description. + * @method atlasXML + * @param {string} key - Unique asset key of the bitmap font. + * @param {Description} atlasURL - The url of the Description. + * @param {Description} atlasData - Description. + */ atlasXML: function (key, textureURL, atlasURL, atlasData) { this.atlas(key, textureURL, atlasURL, atlasData, Phaser.Loader.TEXTURE_ATLAS_XML_STARLING); @@ -369,11 +438,12 @@ Phaser.Loader.prototype = { /** * Add a new texture atlas loading request. - * @param key {string} Unique asset key of the texture atlas file. - * @param textureURL {string} The url of the texture atlas image file. - * @param [atlasURL] {string} The url of the texture atlas data file (json/xml) - * @param [atlasData] {object} A JSON or XML data object. - * @param [format] {number} A value describing the format of the data. + * @method atlas + * @param {string} key - Unique asset key of the texture atlas file. + * @param {string} textureURL - The url of the texture atlas image file. + * @param {string} [atlasURL] - The url of the texture atlas data file (json/xml) + * @param {object} [atlasData] - A JSON or XML data object. + * @param {number} [format] - A value describing the format of the data. */ atlas: function (key, textureURL, atlasURL, atlasData, format) { @@ -448,6 +518,7 @@ Phaser.Loader.prototype = { /** * Remove loading request of a file. + * @method removeFile * @param key {string} Key of the file you want to remove. */ removeFile: function (key) { @@ -458,6 +529,7 @@ Phaser.Loader.prototype = { /** * Remove all file loading requests. + * @method removeAll */ removeAll: function () { @@ -467,6 +539,7 @@ Phaser.Loader.prototype = { /** * Load assets. + * @method start */ start: function () { @@ -497,6 +570,7 @@ Phaser.Loader.prototype = { /** * Load files. Private method ONLY used by loader. + * @method loadFile * @private */ loadFile: function () { @@ -589,6 +663,11 @@ Phaser.Loader.prototype = { }, + /** + * Load files. Private method ONLY used by loader. + * @method getAudioURL + * @param {Description} urls - Description. + */ getAudioURL: function (urls) { var extension; @@ -610,9 +689,10 @@ Phaser.Loader.prototype = { }, /** - * Error occured when load a file. - * @param key {string} Key of the error loading file. - */ + * Error occured when load a file. + * @method fileError + * @param {string} key - Key of the error loading file. + */ fileError: function (key) { this._fileList[key].loaded = true; @@ -627,9 +707,10 @@ Phaser.Loader.prototype = { }, /** - * Called when a file is successfully loaded. - * @param key {string} Key of the successfully loaded file. - */ + * Called when a file is successfully loaded. + * @method fileComplete + * @param {string} key - Key of the successfully loaded file. + */ fileComplete: function (key) { if (!this._fileList[key]) @@ -790,9 +871,10 @@ Phaser.Loader.prototype = { }, /** - * Successfully loaded a JSON file. - * @param key {string} Key of the loaded JSON file. - */ + * Successfully loaded a JSON file. + * @method jsonLoadComplete + * @param {string} key - Key of the loaded JSON file. + */ jsonLoadComplete: function (key) { var data = JSON.parse(this._xhr.response); @@ -812,9 +894,10 @@ Phaser.Loader.prototype = { }, /** - * Successfully loaded a CSV file. - * @param key {string} Key of the loaded CSV file. - */ + * Successfully loaded a CSV file. + * @method csvLoadComplete + * @param {string} key - Key of the loaded CSV file. + */ csvLoadComplete: function (key) { var data = this._xhr.response; @@ -827,9 +910,10 @@ Phaser.Loader.prototype = { }, /** - * Error occured when load a JSON. - * @param key {string} Key of the error loading JSON file. - */ + * Error occured when load a JSON. + * @method dataLoadError + * @param {string} key - Key of the error loading JSON file. + */ dataLoadError: function (key) { var file = this._fileList[key]; @@ -842,6 +926,11 @@ Phaser.Loader.prototype = { }, + /** + * Successfully loaded an XML file. + * @method xmlLoadComplete + * @param {string} key - Key of the loaded XML file. + */ xmlLoadComplete: function (key) { var data = this._xhr.response; diff --git a/src/loader/Parser.js b/src/loader/Parser.js index 1ef50442..a402ad51 100644 --- a/src/loader/Parser.js +++ b/src/loader/Parser.js @@ -1,8 +1,21 @@ +/** +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} +* @module Phaser.Parser +*/ + + +/** +* Description of Phaser.Loader.Parser +* +* @class Phaser.Loader.Parser +*/ Phaser.Loader.Parser = { /** * Parse frame data from an XML file. - * @param xml {object} XML data you want to parse. + * @param {object} xml - XML data you want to parse. * @return {FrameData} Generated FrameData object. */ bitmapFont: function (game, xml, cacheKey) { diff --git a/src/math/Math.js b/src/math/Math.js index d9f46edc..20913191 100644 --- a/src/math/Math.js +++ b/src/math/Math.js @@ -1,32 +1,88 @@ +/** +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} +* @module Phaser.Math +*/ + +/** +* A collection of mathematical methods. +* +* @class Phaser.Math +*/ Phaser.Math = { + /** + * = 2 π + * @method PI2 + * + */ PI2: Math.PI * 2, + /** + * Two number are fuzzyEqual if their difference is less than ε. + * @method fuzzyEqual + * @param {number} a + * @param {number} b + * @param {number} epsilon + * @return {bool} True if |a-b|<ε + */ fuzzyEqual: function (a, b, epsilon) { if (typeof epsilon === "undefined") { epsilon = 0.0001; } return Math.abs(a - b) < epsilon; }, + /** + * a is fuzzyLessThan b if it is less than b + ε. + * @method fuzzyEqual + * @param {number} a + * @param {number} b + * @param {number} epsilon + * @return {bool} True if ab+ε + */ fuzzyGreaterThan: function (a, b, epsilon) { if (typeof epsilon === "undefined") { epsilon = 0.0001; } return a > b - epsilon; }, + /** + * @method fuzzyCeil + * @param {number} val + * @param {number} epsilon + * @return {bool} ceiling(val-ε) + */ fuzzyCeil: function (val, epsilon) { if (typeof epsilon === "undefined") { epsilon = 0.0001; } return Math.ceil(val - epsilon); }, + /** + * @method fuzzyFloor + * @param {number} val + * @param {number} epsilon + * @return {bool} floor(val-ε) + */ fuzzyFloor: function (val, epsilon) { if (typeof epsilon === "undefined") { epsilon = 0.0001; } return Math.floor(val + epsilon); }, + /** + * @method average + */ average: function () { var args = []; @@ -45,10 +101,18 @@ Phaser.Math = { }, + /** + * @method truncate + */ truncate: function (n) { return (n > 0) ? Math.floor(n) : Math.ceil(n); }, + /** + * @method shear + * @param n + * @return n mod 1 + */ shear: function (n) { return n % 1; }, @@ -56,11 +120,12 @@ Phaser.Math = { /** * Snap a value to nearest grid slice, using rounding. * - * example if you have an interval gap of 5 and a position of 12... you will snap to 10. Where as 14 will snap to 15 + * Example: if you have an interval gap of 5 and a position of 12... you will snap to 10 whereas 14 will snap to 15. * - * @param input - the value to snap - * @param gap - the interval gap of the grid - * @param [start] - optional starting offset for gap + * @method snapTo + * @param {number} input - The value to snap. + * @param {number} gap - The interval gap of the grid. + * @param {number} [start] - Optional starting offset for gap. */ snapTo: function (input, gap, start) { @@ -80,11 +145,12 @@ Phaser.Math = { /** * Snap a value to nearest grid slice, using floor. * - * example if you have an interval gap of 5 and a position of 12... you will snap to 10. As will 14 snap to 10... but 16 will snap to 15 + * Example: if you have an interval gap of 5 and a position of 12... you will snap to 10. As will 14 snap to 10... but 16 will snap to 15 * - * @param input - the value to snap - * @param gap - the interval gap of the grid - * @param [start] - optional starting offset for gap + * @method snapToFloor + * @param {number} input - The value to snap. + * @param {number} gap - The interval gap of the grid. + * @param {number} [start] - Optional starting offset for gap. */ snapToFloor: function (input, gap, start) { @@ -104,11 +170,12 @@ Phaser.Math = { /** * Snap a value to nearest grid slice, using ceil. * - * example if you have an interval gap of 5 and a position of 12... you will snap to 15. As will 14 will snap to 15... but 16 will snap to 20 + * Example: if you have an interval gap of 5 and a position of 12... you will snap to 15. As will 14 will snap to 15... but 16 will snap to 20. * - * @param input - the value to snap - * @param gap - the interval gap of the grid - * @param [start] - optional starting offset for gap + * @method snapToCeil + * @param {number} input - The value to snap. + * @param {number} gap - The interval gap of the grid. + * @param {number} [start] - Optional starting offset for gap. */ snapToCeil: function (input, gap, start) { @@ -128,6 +195,10 @@ Phaser.Math = { /** * Snaps a value to the nearest value in an array. + * @method + * @param {number} input + * @param {array} arr + * @param {bool} sort - True if the array needs to be sorted. */ snapToInArray: function (input, arr, sort) { @@ -155,16 +226,10 @@ Phaser.Math = { }, /** - * roundTo some place comparative to a 'base', default is 10 for decimal place + * Round to some place comparative to a 'base', default is 10 for decimal place. * * 'place' is represented by the power applied to 'base' to get that place - * - * @param value - the value to round - * @param place - the place to round to - * @param base - the base to round in... default is 10 for decimal - * * e.g. - * * 2000/7 ~= 285.714285714285714285714 ~= (bin)100011101.1011011011011011 * * roundTo(2000/7,3) == 0 @@ -187,8 +252,13 @@ Phaser.Math = { * roundTo(2000/7,-4,2) == 285.6875 -- 100011101.1011 * roundTo(2000/7,-5,2) == 285.71875 -- 100011101.10111 * - * note what occurs when we round to the 3rd space (8ths place), 100100000, this is to be assumed + * Note what occurs when we round to the 3rd space (8ths place), 100100000, this is to be assumed * because we are rounding 100011.1011011011011011 which rounds up. + * + * @method roundTo + * @param {number} value - The value to round. + * @param {number} place - The place to round to. + * @param {number} base - The base to round in... default is 10 for decimal. */ roundTo: function (value, place, base) { @@ -201,6 +271,12 @@ Phaser.Math = { }, + /** + * @method floorTo + * @param {number} value - The value to round. + * @param {number} place - The place to round to. + * @param {number} base - The base to round in... default is 10 for decimal. + */ floorTo: function (value, place, base) { if (typeof place === "undefined") { place = 0; } @@ -212,6 +288,12 @@ Phaser.Math = { }, + /** + * @method ceilTo + * @param {number} value - The value to round. + * @param {number} place - The place to round to. + * @param {number} base - The base to round in... default is 10 for decimal. + */ ceilTo: function (value, place, base) { if (typeof place === "undefined") { place = 0; } @@ -224,34 +306,50 @@ Phaser.Math = { }, /** - * a one dimensional linear interpolation of a value. + * A one dimensional linear interpolation of a value. + * @method interpolateFloat + * @param {number} a + * @param {number} b + * @param {number} weight */ interpolateFloat: function (a, b, weight) { return (b - a) * weight + a; }, /** - * Find the angle of a segment from (x1, y1) -> (x2, y2 ) + * Find the angle of a segment from (x1, y1) -> (x2, y2 ). + * @method angleBetween + * @param {number} x1 + * @param {number} y1 + * @param {number} x2 + * @param {number} y2 */ angleBetween: function (x1, y1, x2, y2) { return Math.atan2(y2 - y1, x2 - x1); }, /** - * set an angle within the bounds of -PI to PI + * Set an angle within the bounds of -π toπ. + * @method normalizeAngle + * @param {number} angle + * @param {bool} radians - True if angle size is expressed in radians. */ normalizeAngle: function (angle, radians) { if (typeof radians === "undefined") { radians = true; } - var rd = (radians) ? Math.PI : 180; - return this.wrap(angle, -rd, rd); + var rd = (radians) ? GameMath.PI : 180; + return this.wrap(angle, rd, -rd); }, /** - * closest angle between two angles from a1 to a2 + * Closest angle between two angles from a1 to a2 * absolute value the return for exact angle + * @method nearestAngleBetween + * @param {number} a1 + * @param {number} a2 + * @param {bool} radians - True if angle sizes are expressed in radians. */ nearestAngleBetween: function (a1, a2, radians) { @@ -276,7 +374,13 @@ Phaser.Math = { }, /** - * interpolate across the shortest arc between two angles + * Interpolate across the shortest arc between two angles. + * @method interpolateAngles + * @param {number} a1 - Description. + * @param {number} a2 - Description. + * @param {number} weight - Description. + * @param {bool} radians - True if angle sizes are expressed in radians. + * @param {Description} ease - Description. */ interpolateAngles: function (a1, a2, weight, radians, ease) { @@ -291,13 +395,14 @@ Phaser.Math = { }, /** - * Generate a random bool result based on the chance value + * Generate a random bool result based on the chance value. *

* Returns true or false based on the chance value (default 50%). For example if you wanted a player to have a 30% chance * of getting a bonus, call chanceRoll(30) - true means the chance passed, false means it failed. *

- * @param chance The chance of receiving the value. A number between 0 and 100 (effectively 0% to 100%) - * @return true if the roll passed, or false + * @method chanceRoll + * @param {number} chance - The chance of receiving the value. A number between 0 and 100 (effectively 0% to 100%). + * @return {bool} True if the roll passed, or false otherwise. */ chanceRoll: function (chance) { @@ -326,11 +431,12 @@ Phaser.Math = { }, /** - * Returns an Array containing the numbers from min to max (inclusive) + * Returns an Array containing the numbers from min to max (inclusive). * - * @param min The minimum value the array starts with - * @param max The maximum value the array contains - * @return The array of number values + * @method numberArray + * @param {number} min - The minimum value the array starts with. + * @param {number} max - The maximum value the array contains. + * @return {array} The array of number values. */ numberArray: function (min, max) { @@ -346,12 +452,13 @@ Phaser.Math = { }, /** - * Adds the given amount to the value, but never lets the value go over the specified maximum + * Adds the given amount to the value, but never lets the value go over the specified maximum. * - * @param value The value to add the amount to - * @param amount The amount to add to the value - * @param max The maximum the value is allowed to be - * @return The new value + * @method maxAdd + * @param {number} value - The value to add the amount to. + * @param {number} amount - The amount to add to the value. + * @param {number} max- The maximum the value is allowed to be. + * @return The new value. */ maxAdd: function (value, amount, max) { @@ -367,12 +474,13 @@ Phaser.Math = { }, /** - * Subtracts the given amount from the value, but never lets the value go below the specified minimum + * Subtracts the given amount from the value, but never lets the value go below the specified minimum. * - * @param value The base value - * @param amount The amount to subtract from the base value - * @param min The minimum the value is allowed to be - * @return The new value + * @method minSub + * @param {number} value - The base value. + * @param {number} amount - The amount to subtract from the base value. + * @param {number} min - The minimum the value is allowed to be. + * @return {number} The new value. */ minSub: function (value, amount, min) { @@ -415,10 +523,12 @@ Phaser.Math = { * Adds value to amount and ensures that the result always stays between 0 and max, by wrapping the value around. *

Values must be positive integers, and are passed through Math.abs

* - * @param value The value to add the amount to - * @param amount The amount to add to the value - * @param max The maximum the value is allowed to be - * @return The wrapped value + * @method wrapValue + * @param {number} value - The value to add the amount to. + * @param {number} amount - The amount to add to the value. + * @param {number} max - The maximum the value is allowed to be. + * @return {number} The wrapped value. + */ wrapValue: function (value, amount, max) { @@ -433,9 +543,10 @@ Phaser.Math = { }, /** - * Randomly returns either a 1 or -1 + * Randomly returns either a 1 or -1. * - * @return 1 or -1 + * @method randomSign + * @return {number} 1 or -1 */ randomSign: function () { return (Math.random() > 0.5) ? 1 : -1; @@ -444,9 +555,9 @@ Phaser.Math = { /** * Returns true if the number given is odd. * - * @param n The number to check - * - * @return True if the given number is odd. False if the given number is even. + * @method isOdd + * @param {number} n - The number to check. + * @return {bool} True if the given number is odd. False if the given number is even. */ isOdd: function (n) { @@ -457,9 +568,9 @@ Phaser.Math = { /** * Returns true if the number given is even. * - * @param n The number to check - * - * @return True if the given number is even. False if the given number is odd. + * @method isEven + * @param {number} n - The number to check. + * @return {bool} True if the given number is even. False if the given number is odd. */ isEven: function (n) { @@ -476,8 +587,9 @@ Phaser.Math = { /** * Significantly faster version of Math.max - * See http://jsperf.com/math-s-min-max-vs-homemade/5 + * See {@link http://jsperf.com/math-s-min-max-vs-homemade/5} * + * @method max * @return The highest value from those given. */ max: function () { @@ -496,8 +608,9 @@ Phaser.Math = { /** * Significantly faster version of Math.min - * See http://jsperf.com/math-s-min-max-vs-homemade/5 + * See {@link http://jsperf.com/math-s-min-max-vs-homemade/5} * + * @method min * @return The lowest value from those given. */ min: function () { @@ -518,9 +631,9 @@ Phaser.Math = { * Keeps an angle value between -180 and +180
* Should be called whenever the angle is updated on the Sprite to stop it from going insane. * - * @param angle The angle value to check - * - * @return The new angle value, returns the same as the input angle if it was within bounds + * @method wrapAngle + * @param {number} angle - The angle value to check + * @return {number} The new angle value, returns the same as the input angle if it was within bounds. */ wrapAngle: function (angle) { @@ -545,13 +658,14 @@ Phaser.Math = { }, /** - * Keeps an angle value between the given min and max values + * Keeps an angle value between the given min and max values. * - * @param angle The angle value to check. Must be between -180 and +180 - * @param min The minimum angle that is allowed (must be -180 or greater) - * @param max The maximum angle that is allowed (must be 180 or less) + * @method angleLimit + * @param {number} angle - The angle value to check. Must be between -180 and +180. + * @param {number} min - The minimum angle that is allowed (must be -180 or greater). + * @param {number} max - The maximum angle that is allowed (must be 180 or less). * - * @return The new angle value, returns the same as the input angle if it was within bounds + * @return {number} The new angle value, returns the same as the input angle if it was within bounds */ angleLimit: function (angle, min, max) { var result = angle; @@ -564,10 +678,11 @@ Phaser.Math = { }, /** + * Description. * @method linearInterpolation - * @param {Any} v - * @param {Any} k - * @public + * @param {number} v + * @param {number} k + * @return {number} */ linearInterpolation: function (v, k) { var m = v.length - 1; @@ -583,10 +698,11 @@ Phaser.Math = { }, /** + * Description. * @method bezierInterpolation - * @param {Any} v - * @param {Any} k - * @public + * @param {number} v + * @param {number} k + * @return {number} */ bezierInterpolation: function (v, k) { var b = 0; @@ -598,10 +714,11 @@ Phaser.Math = { }, /** + * Description. * @method catmullRomInterpolation - * @param {Any} v - * @param {Any} k - * @public + * @param {number} v + * @param {number} k + * @return {number} */ catmullRomInterpolation: function (v, k) { @@ -626,11 +743,12 @@ Phaser.Math = { }, /** + * Description. * @method Linear - * @param {Any} p0 - * @param {Any} p1 - * @param {Any} t - * @public + * @param {number} p0 + * @param {number} p1 + * @param {number} t + * @return {number} */ linear: function (p0, p1, t) { return (p1 - p0) * t + p0; @@ -638,22 +756,23 @@ Phaser.Math = { /** * @method bernstein - * @param {Any} n - * @param {Any} i - * @public + * @param {number} n + * @param {number} i + * @return {number} */ bernstein: function (n, i) { return this.factorial(n) / this.factorial(i) / this.factorial(n - i); }, /** + * Description. * @method catmullRom - * @param {Any} p0 - * @param {Any} p1 - * @param {Any} p2 - * @param {Any} p3 - * @param {Any} t - * @public + * @param {number} p0 + * @param {number} p1 + * @param {number} p2 + * @param {number} p3 + * @param {number} t + * @return {number} */ catmullRom: function (p0, p1, p2, p3, t) { var v0 = (p2 - p0) * 0.5, v1 = (p3 - p1) * 0.5, t2 = t * t, t3 = t * t2; @@ -668,10 +787,10 @@ Phaser.Math = { * Fetch a random entry from the given array. * Will return null if random selection is missing, or array has no entries. * + * @method getRandom * @param objects An array of objects. * @param startIndex Optional offset off the front of the array. Default value is 0, or the beginning of the array. * @param length Optional restriction on the number of values you want to randomly select from. - * * @return The random object that was selected. */ getRandom: function (objects, startIndex, length) { @@ -701,9 +820,9 @@ Phaser.Math = { /** * Round down to the next whole number. E.g. floor(1.7) == 1, and floor(-2.7) == -2. * - * @param Value Any number. - * - * @return The rounded value of that number. + * @method floor + * @param {number} Value Any number. + * @return {number} The rounded value of that number. */ floor: function (value) { @@ -802,12 +921,13 @@ Phaser.Math = { /** * Returns the distance between the two given set of coordinates. + * * @method distance - * @param {Number} x1 - * @param {Number} y1 - * @param {Number} x2 - * @param {Number} y2 - * @return {Number} The distance between this Point object and the destination Point object. + * @param {number} x1 + * @param {number} y1 + * @param {number} x2 + * @param {number} y2 + * @return {number} The distance between this Point object and the destination Point object. **/ distance: function (x1, y1, x2, y2) { @@ -825,34 +945,61 @@ Phaser.Math = { }, /** - * force a value within the boundaries of two values - * + * Force a value within the boundaries of two values. * Clamp value to range + * + * @method clamp + * @param {number} x + * @param {number} a + * @param {number} b */ clamp: function ( x, a, b ) { return ( x < a ) ? a : ( ( x > b ) ? b : x ); }, - - // Clamp value to range to range - + + /** + * Linear mapping from range to range + * + * @method mapLinear + * @param {number} x + * @param {number} a1 + * @param {number} a1 + * @param {number} a2 + * @param {number} b1 + * @param {number} b2 + * @return {number} + */ mapLinear: function ( x, a1, a2, b1, b2 ) { return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 ); }, - // http://en.wikipedia.org/wiki/Smoothstep - + // + /** + * {@link http://en.wikipedia.org/wiki/Smoothstep} + * + * @method smoothstep + * @param {number} x + * @param {number} min + * @param {number} max + * @return {number} + */ smoothstep: function ( x, min, max ) { if ( x <= min ) return 0; @@ -864,6 +1011,15 @@ Phaser.Math = { }, + /** + * {@link http://en.wikipedia.org/wiki/Smoothstep} + * + * @method smootherstep + * @param {number} x + * @param {number} min + * @param {number} max + * @return {number} + */ smootherstep: function ( x, min, max ) { if ( x <= min ) return 0; @@ -876,8 +1032,12 @@ Phaser.Math = { }, /** - * a value representing the sign of the value. + * A value representing the sign of the value. * -1 for negative, +1 for positive, 0 if value is 0 + * + * @method sign + * @param {number} x + * @return {number} */ sign: function ( x ) { @@ -885,6 +1045,12 @@ Phaser.Math = { }, + /** + * Convert degrees to radians. + * + * @method degToRad + * @return {function} + */ degToRad: function() { var degreeToRadiansFactor = Math.PI / 180; @@ -897,6 +1063,12 @@ Phaser.Math = { }(), + /** + * Convert degrees to radians. + * + * @method radToDeg + * @return {function} + */ radToDeg: function() { var radianToDegreesFactor = 180 / Math.PI; diff --git a/src/math/QuadTree.js b/src/math/QuadTree.js index 0c6e317c..ded11e42 100644 --- a/src/math/QuadTree.js +++ b/src/math/QuadTree.js @@ -1,4 +1,11 @@ -/* +/** +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} +* @module Phaser.Quadtree +*/ + +/** * Javascript QuadTree * @version 1.0 * @author Timo Hausmann @@ -12,35 +19,49 @@ * Original version at https://github.com/timohausmann/quadtree-js/ */ -/* - Copyright © 2012 Timo Hausmann - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +/** +* @overview +* @copyright © 2012 Timo Hausmann +* +* Permission is hereby granted, free of charge, to any person obtaining +* a copy of this software and associated documentation files (the +* "Software"), to deal in the Software without restriction, including +* without limitation the rights to use, copy, modify, merge, publish, +* distribute, sublicense, and/or sell copies of the Software, and to +* permit persons to whom the Software is furnished to do so, subject to +* the following conditions: +* +* The above copyright notice and this permission notice shall be +* included in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/* -* QuadTree Constructor -* @param Integer maxObjects (optional) max objects a node can hold before splitting into 4 subnodes (default: 10) -* @param Integer maxLevels (optional) total max levels inside root QuadTree (default: 4) -* @param Integer level (optional) deepth level, required for subnodes -*/ +/** + * QuadTree Constructor + * + * @class Phaser.QuadTree + * @classdesc Javascript QuadTree

+ * The original code was a conversion of the Java code posted to GameDevTuts. However I've tweaked + * it massively to add node indexing, removed lots of temp. var creation and significantly + * increased performance as a result.

+ * Original version at {@link https://github.com/timohausmann/quadtree-js/} + * @constructor + * @param {Description} physicsManager - Description. + * @param {Description} x - Description. + * @param {Description} y - Description. + * @param {number} width - The width of your game in game pixels. + * @param {number} height - The height of your game in game pixels. + * @param {number} maxObjects - Description. + * @param {number} maxLevels - Description. + * @param {number} level - Description. + */ Phaser.QuadTree = function (physicsManager, x, y, width, height, maxObjects, maxLevels, level) { this.physicsManager = physicsManager; @@ -70,8 +91,10 @@ Phaser.QuadTree = function (physicsManager, x, y, width, height, maxObjects, max Phaser.QuadTree.prototype = { /* - * Split the node into 4 subnodes - */ + * Split the node into 4 subnodes + * + * @method split + */ split: function() { this.level++; @@ -94,7 +117,9 @@ Phaser.QuadTree.prototype = { * Insert the object into the node. If the node * exceeds the capacity, it will split and add all * objects to their corresponding subnodes. - * @param Object pRect bounds of the object to be added, with x, y, width, height + * + * @method insert + * @param {object} body - Description. */ insert: function (body) { @@ -142,9 +167,11 @@ Phaser.QuadTree.prototype = { }, /* - * Determine which node the object belongs to - * @param Object pRect bounds of the area to be checked, with x, y, width, height - * @return Integer index of the subnode (0-3), or -1 if pRect cannot completely fit within a subnode and is part of the parent node + * Determine which node the object belongs to. + * + * @method getIndex + * @param {object} rect - Description. + * @return {number} index - Index of the subnode (0-3), or -1 if rect cannot completely fit within a subnode and is part of the parent node. */ getIndex: function (rect) { @@ -184,9 +211,11 @@ Phaser.QuadTree.prototype = { }, /* - * Return all objects that could collide with the given object - * @param Object pRect bounds of the object to be checked, with x, y, width, height - * @Return Array array with all detected objects + * Return all objects that could collide with the given object. + * + * @method retrieve + * @param {object} rect - Description. + * @Return {array} - Array with all detected objects. */ retrieve: function (sprite) { @@ -219,7 +248,8 @@ Phaser.QuadTree.prototype = { }, /* - * Clear the quadtree + * Clear the quadtree. + * @method clear */ clear: function () { diff --git a/src/math/RandomDataGenerator.js b/src/math/RandomDataGenerator.js index c34ba800..9f3c7d32 100644 --- a/src/math/RandomDataGenerator.js +++ b/src/math/RandomDataGenerator.js @@ -1,9 +1,21 @@ /** -* Phaser.RandomDataGenerator -* -* An extremely useful repeatable random data generator. Access it via Phaser.Game.rnd -* Based on Nonsense by Josh Faul https://github.com/jocafa/Nonsense -* Random number generator from http://baagoe.org/en/wiki/Better_random_numbers_for_javascript +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} +* @module Phaser.RandomDataGenerator +*/ + + +/** +* Phaser.RandomDataGenerator constructor. +* +* @class Phaser.RandomDataGenerator +* @classdesc An extremely useful repeatable random data generator. Access it via Phaser.Game.rnd +* Based on Nonsense by Josh Faul {@link https://github.com/jocafa/Nonsense}. +* Random number generator from {@link http://baagoe.org/en/wiki/Better_random_numbers_for_javascript} +* +* @constructor +* @param {array} seeds */ Phaser.RandomDataGenerator = function (seeds) { @@ -16,37 +28,34 @@ Phaser.RandomDataGenerator = function (seeds) { Phaser.RandomDataGenerator.prototype = { /** - * @property c - * @type Number + * @property {number} c * @private */ c: 1, /** - * @property s0 - * @type Number + * @property {number} s0 * @private */ s0: 0, /** - * @property s1 - * @type Number + * @property {number} s1 * @private */ s1: 0, /** - * @property s2 - * @type Number + * @property {number} s2 * @private */ s2: 0, /** - * Private random helper + * Private random helper. * @method rnd * @private + * @return {number} Description. */ rnd: function () { @@ -61,9 +70,10 @@ Phaser.RandomDataGenerator.prototype = { }, /** - * Reset the seed of the random data generator + * Reset the seed of the random data generator. + * * @method sow - * @param {Array} seeds + * @param {array} seeds */ sow: function (seeds) { @@ -87,9 +97,11 @@ Phaser.RandomDataGenerator.prototype = { }, /** + * Description. * @method hash * @param {Any} data * @private + * @return {number} Description. */ hash: function (data) { @@ -113,49 +125,49 @@ Phaser.RandomDataGenerator.prototype = { }, /** - * Returns a random integer between 0 and 2^32 + * Returns a random integer between 0 and 2^32. * @method integer - * @return {Number} + * @return {number} */ integer: function() { return this.rnd.apply(this) * 0x100000000;// 2^32 }, /** - * Returns a random real number between 0 and 1 + * Returns a random real number between 0 and 1. * @method frac - * @return {Number} + * @return {number} */ frac: function() { return this.rnd.apply(this) + (this.rnd.apply(this) * 0x200000 | 0) * 1.1102230246251565e-16;// 2^-53 }, /** - * Returns a random real number between 0 and 2^32 + * Returns a random real number between 0 and 2^32. * @method real - * @return {Number} + * @return {number} */ real: function() { return this.integer() + this.frac(); }, /** - * Returns a random integer between min and max + * Returns a random integer between min and max. * @method integerInRange - * @param {Number} min - * @param {Number} max - * @return {Number} + * @param {number} min + * @param {number} max + * @return {number} */ integerInRange: function (min, max) { return Math.floor(this.realInRange(min, max)); }, /** - * Returns a random real number between min and max + * Returns a random real number between min and max. * @method realInRange - * @param {Number} min - * @param {Number} max - * @return {Number} + * @param {number} min + * @param {number} max + * @return {number} */ realInRange: function (min, max) { @@ -167,18 +179,18 @@ Phaser.RandomDataGenerator.prototype = { }, /** - * Returns a random real number between -1 and 1 + * Returns a random real number between -1 and 1. * @method normal - * @return {Number} + * @return {number} */ normal: function () { return 1 - 2 * this.frac(); }, /** - * Returns a valid RFC4122 version4 ID hex string (from https://gist.github.com/1308368) + * Returns a valid RFC4122 version4 ID hex string (from {@link https://gist.github.com/1308368}). * @method uuid - * @return {String} + * @return {string} */ uuid: function () { @@ -195,36 +207,40 @@ Phaser.RandomDataGenerator.prototype = { }, /** - * Returns a random member of `array` + * Returns a random member of `array`. * @method pick - * @param {Any} array + * @param {Any} ary + * @return {number} */ pick: function (ary) { return ary[this.integerInRange(0, ary.length)]; }, /** - * Returns a random member of `array`, favoring the earlier entries + * Returns a random member of `array`, favoring the earlier entries. * @method weightedPick - * @param {Any} array + * @param {Any} ary + * @return {number} */ weightedPick: function (ary) { return ary[~~(Math.pow(this.frac(), 2) * ary.length)]; }, /** - * Returns a random timestamp between min and max, or between the beginning of 2000 and the end of 2020 if min and max aren't specified + * Returns a random timestamp between min and max, or between the beginning of 2000 and the end of 2020 if min and max aren't specified. * @method timestamp - * @param {Number} min - * @param {Number} max + * @param {number} min + * @param {number} max + * @return {number} */ timestamp: function (a, b) { return this.realInRange(a || 946684800000, b || 1577862000000); }, /** - * Returns a random angle between -180 and 180 + * Returns a random angle between -180 and 180. * @method angle + * @return {number} */ angle: function() { return this.integerInRange(-180, 180); diff --git a/src/net/Net.js b/src/net/Net.js index 0e6e7c60..d23bf0f7 100644 --- a/src/net/Net.js +++ b/src/net/Net.js @@ -1,3 +1,17 @@ +/** +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} +* @module Phaser.Net +*/ + +/** +* Description of Phaser.Net +* +* @class Phaser.Net +* @constructor +* @param {Phaser.Game} game - A reference to the currently running game. +*/ Phaser.Net = function (game) { this.game = game; @@ -8,6 +22,9 @@ Phaser.Net.prototype = { /** * Returns the hostname given by the browser. + * + * @method getHostName + * @return {string} */ getHostName: function () { @@ -24,6 +41,10 @@ Phaser.Net.prototype = { * If the domain name is found it returns true. * You can specify a part of a domain, for example 'google' would match 'google.com', 'google.co.uk', etc. * Do not include 'http://' at the start. + * + * @method checkDomainName + * @param {string} domain + * @return {string} */ checkDomainName: function (domain) { return window.location.hostname.indexOf(domain) !== -1; @@ -34,6 +55,13 @@ Phaser.Net.prototype = { * If the value doesn't already exist it is set. * If the value exists it is replaced with the new value given. If you don't provide a new value it is removed from the query string. * Optionally you can redirect to the new url, or just return it as a string. + * + * @method updateQueryString + * @param {Description} key - Description. + * @param {Description} value - Description. + * @param {Description} redirect - Description. + * @param {Description} url - Description. + * @return {Description} Description. */ updateQueryString: function (key, value, redirect, url) { @@ -93,6 +121,10 @@ Phaser.Net.prototype = { /** * Returns the Query String as an object. * If you specify a parameter it will return just the value of that parameter, should it exist. + * + * @method getQueryString + * @param {string} parameter - Description. + * @return {Description} Description. */ getQueryString: function (parameter) { @@ -122,6 +154,14 @@ Phaser.Net.prototype = { }, + /** + * Returns the Query String as an object. + * If you specify a parameter it will return just the value of that parameter, should it exist. + * + * @method decodeURI + * @param {string} value - Description. + * @return {string} Description. + */ decodeURI: function (value) { return decodeURIComponent(value.replace(/\+/g, " ")); } diff --git a/src/particles/Particles.js b/src/particles/Particles.js index 1e1d0cd0..cb2a6f16 100644 --- a/src/particles/Particles.js +++ b/src/particles/Particles.js @@ -1,15 +1,47 @@ +/** +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} +* @module Phaser.Particles +*/ + + +/** +* Phaser.Particles constructor +* @class Phaser.Particles +* @classdesc Phaser Particles +* @constructor +* @param {Phaser.Game} game - A reference to the currently running game. +*/ Phaser.Particles = function (game) { + /** + * @property {Description} emitters - Description. + */ this.emitters = {}; + /** + * @property {number} ID - Description. + * @default + */ this.ID = 0; }; Phaser.Particles.prototype = { + /** + * Description. + * @method emitters + */ emitters: null, + /** + * Description. + * @method add + * @param {Description} emitter - Description. + * @return {Description} Description. + */ add: function (emitter) { this.emitters[emitter.name] = emitter; @@ -18,12 +50,22 @@ Phaser.Particles.prototype = { }, + /** + * Description. + * @method remove + * @param {Description} emitter - Description. + */ remove: function (emitter) { delete this.emitters[emitter.name]; }, + /** + * Description. + * @method update + * @param {Description} emitter - Description. + */ update: function () { for (var key in this.emitters) diff --git a/src/particles/arcade/Emitter.js b/src/particles/arcade/Emitter.js index c3fb007c..207c56c3 100644 --- a/src/particles/arcade/Emitter.js +++ b/src/particles/arcade/Emitter.js @@ -1,145 +1,210 @@ +/** +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} +* @module Phaser.Emitter +*/ + /** * Phaser - ArcadeEmitter * -* Emitter is a lightweight particle emitter. It can be used for one-time explosions or for +* @class Phaser.Particles.Arcade.Emitter +* @classdesc Emitter is a lightweight particle emitter. It can be used for one-time explosions or for * continuous effects like rain and fire. All it really does is launch Particle objects out * at set intervals, and fixes their positions and velocities accorindgly. +* @constructor +* @param {Phaser.Game} game - Current game instance. +* @param {number} x - Description. +* @param {number} y - Description. +* @param {number} maxParticles - Description. */ Phaser.Particles.Arcade.Emitter = function (game, x, y, maxParticles) { + /** + * @property {number} maxParticles - Description. + * @default + */ maxParticles = maxParticles || 50; Phaser.Group.call(this, game); + /** + * @property {string} name - Description. + */ this.name = 'emitter' + this.game.particles.ID++; + /** + * @property {Description} type - Description. + */ this.type = Phaser.EMITTER; /** - * The X position of the top left corner of the emitter in world space. + * @property {number} x - The X position of the top left corner of the emitter in world space. + * @default */ this.x = 0; /** - * The Y position of the top left corner of emitter in world space. + * @property {number} y - The Y position of the top left corner of emitter in world space. + * @default */ this.y = 0; /** - * The width of the emitter. Particles can be randomly generated from anywhere within this box. + * @property {number} width - The width of the emitter. Particles can be randomly generated from anywhere within this box. + * @default */ this.width = 1; /** - * The height of the emitter. Particles can be randomly generated from anywhere within this box. - */ + * @property {number} height - The height of the emitter. Particles can be randomly generated from anywhere within this box. + * @default + */ this.height = 1; /** - * The minimum possible velocity of a particle. - * The default value is (-100,-100). - */ + * The minimum possible velocity of a particle. + * The default value is (-100,-100). + * @property {Phaser.Point} minParticleSpeed + */ this.minParticleSpeed = new Phaser.Point(-100, -100); /** - * The maximum possible velocity of a particle. - * The default value is (100,100). - */ + * The maximum possible velocity of a particle. + * The default value is (100,100). + * @property {Phaser.Point} maxParticleSpeed + */ this.maxParticleSpeed = new Phaser.Point(100, 100); /** - * The minimum possible scale of a particle. - * The default value is 1. - */ + * The minimum possible scale of a particle. + * The default value is 1. + * @property {number} minParticleScale + * @default + */ this.minParticleScale = 1; /** * The maximum possible scale of a particle. * The default value is 1. + * @property {number} maxParticleScale + * @default */ this.maxParticleScale = 1; /** * The minimum possible angular velocity of a particle. The default value is -360. + * @property {number} minRotation + * @default */ this.minRotation = -360; /** * The maximum possible angular velocity of a particle. The default value is 360. + * @property {number} maxRotation + * @default */ this.maxRotation = 360; /** * Sets the gravity.y of each particle to this value on launch. + * @property {number} gravity + * @default */ this.gravity = 2; /** * Set your own particle class type here. - * Default is Particle. + * @property {Description} particleClass + * @default */ this.particleClass = null; /** * The X and Y drag component of particles launched from the emitter. + * @property {Phaser.Point} particleDrag */ this.particleDrag = new Phaser.Point(); /** * The angular drag component of particles launched from the emitter if they are rotating. + * @property {number} angularDrag + * @default */ this.angularDrag = 0; /** * How often a particle is emitted in ms (if emitter is started with Explode == false). + * @property {bool} frequency + * @default */ this.frequency = 100; /** * The total number of particles in this emitter. + * @property {number} maxParticles */ this.maxParticles = maxParticles; /** * How long each particle lives once it is emitted in ms. Default is 2 seconds. * Set lifespan to 'zero' for particles to live forever. + * @property {number} lifespan + * @default */ this.lifespan = 2000; /** * How much each particle should bounce on each axis. 1 = full bounce, 0 = no bounce. + * @property {Phaser.Point} bounce */ this.bounce = new Phaser.Point(); /** * Internal helper for deciding how many particles to launch. + * @property {number} _quantity + * @private + * @default */ this._quantity = 0; /** * Internal helper for deciding when to launch particles or kill them. + * @property {number} _timer + * @private + * @default */ this._timer = 0; /** * Internal counter for figuring out how many particles to launch. + * @property {number} _counter + * @private + * @default */ this._counter = 0; /** * Internal helper for the style of particle emission (all at once, or one at a time). + * @property {bool} _explode + * @private + * @default */ this._explode = true; /** * Determines whether the emitter is currently emitting particles. * It is totally safe to directly toggle this. + * @property {bool} on + * @default */ this.on = false; /** * Determines whether the emitter is being updated by the core game loop. + * @property {bool} exists + * @default */ this.exists = true; @@ -147,8 +212,16 @@ Phaser.Particles.Arcade.Emitter = function (game, x, y, maxParticles) { * The point the particles are emitted from. * Emitter.x and Emitter.y control the containers location, which updates all current particles * Emitter.emitX and Emitter.emitY control the emission location relative to the x/y position. + * @property {bool} emitX */ this.emitX = x; + + /** + * The point the particles are emitted from. + * Emitter.x and Emitter.y control the containers location, which updates all current particles + * Emitter.emitX and Emitter.emitY control the emission location relative to the x/y position. + * @property {bool} emitY + */ this.emitY = y; }; @@ -158,6 +231,7 @@ Phaser.Particles.Arcade.Emitter.prototype.constructor = Phaser.Particles.Arcade. /** * Called automatically by the game loop, decides when to launch particles and when to "die". + * @method Phaser.Particles.Arcade.Emitter.prototype.update */ Phaser.Particles.Arcade.Emitter.prototype.update = function () { @@ -202,12 +276,13 @@ Phaser.Particles.Arcade.Emitter.prototype.update = function () { /** * This function generates a new array of particle sprites to attach to the emitter. * - * @param graphics If you opted to not pre-configure an array of Sprite objects, you can simply pass in a particle image or sprite sheet. - * @param quantity {number} The number of particles to generate when using the "create from image" option. - * @param multiple {boolean} Whether the image in the Graphics param is a single particle or a bunch of particles (if it's a bunch, they need to be square!). - * @param collide {number} Whether the particles should be flagged as not 'dead' (non-colliding particles are higher performance). 0 means no collisions, 0-1 controls scale of particle's bounding box. - * - * @return This Emitter instance (nice for chaining stuff together, if you're into that). + * @method Phaser.Particles.Arcade.Emitter.prototype.makeParticles + * @param {Description} keys - Description. + * @param {number} frames - Description. + * @param {number} quantity - The number of particles to generate when using the "create from image" option. + * @param {number} collide - Description. + * @param {bool} collideWorldBounds - Description. + * @return This Emitter instance (nice for chaining stuff together, if you're into that). */ Phaser.Particles.Arcade.Emitter.prototype.makeParticles = function (keys, frames, quantity, collide, collideWorldBounds) { @@ -278,6 +353,7 @@ Phaser.Particles.Arcade.Emitter.prototype.makeParticles = function (keys, frames /** * Call this function to turn off all the particles and the emitter. + * @method Phaser.Particles.Arcade.Emitter.prototype.kill */ Phaser.Particles.Arcade.Emitter.prototype.kill = function () { @@ -290,6 +366,7 @@ Phaser.Particles.Arcade.Emitter.prototype.kill = function () { /** * Handy for bringing game objects "back to life". Just sets alive and exists back to true. * In practice, this is most often called by Object.reset(). + * @method Phaser.Particles.Arcade.Emitter.prototype.revive */ Phaser.Particles.Arcade.Emitter.prototype.revive = function () { @@ -300,11 +377,11 @@ Phaser.Particles.Arcade.Emitter.prototype.revive = function () { /** * Call this function to start emitting particles. - * - * @param explode {boolean} Whether the particles should all burst out at once. - * @param lifespan {number} How long each particle lives once emitted. 0 = forever. - * @param frequency {number} Ignored if Explode is set to true. Frequency is how often to emit a particle in ms. - * @param quantity {number} How many particles to launch. 0 = "all of the particles". + * @method Phaser.Particles.Arcade.Emitter.prototype.start + * @param {boolean} explode - Whether the particles should all burst out at once. + * @param {number} lifespan - How long each particle lives once emitted. 0 = forever. + * @param {number} frequency - Ignored if Explode is set to true. Frequency is how often to emit a particle in ms. + * @param {number} quantity - How many particles to launch. 0 = "all of the particles". */ Phaser.Particles.Arcade.Emitter.prototype.start = function (explode, lifespan, frequency, quantity) { @@ -346,6 +423,7 @@ Phaser.Particles.Arcade.Emitter.prototype.start = function (explode, lifespan, f /** * This function can be used both internally and externally to emit the next particle. + * @method Phaser.Particles.Arcade.Emitter.prototype.emitParticle */ Phaser.Particles.Arcade.Emitter.prototype.emitParticle = function () { @@ -412,9 +490,9 @@ Phaser.Particles.Arcade.Emitter.prototype.emitParticle = function () { /** * A more compact way of setting the width and height of the emitter. - * - * @param width {number} The desired width of the emitter (particles are spawned randomly within these dimensions). - * @param height {number} The desired height of the emitter. + * @method Phaser.Particles.Arcade.Emitter.prototype.setSize + * @param {number} width - The desired width of the emitter (particles are spawned randomly within these dimensions). + * @param {number} height - The desired height of the emitter. */ Phaser.Particles.Arcade.Emitter.prototype.setSize = function (width, height) { @@ -425,9 +503,9 @@ Phaser.Particles.Arcade.Emitter.prototype.setSize = function (width, height) { /** * A more compact way of setting the X velocity range of the emitter. - * - * @param Min {number} The minimum value for this range. - * @param Max {number} The maximum value for this range. + * @method Phaser.Particles.Arcade.Emitter.prototype.setXSpeed + * @param {number} min - The minimum value for this range. + * @param {number} max - The maximum value for this range. */ Phaser.Particles.Arcade.Emitter.prototype.setXSpeed = function (min, max) { @@ -441,9 +519,9 @@ Phaser.Particles.Arcade.Emitter.prototype.setXSpeed = function (min, max) { /** * A more compact way of setting the Y velocity range of the emitter. - * - * @param Min {number} The minimum value for this range. - * @param Max {number} The maximum value for this range. + * @method Phaser.Particles.Arcade.Emitter.prototype.setYSpeed + * @param {number} min - The minimum value for this range. + * @param {number} max - The maximum value for this range. */ Phaser.Particles.Arcade.Emitter.prototype.setYSpeed = function (min, max) { @@ -457,9 +535,9 @@ Phaser.Particles.Arcade.Emitter.prototype.setYSpeed = function (min, max) { /** * A more compact way of setting the angular velocity constraints of the emitter. - * - * @param Min {number} The minimum value for this range. - * @param Max {number} The maximum value for this range. + * @method Phaser.Particles.Arcade.Emitter.prototype.setRotation + * @param {number} min - The minimum value for this range. + * @param {number} max - The maximum value for this range. */ Phaser.Particles.Arcade.Emitter.prototype.setRotation = function (min, max) { @@ -473,8 +551,8 @@ Phaser.Particles.Arcade.Emitter.prototype.setRotation = function (min, max) { /** * Change the emitter's midpoint to match the midpoint of a Object. - * - * @param Object {object} The Object that you want to sync up with. + * @method Phaser.Particles.Arcade.Emitter.prototype.at + * @param {object} object - The Object that you want to sync up with. */ Phaser.Particles.Arcade.Emitter.prototype.at = function (object) { @@ -483,42 +561,51 @@ Phaser.Particles.Arcade.Emitter.prototype.at = function (object) { } +/** +* Get the emitter alpha. +* @return {Description} +*//** +* Set the emiter alpha value. +* @param {Description} value - Description +*/ Object.defineProperty(Phaser.Particles.Arcade.Emitter.prototype, "alpha", { - /** - * Get the emitter alpha. - */ get: function () { return this._container.alpha; }, - /** - * Set the emiter alpha value. - */ set: function (value) { this._container.alpha = value; } }); +/** +* Get the emitter visible state. +* @return {bool} +*//** +* Set the emitter visible state. +* @param {bool} value - Description +*/ Object.defineProperty(Phaser.Particles.Arcade.Emitter.prototype, "visible", { - /** - * Get the emitter visible state. - */ get: function () { return this._container.visible; }, - /** - * Set the emitter visible state. - */ set: function (value) { this._container.visible = value; } }); +/** +* Get +* @return {bool} +*//** +* Set +* @param {bool} value - Description +*/ Object.defineProperty(Phaser.Particles.Arcade.Emitter.prototype, "x", { get: function () { @@ -531,6 +618,13 @@ Object.defineProperty(Phaser.Particles.Arcade.Emitter.prototype, "x", { }); +/** +* Get +* @return {bool} +*//** +* Set +* @param {bool} value - Description +*/ Object.defineProperty(Phaser.Particles.Arcade.Emitter.prototype, "y", { get: function () { @@ -543,6 +637,10 @@ Object.defineProperty(Phaser.Particles.Arcade.Emitter.prototype, "y", { }); +/** +* Get +* @return {number} +*/ Object.defineProperty(Phaser.Particles.Arcade.Emitter.prototype, "left", { get: function () { @@ -551,6 +649,10 @@ Object.defineProperty(Phaser.Particles.Arcade.Emitter.prototype, "left", { }); +/** +* Get +* @return {number} +*/ Object.defineProperty(Phaser.Particles.Arcade.Emitter.prototype, "right", { get: function () { @@ -559,6 +661,10 @@ Object.defineProperty(Phaser.Particles.Arcade.Emitter.prototype, "right", { }); +/** +* Get +* @return {number} +*/ Object.defineProperty(Phaser.Particles.Arcade.Emitter.prototype, "top", { get: function () { @@ -567,6 +673,10 @@ Object.defineProperty(Phaser.Particles.Arcade.Emitter.prototype, "top", { }); +/** +* Get +* @return {number} +*/ Object.defineProperty(Phaser.Particles.Arcade.Emitter.prototype, "bottom", { get: function () { diff --git a/src/sound/Sound.js b/src/sound/Sound.js index 0445b7f6..a109093e 100644 --- a/src/sound/Sound.js +++ b/src/sound/Sound.js @@ -1,12 +1,21 @@ + /** -* The Sound class +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} +* @module Phaser.Sound +*/ + +/** +* The Sound class constructor. * -* @class Sound +* @class Phaser.Sound +* @classdesc The Sound class * @constructor -* @param {Phaser.Game} game Reference to the current game instance. -* @param {string} key Asset key for the sound. -* @param {number} volume Default value for the volume. -* @param {bool} loop Whether or not the sound will loop. +* @param {Phaser.Game} game - Reference to the current game instance. +* @param {string} key - Asset key for the sound. +* @param {number} volume - Default value for the volume. +* @param {bool} loop - Whether or not the sound will loop. */ Phaser.Sound = function (game, key, volume, loop) { @@ -15,101 +24,152 @@ Phaser.Sound = function (game, key, volume, loop) { /** * A reference to the currently running Game. - * @property game - * @public - * @type {Phaser.Game} + * @property {Phaser.Game} game */ this.game = game; /** - * Name of the sound - * @property name - * @public - * @type {string} + * Name of the sound. + * @property {string} name + * @default */ this.name = key; /** * Asset key for the sound. - * @property key - * @public - * @type {string} + * @property {string} key */ this.key = key; /** * Whether or not the sound will loop. - * @property loop - * @public - * @type {bool} + * @property {bool} loop */ this.loop = loop; /** - * The global audio volume. A value between 0 (silence) and 1 (full volume) - * @property _volume + * The global audio volume. A value between 0 (silence) and 1 (full volume). + * @property {number} _volume * @private - * @type {number} */ this._volume = volume; /** - * The sound markers, empty by default - * @property markers - * @public - * @type {object} + * The sound markers, empty by default. + * @property {object} markers */ this.markers = {}; /** * Reference to AudioContext instance. - * @property context - * @public - * @type {AudioContext} + * @property {AudioContext} context + * @default */ this.context = null; /** * Decoded data buffer / Audio tag. + * @property {Description} _buffer + * @private */ this._buffer = null; /** - * Boolean indicating whether the game is on "mute" - * @property _muted + * Boolean indicating whether the game is on "mute". + * @property {bool} _muted * @private - * @type {bool} + * @default */ this._muted = false; /** - * Boolean indicating whether the sound should start automatically - * @property autoplay - * @public - * @type {bool} + * Boolean indicating whether the sound should start automatically. + * @property {bool} autoplay + * @private */ this.autoplay = false; /** * The total duration of the sound, in milliseconds - * @property autoplay - * @public - * @type {bool} + * @property {number} totalDuration + * @default */ this.totalDuration = 0; + + /** + * Description. + * @property {number} startTime + * @default + */ this.startTime = 0; + + /** + * Description. + * @property {number} currentTime + * @default + */ this.currentTime = 0; + + /** + * Description. + * @property {number} duration + * @default + */ this.duration = 0; - this.durationMS = 0; + + /** + * Description. + * @property {number} autoplay + * @default + */ this.stopTime = 0; + + /** + * Description. + * @property {bool} paused + * @default + */ this.paused = false; + + /** + * Description. + * @property {bool} isPlaying + * @default + */ this.isPlaying = false; + + /** + * Description. + * @property {string} currentMarker + * @default + */ this.currentMarker = ''; + + /** + * Description. + * @property {bool} pendingPlayback + * @default + */ this.pendingPlayback = false; + + /** + * Description. + * @property {bool} override + * @default + */ this.override = false; - + + /** + * Description. + * @property {bool} usingWebAudio + */ this.usingWebAudio = this.game.sound.usingWebAudio; + + /** + * Description. + * @property {Description} usingAudioTag + */ this.usingAudioTag = this.game.sound.usingAudioTag; if (this.usingWebAudio) @@ -147,19 +207,62 @@ Phaser.Sound = function (game, key, volume, loop) { } } + /** + * Description. + * @property {Phaser.Signal} onDecoded + */ this.onDecoded = new Phaser.Signal; + + /** + * Description. + * @property {Phaser.Signal} onPlay + */ this.onPlay = new Phaser.Signal; + + /** + * Description. + * @property {Phaser.Signal} onPause + */ this.onPause = new Phaser.Signal; + + /** + * Description. + * @property {Phaser.Signal} onResume + */ this.onResume = new Phaser.Signal; + + /** + * Description. + * @property {Phaser.Signal} onLoop + */ this.onLoop = new Phaser.Signal; + + /** + * Description. + * @property {Phaser.Signal} onStop + */ this.onStop = new Phaser.Signal; + + /** + * Description. + * @property {Phaser.Signal} onMute + */ this.onMute = new Phaser.Signal; + + /** + * Description. + * @property {Phaser.Signal} onMarkerComplete + */ this.onMarkerComplete = new Phaser.Signal; }; Phaser.Sound.prototype = { + /** + * @method soundHasUnlocked + * @param {string} key - Description. + */ soundHasUnlocked: function (key) { if (key == this.key) @@ -171,9 +274,15 @@ Phaser.Sound.prototype = { }, - // start and stop are in SECONDS.MS (2.5 = 2500ms, 0.5 = 500ms, etc) - // volume is between 0 and 1 - /* + /** + * Description. + * @method addMarker + * @param {string} name - Description. + * @param {Description} start - Description. + * @param {Description} stop - Description. + * @param {Description} volume - Description. + * @param {Description} loop - Description. + */ addMarker: function (name, start, stop, volume, loop) { volume = volume || 1; @@ -210,12 +319,21 @@ Phaser.Sound.prototype = { }, + /** + * Description. + * @method removeMarker + * @param {string} name - Description. + */ removeMarker: function (name) { delete this.markers[name]; }, + /** + * Description. + * @method update + */ update: function () { if (this.pendingPlayback && this.game.cache.isSoundReady(this.key)) @@ -276,10 +394,11 @@ Phaser.Sound.prototype = { /** * Play this sound, or a marked section of it. * @method play - * @param {string} marker Assets key of the sound you want to play. - * @param {number} position The starting position - * @param {number} [volume] Volume of the sound you want to play. - * @param {bool} [loop] Loop when it finished playing? (Default to false) + * @param {string} marker - Assets key of the sound you want to play. + * @param {number} position - The starting position. + * @param {number} [volume] - Volume of the sound you want to play. + * @param {bool} [loop] - Loop when it finished playing? (Default to false) + * @param {Description} forceRestart - Description. * @return {Sound} The playing sound object. */ play: function (marker, position, volume, loop, forceRestart) { @@ -472,10 +591,10 @@ Phaser.Sound.prototype = { /** * Restart the sound, or a marked section of it. * @method restart - * @param {string} marker Assets key of the sound you want to play. - * @param {number} position The starting position - * @param {number} [volume] Volume of the sound you want to play. - * @param {bool} [loop] Loop when it finished playing? (Default to false) + * @param {string} marker - Assets key of the sound you want to play. + * @param {number} position - The starting position. + * @param {number} [volume] - Volume of the sound you want to play. + * @param {bool} [loop] - Loop when it finished playing? (Default to false) */ restart: function (marker, position, volume, loop) { @@ -505,7 +624,7 @@ Phaser.Sound.prototype = { }, /** * Resumes the sound - * @method pause + * @method resume */ resume: function () { @@ -571,6 +690,10 @@ Phaser.Sound.prototype = { }; +/** +* Get +* @return {bool} Description. +*/ Object.defineProperty(Phaser.Sound.prototype, "isDecoding", { get: function () { @@ -579,6 +702,10 @@ Object.defineProperty(Phaser.Sound.prototype, "isDecoding", { }); +/** +* Get +* @return {bool} Description. +*/ Object.defineProperty(Phaser.Sound.prototype, "isDecoded", { get: function () { @@ -587,22 +714,19 @@ Object.defineProperty(Phaser.Sound.prototype, "isDecoded", { }); +/** +* Get +* @return {bool} Whether or not the sound is muted. +*//** +* Mutes sound. +* @param {bool} value - Whether or not the sound is muted. +*/ Object.defineProperty(Phaser.Sound.prototype, "mute", { - - /** - * Mutes sound. - * @method mute - * @return {bool} whether or not the sound is muted - */ get: function () { return this._muted; }, - /** - * Mutes sound. - * @method mute - * @return {bool} whether or not the sound is muted - */ + set: function (value) { value = value || null; @@ -642,20 +766,19 @@ Object.defineProperty(Phaser.Sound.prototype, "mute", { }); +/** +* Get the current volume. A value between 0 (silence) and 1 (full volume). +* @return {number} +*//** +* Set +* @param {number} value - Sets the current volume. A value between 0 (silence) and 1 (full volume). +*/ Object.defineProperty(Phaser.Sound.prototype, "volume", { - /** - * @method volume - * @return {number} The current volume. A value between 0 (silence) and 1 (full volume) - */ get: function () { return this._volume; }, - /** - * @method volume - * @return {number} Sets the current volume. A value between 0 (silence) and 1 (full volume) - */ set: function (value) { if (this.usingWebAudio) diff --git a/src/sound/SoundManager.js b/src/sound/SoundManager.js index 252b57d6..8bd8c375 100644 --- a/src/sound/SoundManager.js +++ b/src/sound/SoundManager.js @@ -1,56 +1,93 @@ /** -* Phaser - SoundManager +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} +* @module Phaser.SoundManager +*/ + + +/** +* Sound Manager constructor. * -* @class SoundManager +* @class Phaser.SoundManager +* @classdesc Phaser Sound Manager. * @constructor * @param {Phaser.Game} game reference to the current game instance. */ Phaser.SoundManager = function (game) { - /** - * A reference to the currently running Game. - * @property game - * @public - * @type {Phaser.Game} - */ + /** + * @property {Phaser.Game} game - Local reference to game. + */ this.game = game; - + + /** + * @property {Phaser.Signal} onSoundDecode - Description. + */ this.onSoundDecode = new Phaser.Signal; - - - /** - * Boolean indicating whether the game is on "mute" - * @property _muted - * @private - * @type {bool} - */ + + /** + * @property {bool} _muted - Description. + * @private + * @default + */ this._muted = false; + + /** + * @property {Description} _unlockSource - Description. + * @private + * @default + */ this._unlockSource = null; /** - * The global audio volume. A value between 0 (silence) and 1 (full volume) - * @property _volume + * @property {number} _volume - The global audio volume. A value between 0 (silence) and 1 (full volume). * @private - * @type {number} + * @default */ this._volume = 1; /** - * An array containing all the sounds - * @property _sounds + * @property {array} _sounds - An array containing all the sounds * @private - * @type {array} + * @default The empty array. */ this._sounds = []; - + /** + * @property {Description} context - Description. + * @default + */ this.context = null; + + /** + * @property {bool} usingWebAudio - Description. + * @default + */ this.usingWebAudio = true; + + /** + * @property {bool} usingAudioTag - Description. + * @default + */ this.usingAudioTag = false; + + /** + * @property {bool} noAudio - Description. + * @default + */ this.noAudio = false; + /** + * @property {bool} touchLocked - Description. + * @default + */ this.touchLocked = false; + /** + * @property {number} channels - Description. + * @default + */ this.channels = 32; }; @@ -58,7 +95,7 @@ Phaser.SoundManager = function (game) { Phaser.SoundManager.prototype = { /** - * Initialises the sound manager + * Initialises the sound manager. * @method boot */ boot: function () { @@ -140,7 +177,7 @@ Phaser.SoundManager.prototype = { }, /** - * Enables the audio, usually after the first touch + * Enables the audio, usually after the first touch. * @method unlock */ unlock: function () { @@ -174,7 +211,7 @@ Phaser.SoundManager.prototype = { }, /** - * Stops all the sounds in the game + * Stops all the sounds in the game. * @method stopAll */ stopAll: function () { @@ -190,7 +227,7 @@ Phaser.SoundManager.prototype = { }, /** - * Pauses all the sounds in the game + * Pauses all the sounds in the game. * @method pauseAll */ pauseAll: function () { @@ -206,7 +243,7 @@ Phaser.SoundManager.prototype = { }, /** - * resumes every sound in the game + * resumes every sound in the game. * @method resumeAll */ resumeAll: function () { @@ -224,8 +261,8 @@ Phaser.SoundManager.prototype = { /** * Decode a sound with its assets key. * @method decode - * @param key {string} Assets key of the sound to be decoded. - * @param [sound] {Phaser.Sound} its bufer will be set to decoded data. + * @param {string} key - Assets key of the sound to be decoded. + * @param {Phaser.Sound} [sound] - Its buffer will be set to decoded data. */ decode: function (key, sound) { @@ -254,7 +291,7 @@ Phaser.SoundManager.prototype = { }, /** - * updates every sound in the game + * Updates every sound in the game. * @method update */ update: function () { @@ -282,17 +319,19 @@ Phaser.SoundManager.prototype = { /** - * + * Description. * @method add - * @param {string} key Asset key for the sound. - * @param {number} volume Default value for the volume. - * @param {bool} loop Whether or not the sound will loop. + * @param {string} key - Asset key for the sound. + * @param {number} volume - Default value for the volume. + * @param {bool} loop - Whether or not the sound will loop. */ add: function (key, volume, loop) { volume = volume || 1; if (typeof loop == 'undefined') { loop = false; } + + var sound = new Phaser.Sound(this.game, key, volume, loop); this._sounds.push(sound); @@ -303,24 +342,21 @@ Phaser.SoundManager.prototype = { }; +/** +* A global audio mute toggle. +* @return {bool} Whether or not the game is on "mute". +*//** +* Mute sounds. +* @param {bool} value - Whether or not the game is on "mute" +*/ Object.defineProperty(Phaser.SoundManager.prototype, "mute", { - /** - * A global audio mute toggle. - * @method mute - * @return {bool} whether or not the game is on "mute" - */ get: function () { return this._muted; }, - /** - * Mute sounds. - * @method mute - * @return {bool} whether or not the game is on "mute" - */ set: function (value) { value = value || null; @@ -376,12 +412,15 @@ Object.defineProperty(Phaser.SoundManager.prototype, "mute", { }); +/** +* Get +* @return {number} The global audio volume. A value between 0 (silence) and 1 (full volume). +*//** +* Sets the global volume +* @return {number} value - The global audio volume. A value between 0 (silence) and 1 (full volume). +*/ Object.defineProperty(Phaser.SoundManager.prototype, "volume", { - /** - * @method volume - * @return {number} The global audio volume. A value between 0 (silence) and 1 (full volume) - */ get: function () { if (this.usingWebAudio) @@ -395,11 +434,6 @@ Object.defineProperty(Phaser.SoundManager.prototype, "volume", { }, - /** - * Sets the global volume - * @method volume - * @return {number} The global audio volume. A value between 0 (silence) and 1 (full volume) - */ set: function (value) { value = this.game.math.clamp(value, 1, 0); diff --git a/src/system/Canvas.js b/src/system/Canvas.js index 49eb4b64..4b1fd255 100644 --- a/src/system/Canvas.js +++ b/src/system/Canvas.js @@ -1,28 +1,26 @@ /** * @author Richard Davey * @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.Canvas */ /** -* The Canvas class handles everything related to the tag as a DOM Element, like styles, offset, aspect ratio +* The Canvas class handles everything related to the <canvas> tag as a DOM Element, like styles, offset, aspect ratio * * @class Canvas * @static */ - Phaser.Canvas = { /** - * Creates the tag + * Creates the <canvas> tag * * @method create - * @param {number} width The desired width - * @param {number} height The desired height - * @return {HTMLCanvasElement} the newly created tag + * @param {number} width - The desired width. + * @param {number} height - The desired height. + * @return {HTMLCanvasElement} The newly created <canvas> tag. */ create: function (width, height) { - width = width || 256; height = height || 256; @@ -38,9 +36,9 @@ Phaser.Canvas = { /** * Get the DOM offset values of any given element * @method getOffset - * @param {HTMLElement} element The targeted element that we want to retrieve the offset - * @param {Phaser.Point} [point] The point we want to take the x/y values of the offset - * @return point {Phaser.Point} A point objet with the offsetX and Y as its properties + * @param {HTMLElement} element - The targeted element that we want to retrieve the offset. + * @param {Phaser.Point} [point] - The point we want to take the x/y values of the offset. + * @return {Phaser.Point} - A point objet with the offsetX and Y as its properties. */ getOffset: function (element, point) { @@ -63,8 +61,8 @@ Phaser.Canvas = { * Returns the aspect ratio of the given canvas. * * @method getAspectRatio - * @param {HTMLCanvasElement} canvas The canvas to get the aspect ratio from. - * @return {Number} Returns true on success + * @param {HTMLCanvasElement} canvas - The canvas to get the aspect ratio from. + * @return {number} The ratio between canvas' width and height. */ getAspectRatio: function (canvas) { return canvas.width / canvas.height; @@ -74,8 +72,8 @@ Phaser.Canvas = { * Sets the background color behind the canvas. This changes the canvas style property. * * @method setBackgroundColor - * @param {HTMLCanvasElement} canvas The canvas to set the background color on. - * @param {String} color The color to set. Can be in the format 'rgb(r,g,b)', or '#RRGGBB' or any valid CSS color. + * @param {HTMLCanvasElement} canvas - The canvas to set the background color on. + * @param {string} [color] - The color to set. Can be in the format 'rgb(r,g,b)', or '#RRGGBB' or any valid CSS color. * @return {HTMLCanvasElement} Returns the source canvas. */ setBackgroundColor: function (canvas, color) { @@ -92,9 +90,9 @@ Phaser.Canvas = { * Sets the touch-action property on the canvas style. Can be used to disable default browser touch actions. * * @method setTouchAction - * @param {HTMLCanvasElement} canvas The canvas to set the touch action on. - * @param {String} value The touch action to set. Defaults to 'none'. - * @return {HTMLCanvasElement} Returns the source canvas. + * @param {HTMLCanvasElement} canvas - The canvas to set the touch action on. + * @param {String} [value] - The touch action to set. Defaults to 'none'. + * @return {HTMLCanvasElement} The source canvas. */ setTouchAction: function (canvas, value) { @@ -127,9 +125,9 @@ Phaser.Canvas = { * If no parent is given it will be added as a child of the document.body. * * @method addToDOM - * @param {HTMLCanvasElement} canvas The canvas to set the touch action on. - * @param {String} parent The DOM element to add the canvas to. Defaults to ''. - * @param {bool} overflowHidden If set to true it will add the overflow='hidden' style to the parent DOM element. + * @param {HTMLCanvasElement} canvas - The canvas to set the touch action on. + * @param {string} parent - The DOM element to add the canvas to. Defaults to ''. + * @param {bool} overflowHidden - If set to true it will add the overflow='hidden' style to the parent DOM element. * @return {HTMLCanvasElement} Returns the source canvas. */ addToDOM: function (canvas, parent, overflowHidden) { @@ -167,13 +165,13 @@ Phaser.Canvas = { * Sets the transform of the given canvas to the matrix values provided. * * @method setTransform - * @param {CanvasRenderingContext2D} context The context to set the transform on. - * @param {Number} translateX The value to translate horizontally by. - * @param {Number} translateY The value to translate vertically by. - * @param {Number} scaleX The value to scale horizontally by. - * @param {Number} scaleY The value to scale vertically by. - * @param {Number} skewX The value to skew horizontaly by. - * @param {Number} skewY The value to skew vertically by. + * @param {CanvasRenderingContext2D} context - The context to set the transform on. + * @param {number} translateX - The value to translate horizontally by. + * @param {number} translateY - The value to translate vertically by. + * @param {number} scaleX - The value to scale horizontally by. + * @param {number} scaleY - The value to scale vertically by. + * @param {number} skewX - The value to skew horizontaly by. + * @param {number} skewY - The value to skew vertically by. * @return {CanvasRenderingContext2D} Returns the source context. */ setTransform: function (context, translateX, translateY, scaleX, scaleY, skewX, skewY) { @@ -192,8 +190,8 @@ Phaser.Canvas = { * patchy on earlier browsers, especially on mobile. * * @method setSmoothingEnabled - * @param {CanvasRenderingContext2D} context The context to enable or disable the image smoothing on. - * @param {bool} value If set to true it will enable image smoothing, false will disable it. + * @param {CanvasRenderingContext2D} context - The context to enable or disable the image smoothing on. + * @param {bool} value - If set to true it will enable image smoothing, false will disable it. * @return {CanvasRenderingContext2D} Returns the source context. */ setSmoothingEnabled: function (context, value) { @@ -213,7 +211,7 @@ Phaser.Canvas = { * Note that if this doesn't given the desired result then see the setSmoothingEnabled. * * @method setImageRenderingCrisp - * @param {HTMLCanvasElement} canvas The canvas to set image-rendering crisp on. + * @param {HTMLCanvasElement} canvas - The canvas to set image-rendering crisp on. * @return {HTMLCanvasElement} Returns the source canvas. */ setImageRenderingCrisp: function (canvas) { diff --git a/src/system/Device.js b/src/system/Device.js index d3da1582..4b4a6341 100644 --- a/src/system/Device.js +++ b/src/system/Device.js @@ -1,184 +1,194 @@ /** -* Phaser - Device -* +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} +* @module Phaser.Device +*/ + + +/** * Detects device support capabilities. Using some elements from System.js by MrDoob and Modernizr -* https://github.com/Modernizr/Modernizr/blob/master/feature-detects/audio.js +* {@link https://github.com/Modernizr/Modernizr/blob/master/feature-detects/audio.js} +* +* @class Phaser.Device +* @constructor */ Phaser.Device = function () { /** * An optional 'fix' for the horrendous Android stock browser bug - * https://code.google.com/p/android/issues/detail?id=39247 - * @type {boolean} + * {@link https://code.google.com/p/android/issues/detail?id=39247} + * @property {bool} patchAndroidClearRectBug - Description. + * @default */ this.patchAndroidClearRectBug = false; // Operating System /** - * Is running desktop? - * @type {boolean} + * @property {bool} desktop - Is running desktop? + * @default */ this.desktop = false; /** - * Is running on iOS? - * @type {boolean} + * @property {bool} iOS - Is running on iOS? + * @default */ this.iOS = false; /** - * Is running on android? - * @type {boolean} + * @property {bool} android - Is running on android? + * @default */ this.android = false; /** - * Is running on chromeOS? - * @type {boolean} + * @property {bool} chromeOS - Is running on chromeOS? + * @default */ this.chromeOS = false; /** - * Is running on linux? - * @type {boolean} + * @property {bool} linux - Is running on linux? + * @default */ this.linux = false; /** - * Is running on maxOS? - * @type {boolean} + * @property {bool} maxOS - Is running on maxOS? + * @default */ this.macOS = false; /** - * Is running on windows? - * @type {boolean} + * @property {bool} windows - Is running on windows? + * @default */ this.windows = false; // Features /** - * Is canvas available? - * @type {boolean} + * @property {bool} canvas - Is canvas available? + * @default */ this.canvas = false; /** - * Is file available? - * @type {boolean} + * @property {bool} file - Is file available? + * @default */ this.file = false; /** - * Is fileSystem available? - * @type {boolean} + * @property {bool} fileSystem - Is fileSystem available? + * @default */ this.fileSystem = false; /** - * Is localStorage available? - * @type {boolean} + * @property {bool} localStorage - Is localStorage available? + * @default */ this.localStorage = false; /** - * Is webGL available? - * @type {boolean} + * @property {bool} webGL - Is webGL available? + * @default */ this.webGL = false; /** - * Is worker available? - * @type {boolean} + * @property {bool} worker - Is worker available? + * @default */ this.worker = false; /** - * Is touch available? - * @type {boolean} + * @property {bool} touch - Is touch available? + * @default */ this.touch = false; /** - * Is mspointer available? - * @type {boolean} + * @property {bool} mspointer - Is mspointer available? + * @default */ this.mspointer = false; /** - * Is css3D available? - * @type {boolean} + * @property {bool} css3D - Is css3D available? + * @default */ this.css3D = false; - /** - * Is Pointer Lock available? - * @type {boolean} + /** + * @property {bool} pointerLock - Is Pointer Lock available? + * @default */ this.pointerLock = false; // Browser /** - * Is running in arora? - * @type {boolean} + * @property {bool} arora - Is running in arora? + * @default */ this.arora = false; /** - * Is running in chrome? - * @type {boolean} + * @property {bool} chrome - Is running in chrome? + * @default */ this.chrome = false; /** - * Is running in epiphany? - * @type {boolean} + * @property {bool} epiphany - Is running in epiphany? + * @default */ this.epiphany = false; /** - * Is running in firefox? - * @type {boolean} + * @property {bool} firefox - Is running in firefox? + * @default */ this.firefox = false; /** - * Is running in ie? - * @type {boolean} + * @property {bool} ie - Is running in ie? + * @default */ this.ie = false; /** - * Version of ie? - * @type Number + * @property {number} ieVersion - Version of ie? + * @default */ this.ieVersion = 0; /** - * Is running in mobileSafari? - * @type {boolean} + * @property {bool} mobileSafari - Is running in mobileSafari? + * @default */ this.mobileSafari = false; /** - * Is running in midori? - * @type {boolean} + * @property {bool} midori - Is running in midori? + * @default */ this.midori = false; /** - * Is running in opera? - * @type {boolean} + * @property {bool} opera - Is running in opera? + * @default */ this.opera = false; /** - * Is running in safari? - * @type {boolean} + * @property {bool} safari - Is running in safari? + * @default */ this.safari = false; this.webApp = false; @@ -186,75 +196,76 @@ Phaser.Device = function () { // Audio /** - * Are Audio tags available? - * @type {boolean} + * @property {bool} audioData - Are Audio tags available? + * @default */ this.audioData = false; /** - * Is the WebAudio API available? - * @type {boolean} + * @property {bool} webAudio - Is the WebAudio API available? + * @default */ this.webAudio = false; /** - * Can this device play ogg files? - * @type {boolean} + * @property {bool} ogg - Can this device play ogg files? + * @default */ this.ogg = false; /** - * Can this device play opus files? - * @type {boolean} + * @property {bool} opus - Can this device play opus files? + * @default */ this.opus = false; /** - * Can this device play mp3 files? - * @type {boolean} + * @property {bool} mp3 - Can this device play mp3 files? + * @default */ this.mp3 = false; /** - * Can this device play wav files? - * @type {boolean} + * @property {bool} wav - Can this device play wav files? + * @default */ this.wav = false; /** * Can this device play m4a files? - * @type {boolean} + * @property {bool} m4a - True if this device can play m4a files. + * @default */ this.m4a = false; /** - * Can this device play webm files? - * @type {boolean} + * @property {bool} webm - Can this device play webm files? + * @default */ this.webm = false; // Device /** - * Is running on iPhone? - * @type {boolean} + * @property {bool} iPhone - Is running on iPhone? + * @default */ this.iPhone = false; /** - * Is running on iPhone4? - * @type {boolean} + * @property {bool} iPhone4 - Is running on iPhone4? + * @default */ this.iPhone4 = false; - /** - * Is running on iPad? - * @type {boolean} + /** + * @property {bool} iPad - Is running on iPad? + * @default */ this.iPad = false; /** - * PixelRatio of the host device? - * @type Number + * @property {number} pixelRatio - PixelRatio of the host device? + * @default */ this.pixelRatio = 0; @@ -272,6 +283,7 @@ Phaser.Device.prototype = { /** * Check which OS is game running on. + * @method _checkOS * @private */ _checkOS: function () { @@ -300,6 +312,7 @@ Phaser.Device.prototype = { /** * Check HTML5 features of the host environment. + * @method _checkFeatures * @private */ _checkFeatures: function () { @@ -332,6 +345,7 @@ Phaser.Device.prototype = { /** * Check what browser is game running in. + * @method _checkBrowser * @private */ _checkBrowser: function () { @@ -368,6 +382,7 @@ Phaser.Device.prototype = { /** * Check audio support. + * @method _checkAudio * @private */ _checkAudio: function () { @@ -414,6 +429,7 @@ Phaser.Device.prototype = { /** * Check PixelRatio of devices. + * @method _checkDevice * @private */ _checkDevice: function () { @@ -427,6 +443,7 @@ Phaser.Device.prototype = { /** * Check whether the host environment support 3D CSS. + * @method _checkCSS3D * @private */ _checkCSS3D: function () { @@ -453,6 +470,11 @@ Phaser.Device.prototype = { }, + /** + * Check whether the host environment can play audio. + * @method canPlayAudio + * @param {string} type - One of 'mp3, 'ogg', 'm4a', 'wav', 'webm'. + */ canPlayAudio: function (type) { if (type == 'mp3' && this.mp3) { @@ -471,6 +493,12 @@ Phaser.Device.prototype = { }, + /** + * Check whether the console is open. + * @method isConsoleOpen + * @return {bool} True if console is open. + */ + isConsoleOpen: function () { if (window.console && window.console['firebug']) { diff --git a/src/system/RequestAnimationFrame.js b/src/system/RequestAnimationFrame.js index 9366e22d..7243e7e1 100644 --- a/src/system/RequestAnimationFrame.js +++ b/src/system/RequestAnimationFrame.js @@ -1,13 +1,35 @@ /** -* Phaser - RequestAnimationFrame -* +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} +* @module Phaser.RequestAnimationFrame +*/ + + +/** * Abstracts away the use of RAF or setTimeOut for the core game update loop. +* +* @class Phaser.RequestAnimationFrame +* @constructor +* @param {Phaser.Game} game - A reference to the currently running game. */ Phaser.RequestAnimationFrame = function(game) { + /** + * @property {Phaser.Game} game - The currently running game. + */ this.game = game; + /** + * @property {bool} _isSetTimeOut - Description. + * @private + */ this._isSetTimeOut = false; + + /** + * @property {bool} isRunning - Description. + * @default + */ this.isRunning = false; var vendors = [ @@ -28,6 +50,7 @@ Phaser.RequestAnimationFrame.prototype = { /** * The function called by the update + * @property _onLoop * @private **/ _onLoop: null, @@ -67,7 +90,8 @@ Phaser.RequestAnimationFrame.prototype = { /** * The update method for the requestAnimationFrame - * @method RAFUpdate + * @method updateRAF + * @param {number} time - Description. **/ updateRAF: function (time) { @@ -78,8 +102,8 @@ Phaser.RequestAnimationFrame.prototype = { }, /** - * The update method for the setTimeout - * @method SetTimeoutUpdate + * The update method for the setTimeout. + * @method updateSetTimeout **/ updateSetTimeout: function () { @@ -90,7 +114,7 @@ Phaser.RequestAnimationFrame.prototype = { }, /** - * Stops the requestAnimationFrame from running + * Stops the requestAnimationFrame from running. * @method stop **/ stop: function () { @@ -111,7 +135,7 @@ Phaser.RequestAnimationFrame.prototype = { /** * Is the browser using setTimeout? * @method isSetTimeOut - * @return bool + * @return {bool} **/ isSetTimeOut: function () { return this._isSetTimeOut; @@ -120,7 +144,7 @@ Phaser.RequestAnimationFrame.prototype = { /** * Is the browser using requestAnimationFrame? * @method isRAF - * @return bool + * @return {bool} **/ isRAF: function () { return (this._isSetTimeOut === false); diff --git a/src/system/StageScaleMode.js b/src/system/StageScaleMode.js index 3ff98a9d..b581395f 100644 --- a/src/system/StageScaleMode.js +++ b/src/system/StageScaleMode.js @@ -1,91 +1,120 @@ +/** +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} +* @module Phaser.StageScaleMode +*/ + +/** +* 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. +* +* @class Phaser.StageScaleMode +* @constructor +* @param {Phaser.Game} game - A reference to the currently running game. +* @param {number} width - Description. +* @param {number} height - Description. +*/ Phaser.StageScaleMode = function (game, width, height) { /** - * Stage height when start the game. - * @type {number} + * @property {number} _startHeight - Stage height when starting the game. + * @default + * @private */ this._startHeight = 0; /** - * If the game should be forced to use Landscape mode, this is set to true by Game.Stage - * @type {bool} + * @property {bool} forceLandscape - If the game should be forced to use Landscape mode, this is set to true by Game.Stage + * @default */ this.forceLandscape = false; /** - * If the game should be forced to use Portrait mode, this is set to true by Game.Stage - * @type {bool} + * @property {bool} forcePortrait - If the game should be forced to use Portrait mode, this is set to true by Game.Stage + * @default */ - this.forcePortrait = false; + this.forcePortrait = false; /** - * If the game should be forced to use a specific orientation and the device currently isn't in that orientation this is set to true. - * @type {bool} + * @property {bool} incorrectOrientation - If the game should be forced to use a specific orientation and the device currently isn't in that orientation this is set to true. + * @default */ this.incorrectOrientation = false; /** - * If you wish to align your game in the middle of the page then you can set this value to true. - * It will place a re-calculated margin-left pixel value onto the canvas element which is updated on orientation/resizing. - * It doesn't care about any other DOM element that may be on the page, it literally just sets the margin. - * @type {bool} + * @property {bool} pageAlignHorizontally - If you wish to align your game in the middle of the page then you can set this value to true. +

  • It will place a re-calculated margin-left pixel value onto the canvas element which is updated on orientation/resizing.
  • +
  • It doesn't care about any other DOM element that may be on the page, it literally just sets the margin.
+ * @default */ this.pageAlignHorizontally = false; /** - * If you wish to align your game in the middle of the page then you can set this value to true. - * It will place a re-calculated margin-left pixel value onto the canvas element which is updated on orientation/resizing. - * It doesn't care about any other DOM element that may be on the page, it literally just sets the margin. - * @type {bool} + * @property {bool} pageAlignVeritcally - If you wish to align your game in the middle of the page then you can set this value to true. +
  • It will place a re-calculated margin-left pixel value onto the canvas element which is updated on orientation/resizing. +
  • It doesn't care about any other DOM element that may be on the page, it literally just sets the margin.
+ * @default */ this.pageAlignVeritcally = false; /** - * Minimum width the canvas should be scaled to (in pixels) - * @type {number} + * @property {number} minWidth - Minimum width the canvas should be scaled to (in pixels). + * @default */ this.minWidth = null; /** - * Maximum width the canvas should be scaled to (in pixels). + * @property {number} maxWidth - Maximum width the canvas should be scaled to (in pixels). * If null it will scale to whatever width the browser can handle. - * @type {number} + * @default */ this.maxWidth = null; /** - * Minimum height the canvas should be scaled to (in pixels) - * @type {number} + * @property {number} minHeight - Minimum height the canvas should be scaled to (in pixels). + * @default */ this.minHeight = null; /** - * Maximum height the canvas should be scaled to (in pixels). + * @property {number} maxHeight - Maximum height the canvas should be scaled to (in pixels). * If null it will scale to whatever height the browser can handle. - * @type {number} + * @default */ this.maxHeight = null; /** - * Width of the stage after calculation. - * @type {number} + * @property {number} width - Width of the stage after calculation. + * @default */ this.width = 0; /** - * Height of the stage after calculation. - * @type {number} + * @property {number} height - Height of the stage after calculation. + * @default */ this.height = 0; /** - * The maximum number of times it will try to resize the canvas to fill the browser (default is 5) - * @type {number} + * @property {number} maxIterations - The maximum number of times it will try to resize the canvas to fill the browser. + * @default */ this.maxIterations = 5; + + /** + * @property {Phaser.Game} game - A reference to the currently running game. + */ this.game = game; + /** + * @property {Description} enterLandscape - Description. + */ this.enterLandscape = new Phaser.Signal(); + + /** + * @property {Description} enterPortrait - Description. + */ this.enterPortrait = new Phaser.Signal(); if (window['orientation']) @@ -104,7 +133,15 @@ Phaser.StageScaleMode = function (game, width, height) { } } + /** + * @property {Description} scaleFactor - Description. + */ this.scaleFactor = new Phaser.Point(1, 1); + + /** + * @property {number} aspectRatio - Aspect ratio. + * @default + */ this.aspectRatio = 0; var _this = this; @@ -124,7 +161,10 @@ Phaser.StageScaleMode.NO_SCALE = 1; Phaser.StageScaleMode.SHOW_ALL = 2; Phaser.StageScaleMode.prototype = { - + /** + * Description. + * @method startFullScreen + */ startFullScreen: function () { if (this.isFullScreen) @@ -152,6 +192,10 @@ Phaser.StageScaleMode.prototype = { }, + /** + * Description. + * @method stopFullScreen + */ stopFullScreen: function () { if (document['cancelFullScreen']) @@ -169,6 +213,10 @@ Phaser.StageScaleMode.prototype = { }, + /** + * Description. + * @method checkOrientationState + */ checkOrientationState: function () { // They are in the wrong orientation @@ -194,8 +242,10 @@ Phaser.StageScaleMode.prototype = { } }, - /** + /** * Handle window.orientationchange events + * @method checkOrientation + * @param {Description} event - Description. */ checkOrientation: function (event) { @@ -217,8 +267,10 @@ Phaser.StageScaleMode.prototype = { }, - /** + /** * Handle window.resize events + * @method checkResize + * @param {Description} event - Description. */ checkResize: function (event) { @@ -246,8 +298,9 @@ Phaser.StageScaleMode.prototype = { } }, - /** + /** * Re-calculate scale mode and update screen size. + * @method refresh */ refresh: function () { @@ -280,8 +333,9 @@ Phaser.StageScaleMode.prototype = { }, - /** + /** * Set screen size automatically based on the scaleMode. + * @param {Description} force - Description. */ setScreenSize: function (force) { @@ -329,6 +383,10 @@ Phaser.StageScaleMode.prototype = { }, + /** + * Description. + * @method setSize + */ setSize: function () { if (this.incorrectOrientation == false) @@ -392,6 +450,10 @@ Phaser.StageScaleMode.prototype = { }, + /** + * Description. + * @method setMaximum + */ setMaximum: function () { this.width = window.innerWidth; @@ -399,6 +461,10 @@ Phaser.StageScaleMode.prototype = { }, + /** + * Description. + * @method setShowAll + */ setShowAll: function () { var multiplier = Math.min((window.innerHeight / this.game.height), (window.innerWidth / this.game.width)); @@ -408,6 +474,10 @@ Phaser.StageScaleMode.prototype = { }, + /** + * Description. + * @method setExactFit + */ setExactFit: function () { var availableWidth = window.innerWidth - 0; @@ -439,6 +509,10 @@ Phaser.StageScaleMode.prototype = { }; +/** +* Get +* @return {bool} +*/ Object.defineProperty(Phaser.StageScaleMode.prototype, "isFullScreen", { get: function () { @@ -454,6 +528,10 @@ Object.defineProperty(Phaser.StageScaleMode.prototype, "isFullScreen", { }); +/** +* Get +* @return {number} +*/ Object.defineProperty(Phaser.StageScaleMode.prototype, "isPortrait", { get: function () { @@ -462,6 +540,10 @@ Object.defineProperty(Phaser.StageScaleMode.prototype, "isPortrait", { }); +/** +* Get +* @return {number} +*/ Object.defineProperty(Phaser.StageScaleMode.prototype, "isLandscape", { get: function () { diff --git a/src/tilemap/Tile.js b/src/tilemap/Tile.js index e4500526..29f776f3 100644 --- a/src/tilemap/Tile.js +++ b/src/tilemap/Tile.js @@ -1,91 +1,120 @@ /** -* Phaser - Tile -* -* A Tile is a single representation of a tile within a Tilemap +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} +* @module Phaser.Tile */ + /** -* Tile constructor * Create a new Tile. * -* @param tilemap {Tilemap} the tilemap this tile belongs to. -* @param index {number} The index of this tile type in the core map data. -* @param width {number} Width of the tile. -* @param height number} Height of the tile. +* @class Phaser.Tile +* @classdesc A Tile is a single representation of a tile within a Tilemap. +* @constructor +* @param {Phaser.Game} game - A reference to the currently running game. +* @param {Tilemap} tilemap - The tilemap this tile belongs to. +* @param {number} index - The index of this tile type in the core map data. +* @param {number} width - Width of the tile. +* @param {number} height - Height of the tile. */ Phaser.Tile = function (game, tilemap, index, width, height) { /** - * The virtual mass of the tile. - * @type {number} + * @property {number} mass - The virtual mass of the tile. + * @default */ this.mass = 1.0; /** - * Indicating this Tile doesn't collide at all. - * @type {bool} + * @property {bool} collideNone - Indicating this Tile doesn't collide at all. + * @default */ this.collideNone = true; /** - * Indicating collide with any object on the left. - * @type {bool} + * @property {bool} collideLeft - Indicating collide with any object on the left. + * @default */ this.collideLeft = false; /** - * Indicating collide with any object on the right. - * @type {bool} + * @property {bool} collideRight - Indicating collide with any object on the right. + * @default */ this.collideRight = false; /** - * Indicating collide with any object on the top. - * @type {bool} + * @property {bool} collideUp - Indicating collide with any object on the top. + * @default */ this.collideUp = false; /** - * Indicating collide with any object on the bottom. - * @type {bool} + * @property {bool} collideDown - Indicating collide with any object on the bottom. + * @default */ this.collideDown = false; /** - * Enable separation at x-axis. - * @type {bool} + * @property {bool} separateX - Enable separation at x-axis. + * @default */ this.separateX = true; /** - * Enable separation at y-axis. - * @type {bool} + * @property {bool} separateY - Enable separation at y-axis. + * @default */ this.separateY = true; + /** + * @property {Phaser.Game} game - A reference to the currently running game. + */ this.game = game; + + /** + * @property {bool} tilemap - The tilemap this tile belongs to. + */ this.tilemap = tilemap; + + /** + * @property {number} index - The index of this tile type in the core map data. + */ this.index = index; + + /** + * @property {number} width - The width of the tile. + */ this.width = width; + + /** + * @property {number} height - The height of the tile. + */ this.height = height; }; Phaser.Tile.prototype = { - /** + /** * Clean up memory. + * @method destroy */ destroy: function () { this.tilemap = null; }, - /** + /** * Set collision configs. - * @param collision {number} Bit field of flags. (see Tile.allowCollision) - * @param resetCollisions {bool} Reset collision flags before set. - * @param separateX {bool} Enable seprate at x-axis. - * @param separateY {bool} Enable seprate at y-axis. + * @method setCollision + * @param {bool} left - Indicating collide with any object on the left. + * @param {bool} right - Indicating collide with any object on the right. + * @param {bool} up - Indicating collide with any object on the top. + * @param {bool} down - Indicating collide with any object on the bottom. + * @param {bool} reset - Description. + * @param {bool} separateX - Separate at x-axis. + * @param {bool} separateY - Separate at y-axis. */ setCollision: function (left, right, up, down, reset, separateX, separateY) { @@ -110,8 +139,9 @@ Phaser.Tile.prototype = { }, - /** + /** * Reset collision status flags. + * @method resetCollision */ resetCollision: function () { diff --git a/src/tilemap/Tilemap.js b/src/tilemap/Tilemap.js index 40eec6c8..dfbc677c 100644 --- a/src/tilemap/Tilemap.js +++ b/src/tilemap/Tilemap.js @@ -1,21 +1,24 @@ /** -* Phaser - Tilemap -* -* This GameObject allows for the display of a tilemap within the game world. Tile maps consist of an image, tile data and a size. -* Internally it creates a TilemapLayer for each layer in the tilemap. +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License +* @module Phaser.Tilemap */ + /** -* Tilemap constructor * Create a new Tilemap. -* -* @param game {Phaser.Game} Current game instance. -* @param key {string} Asset key for this map. -* @param mapData {string} Data of this map. (a big 2d array, normally in csv) -* @param format {number} Format of this map data, available: Tilemap.CSV or Tilemap.JSON. -* @param resizeWorld {bool} Resize the world bound automatically based on this tilemap? -* @param tileWidth {number} Width of tiles in this map (used for CSV maps). -* @param tileHeight {number} Height of tiles in this map (used for CSV maps). +* @class Phaser.Tilemap +* @classdesc This GameObject allows for the display of a tilemap within the game world. Tile maps consist of an image, tile data and a size. +* Internally it creates a TilemapLayer for each layer in the tilemap. +* @constructor +* @param {Phaser.Game} game - Current game instance. +* @param {string} key - Asset key for this map. +* @param {object} x - Description. +* @param {object} y - Description. +* @param {bool} resizeWorld - Resize the world bound automatically based on this tilemap? +* @param {number} tileWidth - Width of tiles in this map (used for CSV maps). +* @param {number} tileHeight - Height of tiles in this map (used for CSV maps). */ Phaser.Tilemap = function (game, key, x, y, resizeWorld, tileWidth, tileHeight) { @@ -23,38 +26,85 @@ Phaser.Tilemap = function (game, key, x, y, resizeWorld, tileWidth, tileHeight) if (typeof tileWidth === "undefined") { tileWidth = 0; } if (typeof tileHeight === "undefined") { tileHeight = 0; } + /** + * @property {Phaser.Game} game - A reference to the currently running game. + */ this.game = game; + + /** + * @property {Description} group - Description. + */ this.group = null; + + /** + * @property {string} name - The user defined name given to this Description. + * @default + */ this.name = ''; + + /** + * @property {Description} key - Description. + */ this.key = key; /** - * Render iteration counter + * @property {number} renderOrderID - Render iteration counter + * @default */ this.renderOrderID = 0; - /** - * Tilemap collision callback. - * @type {function} - */ + /** + * @property {bool} collisionCallback - Tilemap collision callback. + * @default + */ this.collisionCallback = null; + /** + * @property {bool} exists - Description. + * @default + */ this.exists = true; + + /** + * @property {bool} visible - Description. + * @default + */ this.visible = true; + /** + * @property {bool} tiles - Description. + * @default + */ this.tiles = []; + + /** + * @property {bool} layers - Description. + * @default + */ this.layers = []; var map = this.game.cache.getTilemap(key); PIXI.DisplayObjectContainer.call(this); + /** + * @property {Description} position - Description. + */ this.position.x = x; this.position.y = y; + /** + * @property {Description} type - Description. + */ this.type = Phaser.TILEMAP; + /** + * @property {Description} renderer - Description. + */ this.renderer = new Phaser.TilemapRenderer(this.game); + /** + * @property {Description} mapFormat - Description. + */ this.mapFormat = map.format; switch (this.mapFormat) @@ -83,11 +133,13 @@ Phaser.Tilemap.CSV = 0; Phaser.Tilemap.JSON = 1; /** -* Parset csv map data and generate tiles. -* @param data {string} CSV map data. -* @param key {string} Asset key for tileset image. -* @param tileWidth {number} Width of its tile. -* @param tileHeight {number} Height of its tile. +* Parse csv map data and generate tiles. +* +* @method Phaser.Tilemap.prototype.parseCSV +* @param {string} data - CSV map data. +* @param {string} key - Asset key for tileset image. +* @param {number} tileWidth - Width of its tile. +* @param {number} tileHeight - Height of its tile. */ Phaser.Tilemap.prototype.parseCSV = function (data, key, tileWidth, tileHeight) { @@ -123,8 +175,10 @@ Phaser.Tilemap.prototype.parseCSV = function (data, key, tileWidth, tileHeight) /** * Parse JSON map data and generate tiles. -* @param data {string} JSON map data. -* @param key {string} Asset key for tileset image. +* +* @method Phaser.Tilemap.prototype.parseTiledJSON +* @param {string} data - JSON map data. +* @param {string} key - Asset key for tileset image. */ Phaser.Tilemap.prototype.parseTiledJSON = function (json, key) { @@ -181,7 +235,8 @@ Phaser.Tilemap.prototype.parseTiledJSON = function (json, key) { /** * Create tiles of given quantity. -* @param qty {number} Quentity of tiles to be generated. +* @method Phaser.Tilemap.prototype.generateTiles +* @param {number} qty - Quantity of tiles to be generated. */ Phaser.Tilemap.prototype.generateTiles = function (qty) { @@ -194,8 +249,10 @@ Phaser.Tilemap.prototype.generateTiles = function (qty) { /** * Set callback to be called when this tilemap collides. -* @param context {object} Callback will be called with this context. -* @param callback {function} Callback function. +* +* @method Phaser.Tilemap.prototype.setCollisionCallback +* @param {object} context - Callback will be called with this context. +* @param {Function} callback - Callback function. */ Phaser.Tilemap.prototype.setCollisionCallback = function (context, callback) { @@ -206,12 +263,14 @@ Phaser.Tilemap.prototype.setCollisionCallback = function (context, callback) { /** * Set collision configs of tiles in a range index. -* @param start {number} First index of tiles. -* @param end {number} Last index of tiles. -* @param collision {number} Bit field of flags. (see Tile.allowCollision) -* @param resetCollisions {bool} Reset collision flags before set. -* @param separateX {bool} Enable seprate at x-axis. -* @param separateY {bool} Enable seprate at y-axis. +* +* @method Phaser.Tilemap.prototype.setCollisionRange +* @param {number} start - First index of tiles. +* @param {number} end - Last index of tiles. +* @param {number} collision - Bit field of flags. (see Tile.allowCollision) +* @param {bool} resetCollisions - Reset collision flags before set. +* @param {bool} separateX - Enable separate at x-axis. +* @param {bool} separateY - Enable separate at y-axis. */ Phaser.Tilemap.prototype.setCollisionRange = function (start, end, left, right, up, down, resetCollisions, separateX, separateY) { @@ -228,11 +287,15 @@ Phaser.Tilemap.prototype.setCollisionRange = function (start, end, left, right, /** * Set collision configs of tiles with given index. -* @param values {number[]} Index array which contains all tile indexes. The tiles with those indexes will be setup with rest parameters. -* @param collision {number} Bit field of flags. (see Tile.allowCollision) -* @param resetCollisions {bool} Reset collision flags before set. -* @param separateX {bool} Enable seprate at x-axis. -* @param separateY {bool} Enable seprate at y-axis. +* @param {number[]} values - Index array which contains all tile indexes. The tiles with those indexes will be setup with rest parameters. +* @param {number} collision - Bit field of flags (see Tile.allowCollision). +* @param {bool} resetCollisions - Reset collision flags before set. +* @param {bool} left - Indicating collide with any object on the left. +* @param {bool} right - Indicating collide with any object on the right. +* @param {bool} up - Indicating collide with any object on the top. +* @param {bool} down - Indicating collide with any object on the bottom. +* @param {bool} separateX - Enable separate at x-axis. +* @param {bool} separateY - Enable separate at y-axis. */ Phaser.Tilemap.prototype.setCollisionByIndex = function (values, left, right, up, down, resetCollisions, separateX, separateY) { @@ -251,7 +314,7 @@ Phaser.Tilemap.prototype.setCollisionByIndex = function (values, left, right, up /** * Get the tile by its index. -* @param value {number} Index of the tile you want to get. +* @param {number} value - Index of the tile you want to get. * @return {Tile} The tile with given index. */ Phaser.Tilemap.prototype.getTileByIndex = function (value) { @@ -267,9 +330,9 @@ Phaser.Tilemap.prototype.getTileByIndex = function (value) { /** * Get the tile located at specific position and layer. -* @param x {number} X position of this tile located. -* @param y {number} Y position of this tile located. -* @param [layer] {number} layer of this tile located. +* @param {number} x - X position of this tile located. +* @param {number} y - Y position of this tile located. +* @param {number} [layer] - layer of this tile located. * @return {Tile} The tile with specific properties. */ Phaser.Tilemap.prototype.getTile = function (x, y, layer) { @@ -281,10 +344,10 @@ Phaser.Tilemap.prototype.getTile = function (x, y, layer) { }; /** -* Get the tile located at specific position (in world coordinate) and layer. (thus you give a position of a point which is within the tile) -* @param x {number} X position of the point in target tile. -* @param x {number} Y position of the point in target tile. -* @param [layer] {number} layer of this tile located. +* Get the tile located at specific position (in world coordinate) and layer (thus you give a position of a point which is within the tile). +* @param {number} x - X position of the point in target tile. +* @param {number} y - Y position of the point in target tile. +* @param {number} [layer] - layer of this tile located. * @return {Tile} The tile with specific properties. */ Phaser.Tilemap.prototype.getTileFromWorldXY = function (x, y, layer) { @@ -296,9 +359,9 @@ Phaser.Tilemap.prototype.getTileFromWorldXY = function (x, y, layer) { }; /** -* Gets the tile underneath the Input.x/y position -* @param layer The layer to check, defaults to 0 -* @returns {Tile} +* Gets the tile underneath the Input.x/y position. +* @param {number} layer - The layer to check, defaults to 0. +* @return {Tile} */ Phaser.Tilemap.prototype.getTileFromInputXY = function (layer) { @@ -310,8 +373,8 @@ Phaser.Tilemap.prototype.getTileFromInputXY = function (layer) { /** * Get tiles overlaps the given object. -* @param object {GameObject} Tiles you want to get that overlaps this. -* @return {array} Array with tiles information. (Each contains x, y and the tile.) +* @param {GameObject} object - Tiles you want to get that overlaps this. +* @return {array} Array with tiles information (Each contains x, y and the tile). */ Phaser.Tilemap.prototype.getTileOverlaps = function (object) { @@ -323,9 +386,9 @@ Phaser.Tilemap.prototype.getTileOverlaps = function (object) { /** * Check whether this tilemap collides with the given game object or group of objects. -* @param objectOrGroup {function} Target object of group you want to check. -* @param callback {function} This is called if objectOrGroup collides the tilemap. -* @param context {object} Callback will be called with this context. +* @param {Function} objectOrGroup - Target object of group you want to check. +* @param {Function} callback - This is called if objectOrGroup collides the tilemap. +* @param {object} context - Callback will be called with this context. * @return {bool} Return true if this collides with given object, otherwise return false. */ Phaser.Tilemap.prototype.collide = function (objectOrGroup, callback, context) { @@ -353,7 +416,7 @@ Phaser.Tilemap.prototype.collide = function (objectOrGroup, callback, context) { /** * Check whether this tilemap collides with the given game object. -* @param object {GameObject} Target object you want to check. +* @param {GameObject} object - Target object you want to check. * @return {bool} Return true if this collides with given object, otherwise return false. */ Phaser.Tilemap.prototype.collideGameObject = function (object) { @@ -383,10 +446,10 @@ Phaser.Tilemap.prototype.collideGameObject = function (object) { /** * Set a tile to a specific layer. -* @param x {number} X position of this tile. -* @param y {number} Y position of this tile. -* @param index {number} The index of this tile type in the core map data. -* @param [layer] {number} which layer you want to set the tile to. +* @param {number} x - X position of this tile. +* @param {number} y - Y position of this tile. +* @param {number} index - The index of this tile type in the core map data. +* @param {number} [layer] - Which layer you want to set the tile to. */ Phaser.Tilemap.prototype.putTile = function (x, y, index, layer) { @@ -397,7 +460,7 @@ Phaser.Tilemap.prototype.putTile = function (x, y, index, layer) { }; /** -* Calls the renderer +* Calls the renderer. */ Phaser.Tilemap.prototype.update = function () { @@ -405,6 +468,9 @@ Phaser.Tilemap.prototype.update = function () { }; +/** +* Description. +*/ Phaser.Tilemap.prototype.destroy = function () { this.tiles.length = 0; @@ -412,6 +478,10 @@ Phaser.Tilemap.prototype.destroy = function () { }; +/** +* Get width in pixels. +* @return {number} +*/ Object.defineProperty(Phaser.Tilemap.prototype, "widthInPixels", { get: function () { @@ -420,6 +490,10 @@ Object.defineProperty(Phaser.Tilemap.prototype, "widthInPixels", { }); +/** +* Get height in pixels. +* @return {number} +*/ Object.defineProperty(Phaser.Tilemap.prototype, "heightInPixels", { get: function () { diff --git a/src/tilemap/TilemapLayer.js b/src/tilemap/TilemapLayer.js index 8e5487ee..510d32f6 100644 --- a/src/tilemap/TilemapLayer.js +++ b/src/tilemap/TilemapLayer.js @@ -1,113 +1,203 @@ /** -* Phaser - TilemapLayer -* -* A Tilemap Layer. Tiled format maps can have multiple overlapping layers. +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License +* @module Phaser.TilemapLayer */ /** -* TilemapLayer constructor * Create a new TilemapLayer. -* +* @class Phaser.TilemapLayer +* @classdesc A Tilemap Layer. Tiled format maps can have multiple overlapping layers. +* @constructor * @param parent {Tilemap} The tilemap that contains this layer. * @param id {number} The ID of this layer within the Tilemap array. * @param key {string} Asset key for this map. -* @param mapFormat {number} Format of this map data, available: Tilemap.CSV or Tilemap.JSON. +* @param mapformat {number} Format of this map data, available: Tilemap.CSV or Tilemap.JSON. * @param name {string} Name of this layer, so you can get this layer by its name. * @param tileWidth {number} Width of tiles in this map. * @param tileHeight {number} Height of tiles in this map. */ Phaser.TilemapLayer = function (parent, id, key, mapFormat, name, tileWidth, tileHeight) { - /** - * Controls whether update() and draw() are automatically called. - * @type {bool} - */ + /** + * @property {bool} exists - Controls whether update() and draw() are automatically called. + * @default + */ this.exists = true; - /** - * Controls whether draw() are automatically called. - * @type {bool} - */ + /** + * @property {bool} visible - Controls whether draw() are automatically called. + * @default + */ this.visible = true; /** * How many tiles in each row. * Read-only variable, do NOT recommend changing after the map is loaded! - * @type {number} + * @property {number} widthInTiles + * @default */ this.widthInTiles = 0; /** * How many tiles in each column. * Read-only variable, do NOT recommend changing after the map is loaded! - * @type {number} + * @property {number} heightInTiles + * @default */ this.heightInTiles = 0; /** * Read-only variable, do NOT recommend changing after the map is loaded! - * @type {number} + * @property {number} widthInPixels + * @default */ this.widthInPixels = 0; /** * Read-only variable, do NOT recommend changing after the map is loaded! - * @type {number} + * @property {number} heightInPixels + * @default */ this.heightInPixels = 0; /** * Distance between REAL tiles to the tileset texture bound. - * @type {number} + * @property {number} tileMargin + * @default */ this.tileMargin = 0; /** * Distance between every 2 neighbor tile in the tileset texture. - * @type {number} + * @property {number} tileSpacing + * @default */ this.tileSpacing = 0; + /** + * @property {Description} parent - Description. + */ this.parent = parent; + + /** + * @property {Phaser.Game} game - Description. + */ this.game = parent.game; + + /** + * @property {Description} ID - Description. + */ this.ID = id; + + /** + * @property {Description} name - Description. + */ this.name = name; + + /** + * @property {Description} key - Description. + */ this.key = key; + + /** + * @property {Description} type - Description. + */ this.type = Phaser.TILEMAPLAYER; + /** + * @property {tileWidth} mapFormat - Description. + */ this.mapFormat = mapFormat; + + /** + * @property {Description} tileWidth - Description. + */ this.tileWidth = tileWidth; + + /** + * @property {Description} tileHeight - Description. + */ this.tileHeight = tileHeight; + /** + * @property {Phaser.Rectangle} boundsInTiles - Description. + */ this.boundsInTiles = new Phaser.Rectangle(); var map = this.game.cache.getTilemap(key); + /** + * @property {Description} tileset - Description. + */ this.tileset = map.data; + /** + * @property {Description} _alpha - Description. + * @private + * @default + */ this._alpha = 1; - this.quadTree = null; - + /** + * @property {Description} canvas - Description. + * @default + */ this.canvas = null; + + /** + * @property {Description} context - Description. + * @default + */ this.context = null; + + /** + * @property {Description} baseTexture - Description. + * @default + */ this.baseTexture = null; + + /** + * @property {Description} texture - Description. + * @default + */ this.texture = null; + + /** + * @property {Description} sprite - Description. + * @default + */ this.sprite = null; + /** + * @property {array} mapData - Description. + */ this.mapData = []; + + /** + * @property {array} _tempTileBlock - Description. + * @private + */ this._tempTileBlock = []; + + /** + * @property {array} _tempBlockResults - Description. + * @private + * + */ this._tempBlockResults = []; }; Phaser.TilemapLayer.prototype = { - /** + /** * Set a specific tile with its x and y in tiles. - * @param x {number} X position of this tile in world coordinates. - * @param y {number} Y position of this tile in world coordinates. - * @param index {number} The index of this tile type in the core map data. + * @method putTileWorldXY + * @param {number} x - X position of this tile in world coordinates. + * @param {number} y - Y position of this tile in world coordinates. + * @param {number} index - The index of this tile type in the core map data. */ putTileWorldXY: function (x, y, index) { @@ -124,11 +214,12 @@ Phaser.TilemapLayer.prototype = { }, - /** + /** * Set a specific tile with its x and y in tiles. - * @param x {number} X position of this tile. - * @param y {number} Y position of this tile. - * @param index {number} The index of this tile type in the core map data. + * @method putTile + * @param {number} x - X position of this tile. + * @param {number} y - Y position of this tile. + * @param {number} index - The index of this tile type in the core map data. */ putTile: function (x, y, index) { @@ -142,14 +233,15 @@ Phaser.TilemapLayer.prototype = { }, - /** + /** * Swap tiles with 2 kinds of indexes. - * @param tileA {number} First tile index. - * @param tileB {number} Second tile index. - * @param [x] {number} specify a Rectangle of tiles to operate. The x position in tiles of Rectangle's left-top corner. - * @param [y] {number} specify a Rectangle of tiles to operate. The y position in tiles of Rectangle's left-top corner. - * @param [width] {number} specify a Rectangle of tiles to operate. The width in tiles. - * @param [height] {number} specify a Rectangle of tiles to operate. The height in tiles. + * @method swapTile + * @param {number} tileA - First tile index. + * @param {number} tileB - Second tile index. + * @param {number} [x] - specify a Rectangle of tiles to operate. The x position in tiles of Rectangle's left-top corner. + * @param {number} [y] - specify a Rectangle of tiles to operate. The y position in tiles of Rectangle's left-top corner. + * @param {number} [width] - specify a Rectangle of tiles to operate. The width in tiles. + * @param {number} [height] - specify a Rectangle of tiles to operate. The height in tiles. */ swapTile: function (tileA, tileB, x, y, width, height) { @@ -186,13 +278,14 @@ Phaser.TilemapLayer.prototype = { }, - /** + /** * Fill a tile block with a specific tile index. - * @param index {number} Index of tiles you want to fill with. - * @param [x] {number} x position (in tiles) of block's left-top corner. - * @param [y] {number} y position (in tiles) of block's left-top corner. - * @param [width] {number} width of block. - * @param [height] {number} height of block. + * @method fillTile + * @param {number} index - Index of tiles you want to fill with. + * @param {number} [x] - X position (in tiles) of block's left-top corner. + * @param {number} [y] - Y position (in tiles) of block's left-top corner. + * @param {number} [width] - width of block. + * @param {number} [height] - height of block. */ fillTile: function (index, x, y, width, height) { @@ -210,13 +303,14 @@ Phaser.TilemapLayer.prototype = { }, - /** + /** * Set random tiles to a specific tile block. - * @param tiles {number[]} Tiles with indexes in this array will be randomly set to the given block. - * @param [x] {number} x position (in tiles) of block's left-top corner. - * @param [y] {number} y position (in tiles) of block's left-top corner. - * @param [width] {number} width of block. - * @param [height] {number} height of block. + * @method randomiseTiles + * @param {number[]} tiles - Tiles with indexes in this array will be randomly set to the given block. + * @param {number} [x] - X position (in tiles) of block's left-top corner. + * @param {number} [y] - Y position (in tiles) of block's left-top corner. + * @param {number} [width] - width of block. + * @param {number} [height] - height of block. */ randomiseTiles: function (tiles, x, y, width, height) { @@ -234,14 +328,15 @@ Phaser.TilemapLayer.prototype = { }, - /** + /** * Replace one kind of tiles to another kind. - * @param tileA {number} Index of tiles you want to replace. - * @param tileB {number} Index of tiles you want to set. - * @param [x] {number} x position (in tiles) of block's left-top corner. - * @param [y] {number} y position (in tiles) of block's left-top corner. - * @param [width] {number} width of block. - * @param [height] {number} height of block. + * @method replaceTile + * @param {number} tileA - First tile index. + * @param {number} tileB - Second tile index. + * @param {number} [x] - X position (in tiles) of block's left-top corner. + * @param {number} [y] - Y position (in tiles) of block's left-top corner. + * @param {number} [width] - width of block. + * @param {number} [height] - height of block. */ replaceTile: function (tileA, tileB, x, y, width, height) { @@ -262,12 +357,13 @@ Phaser.TilemapLayer.prototype = { }, - /** - * Get a tile block with specific position and size.(both are in tiles) - * @param x {number} X position of block's left-top corner. - * @param y {number} Y position of block's left-top corner. - * @param width {number} Width of block. - * @param height {number} Height of block. + /** + * Get a tile block with specific position and size (both are in tiles). + * @method getTileBlock + * @param {number} [x] - X position (in tiles) of block's left-top corner. + * @param {number} [y] - Y position (in tiles) of block's left-top corner. + * @param {number} [width] - width of block. + * @param {number} [height] - height of block. */ getTileBlock: function (x, y, width, height) { @@ -288,10 +384,11 @@ Phaser.TilemapLayer.prototype = { }, - /** + /** * Get a tile with specific position (in world coordinate). (thus you give a position of a point which is within the tile) - * @param x {number} X position of the point in target tile. - * @param x {number} Y position of the point in target tile. + * @method getTileFromWorldXY + * @param {number} [x] - X position (in tiles) of block's left-top corner. + * @param {number} [y] - Y position (in tiles) of block's left-top corner. */ getTileFromWorldXY: function (x, y) { @@ -302,10 +399,11 @@ Phaser.TilemapLayer.prototype = { }, - /** + /** * Get tiles overlaps the given object. - * @param object {GameObject} Tiles you want to get that overlaps this. - * @return {array} Array with tiles informations. (Each contains x, y and the tile.) + * @method getTileOverlaps + * @param {GameObject} object - Tiles you want to get that overlaps this. + * @return {array} Array with tiles informations (each contains x, y, and the tile). */ getTileOverlaps: function (object) { @@ -339,13 +437,14 @@ Phaser.TilemapLayer.prototype = { }, - /** - * Get a tile block with its position and size. (This method does not return, it'll set result to _tempTileBlock) - * @param x {number} X position of block's left-top corner. - * @param y {number} Y position of block's left-top corner. - * @param width {number} Width of block. - * @param height {number} Height of block. - * @param collisionOnly {bool} Whethor or not ONLY return tiles which will collide (its allowCollisions value is not Collision.NONE). + /** + * Get a tile block with its position and size (this method does not return, it'll set result to _tempTileBlock). + * @method getTempBlock + * @param {number} [x] - X position (in tiles) of block's left-top corner. + * @param {number} [y] - Y position (in tiles) of block's left-top corner. + * @param {number} [width] - width of block. + * @param {number} [height] - height of block. + * @param {bool} collisionOnly - Whethor or not ONLY return tiles which will collide (its allowCollisions value is not Collision.NONE). */ getTempBlock: function (x, y, width, height, collisionOnly) { @@ -404,10 +503,11 @@ Phaser.TilemapLayer.prototype = { } }, - /** + /** * Get the tile index of specific position (in tiles). - * @param x {number} X position of the tile. - * @param y {number} Y position of the tile. + * @method getTileIndex + * @param {number} x - X position of the tile. + * @param {number} y - Y position of the tile. * @return {number} Index of the tile at that position. Return null if there isn't a tile there. */ getTileIndex: function (x, y) { @@ -424,9 +524,10 @@ Phaser.TilemapLayer.prototype = { }, - /** + /** * Add a column of tiles into the layer. - * @param column {string[]/number[]} An array of tile indexes to be added. + * @method addColumn + * @param {string[]|number[]} column - An array of tile indexes to be added. */ addColumn: function (column) { @@ -450,6 +551,10 @@ Phaser.TilemapLayer.prototype = { }, + /** + * Description. + * @method createCanvas + */ createCanvas: function () { var width = this.game.width; @@ -484,6 +589,7 @@ Phaser.TilemapLayer.prototype = { /** * Update boundsInTiles with widthInTiles and heightInTiles. + * @method updateBounds */ updateBounds: function () { @@ -491,12 +597,13 @@ Phaser.TilemapLayer.prototype = { }, - /** + /** * Parse tile offsets from map data. * Basically this creates a large array of objects that contain the x/y coordinates to grab each tile from * for the entire map. Yes we could calculate this at run-time by using the tile index and some math, but we're * trading a quite small bit of memory here to not have to process that in our main render loop. - * @return {number} length of tileOffsets array. + * @method parseTileOffsets + * @return {number} Length of tileOffsets array. */ parseTileOffsets: function () { @@ -529,6 +636,13 @@ Phaser.TilemapLayer.prototype = { }; +/** +* Get +* @return {Description} +*//** +* Set +* @param {Description} value - Description. +*/ Object.defineProperty(Phaser.TilemapLayer.prototype, 'alpha', { get: function() { diff --git a/src/tilemap/TilemapRenderer.js b/src/tilemap/TilemapRenderer.js index bd881058..85ff3328 100644 --- a/src/tilemap/TilemapRenderer.js +++ b/src/tilemap/TilemapRenderer.js @@ -1,19 +1,106 @@ +/** +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License +* @module Phaser.TilemapRenderer +*/ + +/** +* Tilemap renderer. +* +* @class Phaser.TilemapRenderer +* @constructor +* @param {Phaser.Game} game - A reference to the currently running game. +*/ Phaser.TilemapRenderer = function (game) { + /** + * @property {Phaser.Game} game - A reference to the currently running game. + */ this.game = game; - - // Local rendering related temp vars to help avoid gc spikes through constant var creation + + /** + * @property {number} _ga - Local rendering related temp vars to help avoid gc spikes through constant var creation. + * @private + * @default + */ this._ga = 1; + + /** + * @property {number} _dx - Description. + * @private + * @default + */ this._dx = 0; + + /** + * @property {number} _dy - Description. + * @private + * @default + */ this._dy = 0; + + /** + * @property {number} _dw - Description. + * @private + * @default + */ this._dw = 0; + + /** + * @property {number} _dh - Description. + * @private + * @default + */ this._dh = 0; + + /** + * @property {number} _tx - Description. + * @private + * @default + */ this._tx = 0; + + /** + * @property {number} _ty - Description. + * @private + * @default + */ this._ty = 0; + + /** + * @property {number} _tl - Description. + * @private + * @default + */ this._tl = 0; + + /** + * @property {number} _maxX - Description. + * @private + * @default + */ this._maxX = 0; + + /** + * @property {number} _maxY - Description. + * @private + * @default + */ this._maxY = 0; + + /** + * @property {number} _startX - Description. + * @private + * @default + */ this._startX = 0; + + /** + * @property {number} _startY - Description. + * @private + * @default + */ this._startY = 0; }; @@ -21,9 +108,11 @@ Phaser.TilemapRenderer = function (game) { Phaser.TilemapRenderer.prototype = { /** - * Render a tilemap to a canvas. - * @param tilemap {Tilemap} The tilemap data to render. - */ + * Render a tilemap to a canvas. + * @method render + * @param tilemap {Tilemap} The tilemap data to render. + * @return {bool} Description. + */ render: function (tilemap) { // Loop through the layers diff --git a/src/time/Time.js b/src/time/Time.js index b141e24f..219a42bc 100644 --- a/src/time/Time.js +++ b/src/time/Time.js @@ -1,160 +1,145 @@ /** * @author Richard Davey * @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.Time */ /** -* This is the core internal game clock. It manages the elapsed time and calculation of elapsed values, -* used for game object motion and tweens. +* Time constructor. * -* @class Time +* @class Phaser.Time +* @classdesc This is the core internal game clock. It manages the elapsed time and calculation of elapsed values, +* used for game object motion and tweens. * @constructor * @param {Phaser.Game} game A reference to the currently running game. */ Phaser.Time = function (game) { /** - * A reference to the currently running Game. - * @property game - * @type {Phaser.Game} + * @property {Phaser.Game} game - Local reference to game. */ this.game = game; /** * The time at which the Game instance started. - * @property _started + * @property {number} _started * @private - * @type {Number} + * @default */ this._started = 0; /** * The time (in ms) that the last second counter ticked over. - * @property _timeLastSecond + * @property {number} _timeLastSecond * @private - * @type {Number} + * @default */ this._timeLastSecond = 0; /** * The time the game started being paused. - * @property _pauseStarted + * @property {number} _pauseStarted * @private - * @type {Number} + * @default */ this._pauseStarted = 0; /** * The elapsed time calculated for the physics motion updates. - * @property physicsElapsed - * @public - * @type {Number} + * @property {number} physicsElapsed + * @default */ this.physicsElapsed = 0; /** * Game time counter. - * @property time - * @public - * @type {Number} + * @property {number} time + * @default */ this.time = 0; /** * Records how long the game has been paused for. Is reset each time the game pauses. - * @property pausedTime - * @public - * @type {Number} + * @property {number} pausedTime + * @default */ this.pausedTime = 0; /** * The time right now. - * @property now - * @public - * @type {Number} + * @property {number} now + * @default */ this.now = 0; /** * Elapsed time since the last frame. - * @property elapsed - * @public - * @type {Number} + * @property {number} elapsed + * @default */ this.elapsed = 0; /** * Frames per second. - * @property fps - * @public - * @type {Number} + * @property {number} fps + * @default */ this.fps = 0; /** * The lowest rate the fps has dropped to. - * @property fpsMin - * @public - * @type {Number} + * @property {number} fpsMin + * @default */ this.fpsMin = 1000; /** * The highest rate the fps has reached (usually no higher than 60fps). - * @property fpsMax - * @public - * @type {Number} + * @property {number} fpsMax + * @default */ this.fpsMax = 0; /** * The minimum amount of time the game has taken between two frames. - * @property msMin - * @public - * @type {Number} + * @property {number} msMin + * @default */ this.msMin = 1000; /** * The maximum amount of time the game has taken between two frames. - * @property msMax - * @public - * @type {Number} + * @property {number} msMax + * @default */ this.msMax = 0; /** * The number of frames record in the last second. - * @property frames - * @public - * @type {Number} + * @property {number} frames + * @default */ this.frames = 0; /** * Records how long the game was paused for in miliseconds. - * @property pauseDuration - * @public - * @type {Number} + * @property {number} pauseDuration + * @default */ this.pauseDuration = 0; /** * The value that setTimeout needs to work out when to next update - * @property timeToCall - * @public - * @type {Number} + * @property {number} timeToCall + * @default */ this.timeToCall = 0; /** * Internal value used by timeToCall as part of the setTimeout loop - * @property lastTime - * @public - * @type {Number} + * @property {number} lastTime + * @default */ this.lastTime = 0; @@ -162,6 +147,11 @@ Phaser.Time = function (game) { this.game.onPause.add(this.gamePaused, this); this.game.onResume.add(this.gameResumed, this); + /** + * Description. + * @property {bool} _justResumed + * @default + */ this._justResumed = false; }; @@ -171,7 +161,7 @@ Phaser.Time.prototype = { /** * The number of seconds that have elapsed since the game was started. * @method totalElapsedSeconds - * @return {Number} + * @return {number} */ totalElapsedSeconds: function() { return (this.now - this._started) * 0.001; @@ -179,9 +169,9 @@ Phaser.Time.prototype = { /** * Updates the game clock and calculate the fps. - * This is called automatically by Phaser.Game + * This is called automatically by Phaser.Game. * @method update - * @param {Number} time The current timestamp, either performance.now or Date.now depending on the browser + * @param {number} time - The current timestamp, either performance.now or Date.now depending on the browser. */ update: function (time) { @@ -251,8 +241,8 @@ Phaser.Time.prototype = { /** * How long has passed since the given time. * @method elapsedSince - * @param {Number} since The time you want to measure against. - * @return {Number} The difference between the given time and now. + * @param {number} since - The time you want to measure against. + * @return {number} The difference between the given time and now. */ elapsedSince: function (since) { return this.now - since; @@ -261,8 +251,8 @@ Phaser.Time.prototype = { /** * How long has passed since the given time (in seconds). * @method elapsedSecondsSince - * @param {Number} since The time you want to measure (in seconds). - * @return {Number} Duration between given time and now (in seconds). + * @param {number} since - The time you want to measure (in seconds). + * @return {number} Duration between given time and now (in seconds). */ elapsedSecondsSince: function (since) { return (this.now - since) * 0.001; diff --git a/src/tween/Easing.js b/src/tween/Easing.js index b2b8350c..42ea177a 100644 --- a/src/tween/Easing.js +++ b/src/tween/Easing.js @@ -1,7 +1,33 @@ +/** +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} +* @module Phaser.Easing +*/ + + +/** +* A collection of easing methods defining ease-in ease-out curves. +* +* @class Phaser.Easing +*/ Phaser.Easing = { + /** + * Linear easing. + * + * @namespace Linear + */ Linear: { + /** + * Ease-in. + * + * @method In + * @param {number} k - Description. + * @memberof Linear + * @returns {number} k^2. + */ None: function ( k ) { return k; @@ -10,20 +36,49 @@ Phaser.Easing = { }, + /** + * Quadratic easing. + * + * @namespace Quadratic + */ Quadratic: { + /** + * Ease-in. + * + * @method In + * @param {number} k - Description. + * @memberof Quadratic + * @returns {number} k^2. + */ In: function ( k ) { return k * k; }, + /** + * Ease-out. + * + * @method Out + * @param {number} k - Description. + * @memberof Quadratic + * @returns {number} k* (2-k). + */ Out: function ( k ) { return k * ( 2 - k ); }, + /** + * Ease-in/out. + * + * @method InOut + * @param {number} k - Description. + * @memberof Quadratic + * @returns {number} Description. + */ InOut: function ( k ) { if ( ( k *= 2 ) < 1 ) return 0.5 * k * k; @@ -33,20 +88,49 @@ Phaser.Easing = { }, + /** + * Cubic easing. + * + * @namespace Cubic + */ Cubic: { + /** + * Cubic ease-in. + * + * @method In + * @param {number} k - Description. + * @memberof Cubic + * @returns {number} Description. + */ In: function ( k ) { return k * k * k; }, + /** + * Cubic ease-out. + * + * @method Out + * @param {number} k - Description. + * @memberof Cubic + * @returns {number} Description. + */ Out: function ( k ) { return --k * k * k + 1; }, + /** + * Cubic ease-in/out. + * + * @method InOut + * @param {number} k - Description. + * @memberof Cubic + * @returns {number} Description. + */ InOut: function ( k ) { if ( ( k *= 2 ) < 1 ) return 0.5 * k * k * k; @@ -56,20 +140,49 @@ Phaser.Easing = { }, + /** + * Quartic easing. + * + * @namespace Quartic + */ Quartic: { + /** + * Quartic ease-in. + * + * @method In + * @param {number} k - Description. + * @memberof Quartic + * @returns {number} Description. + */ In: function ( k ) { return k * k * k * k; }, + /** + * Quartic ease-out. + * + * @method Out + * @param {number} k - Description. + * @memberof Quartic + * @returns {number} Description. + */ Out: function ( k ) { return 1 - ( --k * k * k * k ); }, + /** + * Quartic ease-in/out. + * + * @method InOut + * @param {number} k - Description. + * @returns {number} Description. + * @memberof Quartic + */ InOut: function ( k ) { if ( ( k *= 2 ) < 1) return 0.5 * k * k * k * k; @@ -79,20 +192,49 @@ Phaser.Easing = { }, + /** + * Quintic easing. + * + * @namespace Quintic + */ Quintic: { + /** + * Quintic ease-in. + * + * @method In + * @param {number} k - Description. + * @memberof Quintic + * @returns {number} Description. + */ In: function ( k ) { return k * k * k * k * k; }, + /** + * Quintic ease-out. + * + * @method Out + * @param {number} k - Description. + * @memberof Quintic + * @returns {number} Description. + */ Out: function ( k ) { return --k * k * k * k * k + 1; }, + /** + * Quintic ease-in/out. + * + * @method InOut + * @param {number} k - Description. + * @memberof Quintic + * @returns {number} Description. + */ InOut: function ( k ) { if ( ( k *= 2 ) < 1 ) return 0.5 * k * k * k * k * k; @@ -102,20 +244,49 @@ Phaser.Easing = { }, + /** + * Sinusoidal easing. + * + * @namespace Sinusoidal + */ Sinusoidal: { + /** + * Sinusoidal ease-in. + * + * @method In + * @param {number} k - Description. + * @memberof Sinusoidal + * @returns {number} Description. + */ In: function ( k ) { return 1 - Math.cos( k * Math.PI / 2 ); }, + /** + * Sinusoidal ease-out. + * + * @method Out + * @param {number} k - Description. + * @memberof Sinusoidal + * @returns {number} Description. + */ Out: function ( k ) { return Math.sin( k * Math.PI / 2 ); }, + /** + * Sinusoidal ease-in/out. + * + * @method InOut + * @param {number} k - Description. + * @memberof Sinusoidal + * @returns {number} Description. + */ InOut: function ( k ) { return 0.5 * ( 1 - Math.cos( Math.PI * k ) ); @@ -124,20 +295,49 @@ Phaser.Easing = { }, + /** + * Exponential easing. + * + * @namespace Exponential + */ Exponential: { + /** + * Exponential ease-in. + * + * @method In + * @param {number} k - Description. + * @memberof Exponential + * @returns {number} Description. + */ In: function ( k ) { return k === 0 ? 0 : Math.pow( 1024, k - 1 ); }, + /** + * Exponential ease-out. + * + * @method Out + * @param {number} k - Description. + * @memberof Exponential + * @returns {number} Description. + */ Out: function ( k ) { return k === 1 ? 1 : 1 - Math.pow( 2, - 10 * k ); }, + /** + * Exponential ease-in/out. + * + * @method InOut + * @param {number} k - Description. + * @memberof Exponential + * @returns {number} Description. + */ InOut: function ( k ) { if ( k === 0 ) return 0; @@ -149,20 +349,49 @@ Phaser.Easing = { }, + /** + * Circular easing. + * + * @namespace Circular + */ Circular: { + /** + * Circular ease-in. + * + * @method In + * @param {number} k - Description. + * @memberof Circular + * @returns {number} Description. + */ In: function ( k ) { return 1 - Math.sqrt( 1 - k * k ); }, + /** + * Circular ease-out. + * + * @method Out + * @param {number} k - Description. + * @memberof Circular + * @returns {number} Description. + */ Out: function ( k ) { return Math.sqrt( 1 - ( --k * k ) ); }, + /** + * Circular ease-in/out. + * + * @method InOut + * @param {number} k - Description. + * @memberof Circular + * @returns {number} Description. + */ InOut: function ( k ) { if ( ( k *= 2 ) < 1) return - 0.5 * ( Math.sqrt( 1 - k * k) - 1); @@ -172,8 +401,21 @@ Phaser.Easing = { }, + /** + * Elastic easing. + * + * @namespace Elastic + */ Elastic: { + /** + * Elastic ease-in. + * + * @method In + * @param {number} k - Description. + * @memberof Elastic + * @returns {number} Description. + */ In: function ( k ) { var s, a = 0.1, p = 0.4; @@ -185,6 +427,14 @@ Phaser.Easing = { }, + /** + * Elastic ease-out. + * + * @method Out + * @param {number} k - Description. + * @memberof Elastic + * @returns {number} Description. + */ Out: function ( k ) { var s, a = 0.1, p = 0.4; @@ -196,6 +446,14 @@ Phaser.Easing = { }, + /** + * Elastic ease-in/out. + * + * @method InOut + * @param {number} k - Description. + * @memberof Elastic + * @returns {number} Description. + */ InOut: function ( k ) { var s, a = 0.1, p = 0.4; @@ -210,8 +468,21 @@ Phaser.Easing = { }, + /** + * Back easing. + * + * @namespace Back + */ Back: { + /** + * Back ease-in. + * + * @method In + * @param {number} k - Description. + * @memberof Back + * @returns {number} Description. + */ In: function ( k ) { var s = 1.70158; @@ -219,6 +490,14 @@ Phaser.Easing = { }, + /** + * Back ease-out. + * + * @method Out + * @param {number} k - Description. + * @memberof Back + * @returns {number} Description. + */ Out: function ( k ) { var s = 1.70158; @@ -226,6 +505,14 @@ Phaser.Easing = { }, + /** + * Back ease-in/out. + * + * @method InOut + * @param {number} k - Description. + * @memberof Back + * @returns {number} Description. + */ InOut: function ( k ) { var s = 1.70158 * 1.525; @@ -236,14 +523,35 @@ Phaser.Easing = { }, + /** + * Bounce easing. + * + * @namespace Bounce + */ Bounce: { + /** + * Bounce ease-in. + * + * @method In + * @param {number} k - Description. + * @memberof Bounce + * @returns {number} Description. + */ In: function ( k ) { return 1 - Phaser.Easing.Bounce.Out( 1 - k ); }, + /** + * Bounce ease-out. + * + * @method Out + * @param {number} k - Description. + * @memberof Bounce + * @returns {number} Description. + */ Out: function ( k ) { if ( k < ( 1 / 2.75 ) ) { @@ -266,6 +574,14 @@ Phaser.Easing = { }, + /** + * Bounce ease-in/out. + * + * @method InOut + * @param {number} k - Description. + * @memberof Bounce + * @returns {number} Description. + */ InOut: function ( k ) { if ( k < 0.5 ) return Phaser.Easing.Bounce.In( k * 2 ) * 0.5; diff --git a/src/tween/Tween.js b/src/tween/Tween.js index 07fe841d..4abbad87 100644 --- a/src/tween/Tween.js +++ b/src/tween/Tween.js @@ -1,52 +1,177 @@ +/** +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} +* @module Phaser.Tween +*/ + + /** * Tween constructor * Create a new Tween. * -* @param object {object} Target object will be affected by this tween. -* @param game {Phaser.Game} Current game instance. +* @class Phaser.Tween +* @constructor +* @param {object} object - Target object will be affected by this tween. +* @param {Phaser.Game} game - Current game instance. */ - Phaser.Tween = function (object, game) { /** * Reference to the target object. - * @type {object} + * @property {object} _object + * @private */ this._object = object; + /** + * @property {Phaser.Game} game - A reference to the currently running Game. + */ this.game = game; + + /** + * @property {object} _manager - Description. + * @private + */ this._manager = this.game.tweens; - this._valuesStart = {}; - this._valuesEnd = {}; - this._valuesStartRepeat = {}; - this._duration = 1000; - this._repeat = 0; - this._yoyo = false; - this._reversed = false; - this._delayTime = 0; - this._startTime = null; - this._easingFunction = Phaser.Easing.Linear.None; - this._interpolationFunction = Phaser.Math.linearInterpolation; - this._chainedTweens = []; - this._onStartCallback = null; - this._onStartCallbackFired = false; - this._onUpdateCallback = null; - this._onCompleteCallback = null; + /** + * @property {object} _valuesStart - Description. + * @private + */ + this._valuesStart = {}; + /** + * @property {object} _valuesEnd - Description. + * @private + */ + this._valuesEnd = {}; + + /** + * @property {object} _valuesStartRepeat - Description. + * @private + */ + this._valuesStartRepeat = {}; + + /** + * @property {number} _duration - Description. + * @default + */ + this._duration = 1000; + + /** + * @property {number} _repeat - Description. + * @private + * @default + */ + this._repeat = 0; + + /** + * @property {bool} _yoyo - Description. + * @private + * @default + */ + this._yoyo = false; + + /** + * @property {bool} _reversed - Description. + * @private + * @default + */ + this._reversed = false; + + /** + * @property {number} _delayTime - Description. + * @private + * @default + */ + this._delayTime = 0; + + /** + * @property {Description} _startTime - Description. + * @private + * @default null + */ + this._startTime = null; + + /** + * @property {Description} _easingFunction - Description. + * @private + */ + this._easingFunction = Phaser.Easing.Linear.None; + + /** + * @property {Description} _interpolationFunction - Description. + * @private + */ + this._interpolationFunction = Phaser.Math.linearInterpolation; + + /** + * @property {Description} _chainedTweens - Description. + * @private + */ + this._chainedTweens = []; + + /** + * @property {Description} _onStartCallback - Description. + * @private + * @default + */ + this._onStartCallback = null; + + /** + * @property {bool} _onStartCallbackFired - Description. + * @private + * @default + */ + this._onStartCallbackFired = false; + + /** + * @property {Description} _onUpdateCallback - Description. + * @private + * @default null + */ + this._onUpdateCallback = null; + + /** + * @property {Description} _onCompleteCallback - Description. + * @private + * @default null + */ + this._onCompleteCallback = null; + + /** + * @property {number} _pausedTime - Description. + * @private + * @default + */ this._pausedTime = 0; - this._parent = null; + /** + * @property {bool} pendingDelete - Description. + * @default + */ this.pendingDelete = false; - // Set all starting values present on the target object - for ( var field in object ) { - this._valuesStart[ field ] = parseFloat(object[field], 10); - } - + // Set all starting values present on the target object + for ( var field in object ) { + this._valuesStart[ field ] = parseFloat(object[field], 10); + } + + /** + * @property {Phaser.Signal} onStart - Description. + */ this.onStart = new Phaser.Signal(); + + /** + * @property {Phaser.Signal} onComplete - Description. + */ this.onComplete = new Phaser.Signal(); + /** + * @property {bool} isRunning - Description. + * @default + */ this.isRunning = false; }; @@ -55,13 +180,16 @@ Phaser.Tween.prototype = { /** * Configure the Tween - * @param properties {object} Propertis you want to tween. - * @param [duration] {number} duration of this tween. - * @param [ease] {any} Easing function. - * @param [autoStart] {bool} Whether this tween will start automatically or not. - * @param [delay] {number} delay before this tween will start, defaults to 0 (no delay) - * @param [loop] {bool} Should the tween automatically restart once complete? (ignores any chained tweens) - * @return {Tween} Itself. + * + * @method to + * @param {object} properties - Properties you want to tween. + * @param {number} duration - Duration of this tween. + * @param {function} ease - Easing function. + * @param {bool} autoStart - Whether this tween will start automatically or not. + * @param {number} delay - Delay before this tween will start, defaults to 0 (no delay). + * @param {bool} repeat - Should the tween automatically restart once complete? (ignores any chained tweens). + * @param {Phaser.Tween} yoyo - Description. + * @return {Phaser.Tween} Itself. */ to: function ( properties, duration, ease, autoStart, delay, repeat, yoyo ) { @@ -109,6 +237,13 @@ Phaser.Tween.prototype = { }, + /** + * Description. + * + * @method start + * @param {number} time - Description. + * @return {Phaser.Tween} Itself. + */ start: function ( time ) { if (this.game === null || this._object === null) { @@ -155,6 +290,12 @@ Phaser.Tween.prototype = { }, + /** + * Description. + * + * @method stop + * @return {Phaser.Tween} Itself. + */ stop: function () { this._manager.remove(this); @@ -164,6 +305,13 @@ Phaser.Tween.prototype = { }, + /** + * Description. + * + * @method delay + * @param {number} amount - Description. + * @return {Phaser.Tween} Itself. + */ delay: function ( amount ) { this._delayTime = amount; @@ -171,6 +319,13 @@ Phaser.Tween.prototype = { }, + /** + * Description. + * + * @method repeat + * @param {number} times - How many times to repeat. + * @return {Phaser.Tween} Itself. + */ repeat: function ( times ) { this._repeat = times; @@ -178,6 +333,13 @@ Phaser.Tween.prototype = { }, + /** + * Description. + * + * @method yoyo + * @param {Phaser.Tween} yoyo - Description. + * @return {Phaser.Tween} Itself. + */ yoyo: function( yoyo ) { this._yoyo = yoyo; @@ -185,6 +347,13 @@ Phaser.Tween.prototype = { }, + /** + * Set easing function. + * + * @method easing + * @param {function} easing - Description. + * @return {Phaser.Tween} Itself. + */ easing: function ( easing ) { this._easingFunction = easing; @@ -192,6 +361,13 @@ Phaser.Tween.prototype = { }, + /** + * Set interpolation function. + * + * @method interpolation + * @param {function} interpolation - Description. + * @return {Phaser.Tween} Itself. + */ interpolation: function ( interpolation ) { this._interpolationFunction = interpolation; @@ -199,6 +375,12 @@ Phaser.Tween.prototype = { }, + /** + * Description. + * + * @method chain + * @return {Phaser.Tween} Itself. + */ chain: function () { this._chainedTweens = arguments; @@ -215,7 +397,7 @@ Phaser.Tween.prototype = { * .to({ x: 0 }, 1000, Phaser.Easing.Linear.None) * .to({ y: 0 }, 1000, Phaser.Easing.Linear.None) * .loop(); - * + * @method loop * @return {Tween} Itself. */ loop: function() { @@ -223,6 +405,13 @@ Phaser.Tween.prototype = { return this; }, + /** + * Description. + * + * @method onStartCallback + * @param {object} callback - Description. + * @return {Phaser.Tween} Itself. + */ onStartCallback: function ( callback ) { this._onStartCallback = callback; @@ -230,6 +419,13 @@ Phaser.Tween.prototype = { }, + /** + * Description. + * + * @method onUpdateCallback + * @param {object} callback - Description. + * @return {Phaser.Tween} Itself. + */ onUpdateCallback: function ( callback ) { this._onUpdateCallback = callback; @@ -237,6 +433,13 @@ Phaser.Tween.prototype = { }, + /** + * Description. + * + * @method onCompleteCallback + * @param {object} callback - Description. + * @return {Phaser.Tween} Itself. + */ onCompleteCallback: function ( callback ) { this._onCompleteCallback = callback; @@ -244,19 +447,32 @@ Phaser.Tween.prototype = { }, - pause: function () { - this._paused = true; - this._pausedTime = this.game.time.now; - }, + /** + * Pause. + * + * @method pause + */ + pause: function () { + this._paused = true; + }, - resume: function () { - - this._paused = false; - - this._startTime += (this.game.time.now - this._pausedTime); - - }, + /** + * Resume. + * + * @method resume + */ + resume: function () { + this._paused = false; + this._startTime += this.game.time.pauseDuration; + }, + /** + * Description. + * + * @method update + * @param {number} time - Description. + * @return {bool} Description. + */ update: function ( time ) { if (this.pendingDelete) diff --git a/src/tween/TweenManager.js b/src/tween/TweenManager.js index e4c0963f..23cc4b2c 100644 --- a/src/tween/TweenManager.js +++ b/src/tween/TweenManager.js @@ -1,18 +1,44 @@ +/** +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} +* @module Phaser.TweenManager +*/ + + /** * Phaser - TweenManager -* +* +* @class Phaser.TweenManager +* @classdesc * Phaser.Game has a single instance of the TweenManager through which all Tween objects are created and updated. * Tweens are hooked into the game clock and pause system, adjusting based on the game state. * -* TweenManager is based heavily on tween.js by sole (http://soledadpenades.com). +* TweenManager is based heavily on tween.js by {@link http://soledadpenades.com|sole}. * The difference being that tweens belong to a games instance of TweenManager, rather than to a global TWEEN object. * It also has callbacks swapped for Signals and a few issues patched with regard to properties and completion errors. -* Please see https://github.com/sole/tween.js for a full list of contributors. +* Please see {@link https://github.com/sole/tween.js} for a full list of contributors. +* @constructor +* +* @param {Phaser.Game} game - A reference to the currently running game. */ Phaser.TweenManager = function (game) { + /** + * @property {Phaser.Game} game - Local reference to game. + */ this.game = game; + + /** + * @property {array} _tweens - Description. + * @private + */ this._tweens = []; + + /** + * @property {array} _add - Description. + * @private + */ this._add = []; this.game.onPause.add(this.pauseAll, this); @@ -22,11 +48,17 @@ Phaser.TweenManager = function (game) { Phaser.TweenManager.prototype = { + /** + * Description. + * @property {string} REVISION + * @default + */ REVISION: '11dev', /** * Get all the tween objects in an array. - * @return {Phaser.Tween[]} Array with all tween objects. + * @method getAll + * @returns {Phaser.Tween[]} Array with all tween objects. */ getAll: function () { @@ -36,19 +68,20 @@ Phaser.TweenManager.prototype = { /** * Remove all tween objects. + * @method removeAll */ removeAll: function () { - this._add.length = 0; - this._tweens.length = 0; + this._tweens = []; }, /** * Add a new tween into the TweenManager. * - * @param tween {Phaser.Tween} The tween object you want to add. - * @return {Phaser.Tween} The tween object you added to the manager. + * @method add + * @param {Phaser.Tween} tween - The tween object you want to add. + * @returns {Phaser.Tween} The tween object you added to the manager. */ add: function ( tween ) { @@ -57,11 +90,12 @@ Phaser.TweenManager.prototype = { }, /** - * Create a tween object for a specific object. The object can be any JavaScript object or Phaser object such as Sprite. - * - * @param obj {object} Object the tween will be run on. - * @return {Phaser.Tween} The newly created tween object. - */ + * Create a tween object for a specific object. The object can be any JavaScript object or Phaser object such as Sprite. + * + * @method create + * @param {Object} object - Object the tween will be run on. + * @returns {Phaser.Tween} The newly created tween object. + */ create: function (object) { return new Phaser.Tween(object, this.game); @@ -71,7 +105,8 @@ Phaser.TweenManager.prototype = { /** * Remove a tween from this manager. * - * @param tween {Phaser.Tween} The tween object you want to remove. + * @method remove + * @param {Phaser.Tween} tween - The tween object you want to remove. */ remove: function ( tween ) { @@ -88,7 +123,8 @@ Phaser.TweenManager.prototype = { /** * Update all the tween objects you added to this manager. * - * @return {bool} Return false if there's no tween to update, otherwise return true. + * @method update + * @returns {bool} Return false if there's no tween to update, otherwise return true. */ update: function () { @@ -126,8 +162,10 @@ Phaser.TweenManager.prototype = { /** * Pauses all currently running tweens. + * + * @method update */ - pauseAll: function () { + pauseAll: function () { for (var i = this._tweens.length - 1; i >= 0; i--) { this._tweens[i].pause(); @@ -137,8 +175,10 @@ Phaser.TweenManager.prototype = { /** * Pauses all currently paused tweens. + * + * @method resumeAll */ - resumeAll: function () { + resumeAll: function () { for (var i = this._tweens.length - 1; i >= 0; i--) { this._tweens[i].resume(); diff --git a/src/utils/Color.js b/src/utils/Color.js index 9c489aa9..a3852434 100644 --- a/src/utils/Color.js +++ b/src/utils/Color.js @@ -1,48 +1,53 @@ +/** +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} +* @module Phaser.Colors +*/ + + /** * A collection of methods useful for manipulating and comparing colors. * -* @class Color -* @author Richard Davey -* @copyright 2013 Photon Storm Ltd. -* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License -* @module Phaser +* @class Phaser.Color */ + Phaser.Color = { - /** - * Given an alpha and 3 color values this will return an integer representation of it + /** + * Given an alpha and 3 color values this will return an integer representation of it. * * @method getColor32 - * @param {Number} alpha The Alpha value (between 0 and 255) - * @param {Number} red The Red channel value (between 0 and 255) - * @param {Number} green The Green channel value (between 0 and 255) - * @param {Number} blue The Blue channel value (between 0 and 255) - * @return {Number} A native color value integer (format: 0xAARRGGBB) + * @param {number} alpha - The Alpha value (between 0 and 255). + * @param {number} red - The Red channel value (between 0 and 255). + * @param {number} green - The Green channel value (between 0 and 255). + * @param {number} blue - The Blue channel value (between 0 and 255). + * @returns {number} A native color value integer (format: 0xAARRGGBB). */ getColor32: function (alpha, red, green, blue) { return alpha << 24 | red << 16 | green << 8 | blue; }, - /** + /** * Given 3 color values this will return an integer representation of it. * * @method getColor - * @param {Number} red The Red channel value (between 0 and 255) - * @param {Number} green The Green channel value (between 0 and 255) - * @param {Number} blue The Blue channel value (between 0 and 255) - * @return {Number} A native color value integer (format: 0xRRGGBB) + * @param {number} red - The Red channel value (between 0 and 255). + * @param {number} green - The Green channel value (between 0 and 255). + * @param {number} blue - The Blue channel value (between 0 and 255). + * @returns {number} A native color value integer (format: 0xRRGGBB). */ getColor: function (red, green, blue) { return red << 16 | green << 8 | blue; }, - /** + /** * Converts the given hex string into an object containing the RGB values. * * @method hexToRGB - * @param {String} The string hex color to convert. - * @return {Object} An object with 3 properties: r,g and b. + * @param {string}h - The string hex color to convert. + * @returns {object} An object with 3 properties: r,g and b. */ hexToRGB: function (h) { @@ -55,13 +60,13 @@ Phaser.Color = { }, - /** + /** * Returns a string containing handy information about the given color including string hex value, * RGB format information and HSL information. Each section starts on a newline, 3 lines in total. * * @method getColorInfo - * @param {Number} color A color value in the format 0xAARRGGBB - * @return {String} string containing the 3 lines of information + * @param {number} color - A color value in the format 0xAARRGGBB. + * @returns {string}String containing the 3 lines of information. */ getColorInfo: function (color) { var argb = Phaser.Color.getRGB(color); @@ -75,36 +80,36 @@ Phaser.Color = { return result; }, - /** - * Return a string representation of the color in the format 0xAARRGGBB + /** + * Return a string representation of the color in the format 0xAARRGGBB. * * @method RGBtoHexstring - * @param {Number} color The color to get the string representation for - * @return {String A string of length 10 characters in the format 0xAARRGGBB + * @param {number} color - The color to get the string representation for + * @returns {String A string of length 10 characters in the format 0xAARRGGBB */ RGBtoHexstring: function (color) { var argb = Phaser.Color.getRGB(color); return "0x" + Phaser.Color.colorToHexstring(argb.alpha) + Phaser.Color.colorToHexstring(argb.red) + Phaser.Color.colorToHexstring(argb.green) + Phaser.Color.colorToHexstring(argb.blue); }, - /** - * Return a string representation of the color in the format #RRGGBB + /** + * Return a string representation of the color in the format #RRGGBB. * * @method RGBtoWebstring - * @param {Number} color The color to get the string representation for - * @return {String} A string of length 10 characters in the format 0xAARRGGBB + * @param {number} color - The color to get the string representation for. + * @returns {string}A string of length 10 characters in the format 0xAARRGGBB. */ RGBtoWebstring: function (color) { var argb = Phaser.Color.getRGB(color); return "#" + Phaser.Color.colorToHexstring(argb.red) + Phaser.Color.colorToHexstring(argb.green) + Phaser.Color.colorToHexstring(argb.blue); }, - /** - * Return a string containing a hex representation of the given color + /** + * Return a string containing a hex representation of the given color. * * @method colorToHexstring - * @param {Number} color The color channel to get the hex value for, must be a value between 0 and 255) - * @return {String} A string of length 2 characters, i.e. 255 = FF, 0 = 00 + * @param {number} color - The color channel to get the hex value for, must be a value between 0 and 255). + * @returns {string}A string of length 2 characters, i.e. 255 = FF, 0 = 00. */ colorToHexstring: function (color) { var digits = "0123456789ABCDEF"; @@ -114,15 +119,15 @@ Phaser.Color = { return hexified; }, - /** + /** * Interpolates the two given colours based on the supplied step and currentStep properties. * @method interpolateColor - * @param {Number} color1 - * @param {Number} color2 - * @param {Number} steps - * @param {Number} currentStep - * @param {Number} alpha - * @return {Number} The interpolated color value. + * @param {number} color1 - Description. + * @param {number} color2 - Description. + * @param {number} steps - Description. + * @param {number} currentStep - Description. + * @param {number} alpha - Description. + * @returns {number} The interpolated color value. */ interpolateColor: function (color1, color2, steps, currentStep, alpha) { if (typeof alpha === "undefined") { alpha = 255; } @@ -134,16 +139,16 @@ Phaser.Color = { return Phaser.Color.getColor32(alpha, r, g, b); }, - /** + /** * Interpolates the two given colours based on the supplied step and currentStep properties. * @method interpolateColorWithRGB - * @param {Number} color - * @param {Number} r - * @param {Number} g - * @param {Number} b - * @param {Number} steps - * @param {Number} currentStep - * @return {Number} The interpolated color value. + * @param {number} color - Description. + * @param {number} r - Description. + * @param {number} g - Description. + * @param {number} b - Description. + * @param {number} steps - Description. + * @param {number} currentStep - Description. + * @returns {number} The interpolated color value. */ interpolateColorWithRGB: function (color, r, g, b, steps, currentStep) { var src = Phaser.Color.getRGB(color); @@ -153,18 +158,18 @@ Phaser.Color = { return Phaser.Color.getColor(or, og, ob); }, - /** + /** * Interpolates the two given colours based on the supplied step and currentStep properties. * @method interpolateRGB - * @param {Number} r1 - * @param {Number} g1 - * @param {Number} b1 - * @param {Number} r2 - * @param {Number} g2 - * @param {Number} b2 - * @param {Number} steps - * @param {Number} currentStep - * @return {Number} The interpolated color value. + * @param {number} r1 - Description. + * @param {number} g1 - Description. + * @param {number} b1 - Description. + * @param {number} r2 - Description. + * @param {number} g2 - Description. + * @param {number} b2 - Description. + * @param {number} steps - Description. + * @param {number} currentStep - Description. + * @returns {number} The interpolated color value. */ interpolateRGB: function (r1, g1, b1, r2, g2, b2, steps, currentStep) { var r = (((r2 - r1) * currentStep) / steps) + r1; @@ -173,16 +178,16 @@ Phaser.Color = { return Phaser.Color.getColor(r, g, b); }, - /** + /** * Returns a random color value between black and white *

Set the min value to start each channel from the given offset.

*

Set the max value to restrict the maximum color used per channel

* * @method getRandomColor - * @param {Number} min The lowest value to use for the color - * @param {Number} max The highest value to use for the color - * @param {Number} alpha The alpha value of the returning color (default 255 = fully opaque) - * @return {Number} 32-bit color value with alpha + * @param {number} min - The lowest value to use for the color. + * @param {number} max - The highest value to use for the color. + * @param {number} alpha - The alpha value of the returning color (default 255 = fully opaque). + * @returns {number} 32-bit color value with alpha. */ getRandomColor: function (min, max, alpha) { if (typeof min === "undefined") { min = 0; } @@ -201,14 +206,14 @@ Phaser.Color = { return Phaser.Color.getColor32(alpha, red, green, blue); }, - /** + /** * Return the component parts of a color as an Object with the properties alpha, red, green, blue * *

Alpha will only be set if it exist in the given color (0xAARRGGBB)

* * @method getRGB - * @param {Number} color in RGB (0xRRGGBB) or ARGB format (0xAARRGGBB) - * @return {Object} An Object with properties: alpha, red, green, blue + * @param {number} color - Color in RGB (0xRRGGBB) or ARGB format (0xAARRGGBB). + * @returns {object} An Object with properties: alpha, red, green, blue. */ getRGB: function (color) { return { @@ -219,11 +224,11 @@ Phaser.Color = { }; }, - /** + /** * Returns a CSS friendly string value from the given color. * @method getWebRGB - * @param {Number} color - * @return {String} A string in the format: 'rgba(r,g,b,a)' + * @param {number} color + * @returns {string}A string in the format: 'rgba(r,g,b,a)' */ getWebRGB: function (color) { var alpha = (color >>> 24) / 255; @@ -233,56 +238,56 @@ Phaser.Color = { return 'rgba(' + red.toString() + ',' + green.toString() + ',' + blue.toString() + ',' + alpha.toString() + ')'; }, - /** - * Given a native color value (in the format 0xAARRGGBB) this will return the Alpha component, as a value between 0 and 255 + /** + * Given a native color value (in the format 0xAARRGGBB) this will return the Alpha component, as a value between 0 and 255. * * @method getAlpha - * @param {Number} color In the format 0xAARRGGBB - * @return {Number} The Alpha component of the color, will be between 0 and 1 (0 being no Alpha (opaque), 1 full Alpha (transparent)) + * @param {number} color - In the format 0xAARRGGBB. + * @returns {number} The Alpha component of the color, will be between 0 and 1 (0 being no Alpha (opaque), 1 full Alpha (transparent)). */ getAlpha: function (color) { return color >>> 24; }, - /** - * Given a native color value (in the format 0xAARRGGBB) this will return the Alpha component as a value between 0 and 1 + /** + * Given a native color value (in the format 0xAARRGGBB) this will return the Alpha component as a value between 0 and 1. * * @method getAlphaFloat - * @param {Number} color In the format 0xAARRGGBB - * @return {Number} The Alpha component of the color, will be between 0 and 1 (0 being no Alpha (opaque), 1 full Alpha (transparent)) + * @param {number} color - In the format 0xAARRGGBB. + * @returns {number} The Alpha component of the color, will be between 0 and 1 (0 being no Alpha (opaque), 1 full Alpha (transparent)). */ getAlphaFloat: function (color) { return (color >>> 24) / 255; }, - /** - * Given a native color value (in the format 0xAARRGGBB) this will return the Red component, as a value between 0 and 255 + /** + * Given a native color value (in the format 0xAARRGGBB) this will return the Red component, as a value between 0 and 255. * * @method getRed - * @param {Number} color In the format 0xAARRGGBB - * @return {Number} The Red component of the color, will be between 0 and 255 (0 being no color, 255 full Red) + * @param {number} color In the format 0xAARRGGBB. + * @returns {number} The Red component of the color, will be between 0 and 255 (0 being no color, 255 full Red). */ getRed: function (color) { return color >> 16 & 0xFF; }, - /** - * Given a native color value (in the format 0xAARRGGBB) this will return the Green component, as a value between 0 and 255 + /** + * Given a native color value (in the format 0xAARRGGBB) this will return the Green component, as a value between 0 and 255. * * @method getGreen - * @param {Number} color In the format 0xAARRGGBB - * @return {Number} The Green component of the color, will be between 0 and 255 (0 being no color, 255 full Green) + * @param {number} color - In the format 0xAARRGGBB. + * @returns {number} The Green component of the color, will be between 0 and 255 (0 being no color, 255 full Green). */ getGreen: function (color) { return color >> 8 & 0xFF; }, - /** - * Given a native color value (in the format 0xAARRGGBB) this will return the Blue component, as a value between 0 and 255 + /** + * Given a native color value (in the format 0xAARRGGBB) this will return the Blue component, as a value between 0 and 255. * * @method getBlue - * @param {Number} color In the format 0xAARRGGBB - * @return {Number} The Blue component of the color, will be between 0 and 255 (0 being no color, 255 full Blue) + * @param {number} color - In the format 0xAARRGGBB. + * @returns {number} The Blue component of the color, will be between 0 and 255 (0 being no color, 255 full Blue). */ getBlue: function (color) { return color & 0xFF; diff --git a/src/utils/Debug.js b/src/utils/Debug.js index 6516684e..8e5baea4 100644 --- a/src/utils/Debug.js +++ b/src/utils/Debug.js @@ -1,38 +1,73 @@ /** * @author Richard Davey * @copyright 2013 Photon Storm Ltd. -* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License -* @module Phaser +* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} +* @module Phaser.Debug */ /** * A collection of methods for displaying debug information about game objects. * -* @class DebugUtils +* @class Phaser.Utils.Debug +* @constructor +* @param {Phaser.Game} game - A reference to the currently running game. */ Phaser.Utils.Debug = function (game) { + /** + * @property {Phaser.Game} game - A reference to the currently running Game. + */ this.game = game; + + /** + * @property {Context} context - Description. + */ this.context = game.context; + /** + * @property {string} font - Description. + * @default '14px Courier' + */ this.font = '14px Courier'; + + /** + * @property {number} lineHeight - Description. + */ this.lineHeight = 16; + + /** + * @property {bool} renderShadow - Description. + */ this.renderShadow = true; + + /** + * @property {Context} currentX - Description. + * @default + */ this.currentX = 0; + + /** + * @property {number} currentY - Description. + * @default + */ this.currentY = 0; + + /** + * @property {number} currentAlpha - Description. + * @default + */ this.currentAlpha = 1; }; Phaser.Utils.Debug.prototype = { - /** * Internal method that resets the debug output values. * @method start - * @param {Number} x The X value the debug info will start from. - * @param {Number} y The Y value the debug info will start from. - * @param {String} color The color the debug info will drawn in. + * @param {number} x - The X value the debug info will start from. + * @param {number} y - The Y value the debug info will start from. + * @param {string} color - The color the debug info will drawn in. */ start: function (x, y, color) { @@ -72,9 +107,9 @@ Phaser.Utils.Debug.prototype = { /** * Internal method that outputs a single line of text. * @method line - * @param {String} text The line of text to draw. - * @param {Number} x The X value the debug info will start from. - * @param {Number} y The Y value the debug info will start from. + * @param {string} text - The line of text to draw. + * @param {number} x - The X value the debug info will start from. + * @param {number} y - The Y value the debug info will start from. */ line: function (text, x, y) { @@ -106,6 +141,12 @@ Phaser.Utils.Debug.prototype = { }, + /** + * Description. + * @method renderQuadTree + * @param {Description} quadtree - Description. + * @param {string} color - Description. + */ renderQuadTree: function (quadtree, color) { color = color || 'rgba(255,0,0,0.3)'; @@ -140,6 +181,14 @@ Phaser.Utils.Debug.prototype = { }, + /** + * Description. + * @method renderSpriteCorners + * @param {Phaser.Sprite} sprite - The sprite to be rendered. + * @param {bool} showText - Description. + * @param {bool} showBounds - Description. + * @param {string} color - Description. + */ renderSpriteCorners: function (sprite, showText, showBounds, color) { if (this.context == null) @@ -189,10 +238,12 @@ Phaser.Utils.Debug.prototype = { }, /** - * Render debug infos. (including id, position, rotation, scrolling factor, worldBounds and some other properties) - * @param x {number} X position of the debug info to be rendered. - * @param y {number} Y position of the debug info to be rendered. - * @param [color] {number} color of the debug info to be rendered. (format is css color string) + * Render debug infos (including id, position, rotation, scrolling factor, worldBounds and some other properties). + * @method renderSoundInfo + * @param {Description} sound - Description. + * @param {number} x - X position of the debug info to be rendered. + * @param {number} y - Y position of the debug info to be rendered. + * @param {string} [color] - color of the debug info to be rendered. (format is css color string). */ renderSoundInfo: function (sound, x, y, color) { @@ -225,9 +276,11 @@ Phaser.Utils.Debug.prototype = { /** * Render debug infos. (including id, position, rotation, scrolling factor, worldBounds and some other properties) - * @param x {number} X position of the debug info to be rendered. - * @param y {number} Y position of the debug info to be rendered. - * @param [color] {number} color of the debug info to be rendered. (format is css color string) + * @method renderCameraInfo + * @param {Description} camera - Description. + * @param {number} x - X position of the debug info to be rendered. + * @param {number} y - Y position of the debug info to be rendered. + * @param {string} [color] - color of the debug info to be rendered (format is css color string) */ renderCameraInfo: function (camera, x, y, color) { @@ -248,6 +301,11 @@ Phaser.Utils.Debug.prototype = { /** * Renders the Pointer.circle object onto the stage in green if down or red if up. * @method renderDebug + * @param {Description} pointer - Description. + * @param {bool} hideIfUp - Description. + * @param {string} downColor - Description. + * @param {string} upColor - Description. + * @param {string} color - Description. */ renderPointer: function (pointer, hideIfUp, downColor, upColor, color) { @@ -301,10 +359,12 @@ Phaser.Utils.Debug.prototype = { }, /** - * Render Sprite Input Debug information - * @param x {number} X position of the debug info to be rendered. - * @param y {number} Y position of the debug info to be rendered. - * @param [color] {number} color of the debug info to be rendered. (format is css color string) + * Render Sprite Input Debug information. + * @method renderSpriteInputInfo + * @param {Phaser.Sprite} sprite - The sprite to be rendered. + * @param {number} x - X position of the debug info to be rendered. + * @param {number} y - Y position of the debug info to be rendered. + * @param {string} [color] - color of the debug info to be rendered (format is css color string). */ renderSpriteInputInfo: function (sprite, x, y, color) { @@ -320,6 +380,14 @@ Phaser.Utils.Debug.prototype = { }, + /** + * Render Sprite collision. + * @method renderSpriteCollision + * @param {Phaser.Sprite} sprite - The sprite to be rendered. + * @param {number} x - X position of the debug info to be rendered. + * @param {number} y - Y position of the debug info to be rendered. + * @param {string} [color] - color of the debug info to be rendered (format is css color string). + */ renderSpriteCollision: function (sprite, x, y, color) { color = color || 'rgb(255,255,255)'; @@ -338,9 +406,10 @@ Phaser.Utils.Debug.prototype = { /** * Render debug information about the Input object. - * @param x {number} X position of the debug info to be rendered. - * @param y {number} Y position of the debug info to be rendered. - * @param [color] {number} color of the debug info to be rendered. (format is css color string) + * @method renderInputInfo + * @param {number} x - X position of the debug info to be rendered. + * @param {number} y - Y position of the debug info to be rendered. + * @param {string} [color] - color of the debug info to be rendered. (format is css color string) */ renderInputInfo: function (x, y, color) { @@ -362,10 +431,12 @@ Phaser.Utils.Debug.prototype = { }, /** - * Render debug infos. (including name, bounds info, position and some other properties) - * @param x {number} X position of the debug info to be rendered. - * @param y {number} Y position of the debug info to be rendered. - * @param [color] {number} color of the debug info to be rendered. (format is css color string) + * Render debug infos (including name, bounds info, position and some other properties). + * @method renderSpriteInfo + * @param {Phaser.Sprite} sprite - Description. + * @param {number} x - X position of the debug info to be rendered. + * @param {number} y - Y position of the debug info to be rendered. + * @param {string} [color] - Color of the debug info to be rendered (format is css color string). */ renderSpriteInfo: function (sprite, x, y, color) { @@ -391,6 +462,7 @@ Phaser.Utils.Debug.prototype = { // 4 = scaleY // 5 = translateY + // this.line('id: ' + sprite._id); // this.line('scale x: ' + sprite.worldTransform[0]); // this.line('scale y: ' + sprite.worldTransform[4]); @@ -407,6 +479,14 @@ Phaser.Utils.Debug.prototype = { }, + /** + * Render debug infos (including name, bounds info, position and some other properties). + * @method renderWorldTransformInfo + * @param {Phaser.Sprite} sprite - Description. + * @param {number} x - X position of the debug info to be rendered. + * @param {number} y - Y position of the debug info to be rendered. + * @param {string} [color] - Color of the debug info to be rendered (format is css color string). + */ renderWorldTransformInfo: function (sprite, x, y, color) { if (this.context == null) @@ -428,6 +508,14 @@ Phaser.Utils.Debug.prototype = { }, + /** + * Description. + * @method renderLocalTransformInfo + * @param {Phaser.Sprite} sprite - Description. + * @param {number} x - X position of the debug info to be rendered. + * @param {number} y - Y position of the debug info to be rendered. + * @param {string} [color] - Color of the debug info to be rendered (format is css color string). + */ renderLocalTransformInfo: function (sprite, x, y, color) { if (this.context == null) @@ -451,6 +539,14 @@ Phaser.Utils.Debug.prototype = { }, + /** + * Description. + * @method renderPointInfo + * @param {Phaser.Sprite} sprite - Description. + * @param {number} x - X position of the debug info to be rendered. + * @param {number} y - Y position of the debug info to be rendered. + * @param {string} [color] - Color of the debug info to be rendered (format is css color string). + */ renderPointInfo: function (point, x, y, color) { if (this.context == null) @@ -466,7 +562,13 @@ Phaser.Utils.Debug.prototype = { }, - renderSpriteBody: function (sprite, color) { + /** + * Description. + * @method renderSpriteBounds + * @param {Phaser.Sprite} sprite - Description. + * @param {string} [color] - Color of the debug info to be rendered (format is css color string). + */ + renderSpriteBounds: function (sprite, color) { if (this.context == null) { @@ -512,6 +614,13 @@ Phaser.Utils.Debug.prototype = { }, + /** + * Description. + * @method renderPixel + * @param {number} x - X position of the debug info to be rendered. + * @param {number} y - Y position of the debug info to be rendered. + * @param {string} fillStyle - Description. + */ renderPixel: function (x, y, fillStyle) { if (this.context == null) @@ -528,6 +637,12 @@ Phaser.Utils.Debug.prototype = { }, + /** + * Description. + * @method renderPoint + * @param {Description} point - Description. + * @param {string} fillStyle - Description. + */ renderPoint: function (point, fillStyle) { if (this.context == null) @@ -544,6 +659,12 @@ Phaser.Utils.Debug.prototype = { }, + /** + * Description. + * @method renderRectangle + * @param {Description} rect - Description. + * @param {string} fillStyle - Description. + */ renderRectangle: function (rect, fillStyle) { if (this.context == null) @@ -560,6 +681,12 @@ Phaser.Utils.Debug.prototype = { }, + /** + * Description. + * @method renderCircle + * @param {Description} circle - Description. + * @param {string} fillStyle - Description. + */ renderCircle: function (circle, fillStyle) { if (this.context == null) @@ -580,10 +707,13 @@ Phaser.Utils.Debug.prototype = { }, /** - * Render text - * @param x {number} X position of the debug info to be rendered. - * @param y {number} Y position of the debug info to be rendered. - * @param [color] {number} color of the debug info to be rendered. (format is css color string) + * Render text. + * @method renderText + * @param {string} text - The line of text to draw. + * @param{number} x - X position of the debug info to be rendered. + * @param {number} y - Y position of the debug info to be rendered. + * @param {string} [color] - Color of the debug info to be rendered (format is css color string). + * @param {string} font - The font of text to draw. */ renderText: function (text, x, y, color, font) { diff --git a/src/utils/Utils.js b/src/utils/Utils.js index 8be83b21..8fc83814 100644 --- a/src/utils/Utils.js +++ b/src/utils/Utils.js @@ -1,7 +1,7 @@ /** * @author Richard Davey * @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.Utils */ @@ -13,15 +13,15 @@ Phaser.Utils = { /** - * Javascript string pad - * http://www.webtoolkit.info/ - * pad = the string to pad it out with (defaults to a space) + * Javascript string pad ({@link http://www.webtoolkit.info/}) + * pad = the string to pad it out with (defaults to a space)
* dir = 1 (left), 2 (right), 3 (both) * @method pad - * @param {string} str the target string - * @param {number} pad the string to pad it out with (defaults to a space) - * @param {number} len - * @param {number} [dir=3] the direction dir = 1 (left), 2 (right), 3 (both) + * @param {string} str - The target string. + * @param {number} len - Description. + * @param {number} pad - the string to pad it out with (defaults to a space). + * @param {number} [dir=3] the direction dir = 1 (left), 2 (right), 3 (both). + * @return {string} **/ pad: function (str, len, pad, dir) { @@ -53,10 +53,11 @@ Phaser.Utils = { }, - /** - * This is a slightly modified version of jQuery.isPlainObject + /** + * This is a slightly modified version of jQuery.isPlainObject. * @method isPlainObject - * @param {object} obj + * @param {object} obj - Description. + * @return {bool} - Description. */ isPlainObject: function (obj) { @@ -87,12 +88,17 @@ Phaser.Utils = { return true; }, - /** - * This is a slightly modified version of jQuery.extend (http://api.jquery.com/jQuery.extend/) + + // deep, target, objects to copy to the target object + // This is a slightly modified version of {@link http://api.jquery.com/jQuery.extend/|jQuery.extend} + // deep (boolean) + // target (object to add to) + // objects ... (objects to recurse and copy from) + + /** + * This is a slightly modified version of {@link http://api.jquery.com/jQuery.extend/|jQuery.extend} * @method extend - * @param {bool} [deep] If true, the merge becomes recursive (aka. deep copy). - * @param {object} target The object to add to - * @param {object} objets Objects to recurse and copy from + * @return {Description} Description. */ extend: function () { @@ -173,7 +179,7 @@ Phaser.Utils = { * Converts a hex color number to an [R, G, B] array * * @method HEXtoRGB - * @param {Number} hex + * @param {number} hex * @return {array} */ function HEXtoRGB(hex) {