diff --git a/Docs/Documentation Checklist.xlsx b/Docs/Documentation Checklist.xlsx index 09a7b447..292dcd33 100644 Binary files a/Docs/Documentation Checklist.xlsx and b/Docs/Documentation Checklist.xlsx differ diff --git a/examples/camera/follow styles.php b/examples/camera/follow styles.php new file mode 100644 index 00000000..dac30a44 --- /dev/null +++ b/examples/camera/follow styles.php @@ -0,0 +1,139 @@ + + + + + + diff --git a/examples/camera/moving the game camera.php b/examples/camera/moving the game camera.php index d1dcb921..28edd32e 100644 --- a/examples/camera/moving the game camera.php +++ b/examples/camera/moving the game camera.php @@ -21,13 +21,11 @@ //setting the size of the game world larger than the tilemap's size game.world.setSize(2000,2000); - // game.camera.width=150; - // game.camera.height=150; - game.stage.backgroundColor = '#255d3b'; // adding the tilemap - game.add.tilemap(0, 168, 'snes'); + game.add.tilemap(0, 150, 'snes'); + } diff --git a/examples/camera/world sprite.php b/examples/camera/world sprite.php new file mode 100644 index 00000000..56244285 --- /dev/null +++ b/examples/camera/world sprite.php @@ -0,0 +1,70 @@ + + + + + + diff --git a/examples/display/render crisp.php b/examples/display/render crisp.php index e5e1917a..90e337bb 100644 --- a/examples/display/render crisp.php +++ b/examples/display/render crisp.php @@ -7,7 +7,7 @@ (function () { - var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create }); + var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create }); function preload() { @@ -21,17 +21,21 @@ function create() { // For browsers that support it, this keeps our pixel art looking crisp - //Phaser.Canvas.setSmoothingEnabled(game.stage.canvas.context, false); + // This only works when you use Phaser.CANVAS as the renderer + Phaser.Canvas.setSmoothingEnabled(game.context, false); boss = game.add.sprite(game.world.centerX, game.world.centerY, 'boss'); boss.anchor.setTo(0.5, 0.5); - // Zoom in each time we press it + + // Zoom in each time we press the button button = game.add.button(32, 32, 'button', clickedIt, this, 2, 1, 0); } function clickedIt() { + boss.scale.x += 0.5; boss.scale.y += 0.5; + } })(); diff --git a/src/core/Camera.js b/src/core/Camera.js index b738e5f5..e5da9e26 100644 --- a/src/core/Camera.js +++ b/src/core/Camera.js @@ -1,65 +1,107 @@ /** -* Phaser - Camera +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License +* @module Phaser.Camera +*/ + +/** * * A Camera is your view into the game world. It has a position and size and renders only those objects within its field of view. * The game automatically creates a single Stage sized camera on boot. Move the camera around the world with Phaser.Camera.x/y * -* @class Phaser.Camera +* @class Camera * @constructor -* @param game {Phaser.Game} game reference to the currently running game. -* @param id {number} not being used at the moment, will be when Phaser supports multiple camera -* @param x {number} position of the camera on the X axis -* @param y {number} position of the camera on the Y axis -* @param width {number} the width of the view rectangle -* @param height {number} 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} + */ this.game = game; + + /** + * A reference to the game world + * @property world + * @public + * @type {Phaser.World} + */ this.world = game.world; - this.id = 0; // reserved for future multiple camera set-ups - - // 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?) + + /** + * reserved for future multiple camera set-ups + * @property id + * @public + * @type {number} + */ + this.id = 0; /** * Camera view. - * @type {Rectangle} + * 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} */ this.view = new Phaser.Rectangle(x, y, width, height); /** * Used by Sprites to work out Camera culling. - * @type {Rectangle} + * @property screenView + * @public + * @type {Phaser.Rectangle} */ this.screenView = new Phaser.Rectangle(x, y, width, height); /** * Sprite moving inside this Rectangle will not cause camera moving. - * @type {Rectangle} + * @property deadzone + * @type {Phaser.Rectangle} */ this.deadzone = null; /** * Whether this camera is visible or not. (default is true) + * @property visible + * @public + * @default true * @type {bool} */ this.visible = true; /** * Whether this camera is flush with the World Bounds or not. + * @property atLimit * @type {bool} */ this.atLimit = { x: false, y: false }; /** * If the camera is tracking a Sprite, this is a reference to it, otherwise null - * @type {Sprite} + * @property target + * @public + * @type {Phaser.Sprite} */ this.target = null; + /** + * Edge property + * @property edge + * @private + * @type {number} + */ this._edge = 0; }; @@ -74,8 +116,9 @@ Phaser.Camera.prototype = { /** * Tells this camera which sprite to follow. - * @param target {Sprite} The object you want the camera to track. Set to null to not follow anything. - * @param [style] {number} Leverage one of the existing "deadzone" presets. If you use a custom deadzone, ignore this parameter and manually specify the deadzone after calling follow(). + * @method follow + * @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) { @@ -112,9 +155,10 @@ Phaser.Camera.prototype = { }, /** - * Move the camera focus to this location instantly. - * @param x {number} X position. - * @param y {number} Y position. + * Move the camera focus to a location instantly. + * @method focusOnXY + * @param {number} x X position. + * @param {number} y Y position. */ focusOnXY: function (x, y) { @@ -125,6 +169,7 @@ Phaser.Camera.prototype = { /** * Update focusing and scrolling. + * @method update */ update: function () { @@ -172,6 +217,10 @@ Phaser.Camera.prototype = { }, + /** + * Method called to ensure the camera doesn't venture outside of the game world + * @method checkWorldBounds + */ checkWorldBounds: function () { this.atLimit.x = false; @@ -206,6 +255,14 @@ 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 + * + * @method setPosition + * @param {number} x X position. + * @param {number} y Y position. + */ setPosition: function (x, y) { this.view.x = x; @@ -214,6 +271,13 @@ Phaser.Camera.prototype = { }, + /** + * 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. + */ setSize: function (width, height) { this.view.width = width; @@ -225,10 +289,17 @@ Phaser.Camera.prototype = { 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(); @@ -238,10 +309,18 @@ Object.defineProperty(Phaser.Camera.prototype, "x", { 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(); @@ -251,10 +330,18 @@ Object.defineProperty(Phaser.Camera.prototype, "y", { 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; } @@ -263,10 +350,18 @@ Object.defineProperty(Phaser.Camera.prototype, "width", { 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/Stage.js b/src/core/Stage.js index 5a4e07e6..73ea9392 100644 --- a/src/core/Stage.js +++ b/src/core/Stage.js @@ -1,49 +1,97 @@ /** - * Stage - * - * The Stage controls the canvas on which everything is displayed. It handles display within the browser, - * focus handling, game resizing, scaling and the pause, boot and orientation screens. - * - * @package Phaser.Stage - * @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 https://github.com/photonstorm/phaser/blob/master/license.txt MIT License +* @module Phaser.Stage +*/ +/** +* +* The Stage controls the canvas on which everything is displayed. It handles display within the browser, +* focus handling, game resizing, scaling and the pause, boot and orientation screens. +* * @class Stage * @constructor -* @param game {Phaser.Game} game reference to the currently running game. -* @param width {number} width of the canvas element -* @param height {number} 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} + */ this.game = game; /** * Background color of the stage (defaults to black). Set via the public backgroundColor property. + * @property _backgroundColor + * @private * @type {string} */ this._backgroundColor = 'rgb(0,0,0)'; - // Get the offset values (for input and other things) + /** + * Get the offset values (for input and other things) + * @property offset + * @public + * @type {Phaser.Point} + */ this.offset = new Phaser.Point; - + + /** + * reference to the newly created element + * @property canvas + * @public + * @type {HTMLCanvasElement} + */ 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 + + /** + * The Pixi Stage which is hooked to the renderer + * @property _stage + * @private + * @type {PIXI.Stage} + */ this._stage = new PIXI.Stage(0x000000, false); this._stage.name = '_stage_root'; - + + /** + * The current scaleMode + * @property scaleMode + * @public + * @type {number} + */ this.scaleMode = Phaser.StageScaleMode.NO_SCALE; + + /** + * The scale of the current running game + * @property scale + * @public + * @type {Phaser.StageScaleMode} + */ this.scale = new Phaser.StageScaleMode(this.game, width, height); + + /** + * aspect ratio + * @property aspectRatio + * @public + * @type {number} + */ this.aspectRatio = width / height; }; Phaser.Stage.prototype = { + /** + * Initialises the stage and adds the event listeners + * @method boot + */ boot: function () { Phaser.Canvas.getOffset(this.canvas, this.offset); @@ -68,6 +116,8 @@ 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 */ visibilityChange: function (event) { @@ -93,10 +143,19 @@ Phaser.Stage.prototype = { 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/World.js b/src/core/World.js index 36319967..4fbbd8c6 100644 --- a/src/core/World.js +++ b/src/core/World.js @@ -1,5 +1,11 @@ /** - * World +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license 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 * @@ -7,50 +13,62 @@ * 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. * - * @package Phaser.World - * @author Richard Davey - * @copyright 2013 Photon Storm Ltd. - * @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License - * @class World * @constructor - * @param game {Phaser.Game} reference to the current game instance. + * @param {Phaser.Game} game Reference to the current game instance. */ Phaser.World = function (game) { /** - * Local reference to Game. - */ + * A reference to the currently running Game. + * @property game + * @public + * @type {Phaser.Game} + */ this.game = game; /** - * Bound of this world that objects can not escape from. - * @type {Rectangle} - */ + * Bound of this world that objects can not escape from. + * @property bounds + * @public + * @type {Phaser.Rectangle} + */ this.bounds = new Phaser.Rectangle(0, 0, game.width, game.height); /** - * Camera instance. - * @type {Camera} - */ + * Camera instance. + * @property camera + * @public + * @type {Phaser.Camera} + */ this.camera = null; /** - * Reset each frame, keeps a count of the total number of objects updated. - * @type {Number} - */ + * Reset each frame, keeps a count of the total number of objects updated. + * @property currentRenderOrderID + * @public + * @type {Number} + */ this.currentRenderOrderID = 0; /** - * Object container stores every object created with `create*` methods. - * @type {Group} - */ + * Object container stores every object created with `create*` methods. + * @property group + * @public + * @type {Phaser.Group} + */ this.group = null; }; Phaser.World.prototype = { + + /** + * Initialises the game world + * + * @method boot + */ boot: function () { this.camera = new Phaser.Camera(this.game, 0, 0, 0, this.game.width, this.game.height); @@ -62,8 +80,9 @@ Phaser.World.prototype = { }, /** - * This is called automatically every frame, and is where main logic happens. - */ + * This is called automatically every frame, and is where main logic happens. + * @method update + */ update: function () { this.camera.update(); @@ -96,8 +115,8 @@ Phaser.World.prototype = { /** * Updates the size of this world. * @method setSize - * @param width {number} New width of the world. - * @param height {number} 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) { @@ -134,10 +153,18 @@ Phaser.World.prototype = { Object.defineProperty(Phaser.World.prototype, "width", { + /** + * @method width + * @return {Number} The current width of the game world + */ get: function () { return this.bounds.width; }, + /** + * @method width + * @return {Number} Sets the width of the game world + */ set: function (value) { this.bounds.width = value; } @@ -146,10 +173,18 @@ Object.defineProperty(Phaser.World.prototype, "width", { 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; } @@ -158,6 +193,10 @@ Object.defineProperty(Phaser.World.prototype, "height", { 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; } @@ -166,6 +205,10 @@ Object.defineProperty(Phaser.World.prototype, "centerX", { 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; } @@ -174,6 +217,10 @@ Object.defineProperty(Phaser.World.prototype, "centerY", { 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); } @@ -182,6 +229,10 @@ Object.defineProperty(Phaser.World.prototype, "randomX", { 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/Button.js b/src/gameobjects/Button.js index 9aea5634..325fee20 100644 --- a/src/gameobjects/Button.js +++ b/src/gameobjects/Button.js @@ -1,20 +1,28 @@ +/** +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License +* @module Phaser.Button +*/ + /** * Create a new Button object. * @class Button * @constructor * -* @param game {Phaser.Game} Current game instance. -* @param [x] {number} X position of the button. -* @param [y] {number} Y position of the button. -* @param [key] {string} The image key as defined in the Game.Cache to use as the texture for this button. -* @param [callback] {function} The function to call when this button is pressed -* @param [callbackContext] {object} The context in which the callback will be called (usually 'this') -* @param [overFrame] {string|number} 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 [outFrame] {string|number} 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 [downFrame] {string|number} 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. +* @param {Phaser.Game} game Current game instance. +* @param {number} [x] X position of the button. +* @param {number} [y] Y position of the button. +* @param {string} [key] The image key as defined in the Game.Cache to use as the texture for this button. +* @param {function} [callback] The function to call when this button is pressed +* @param {object} [callbackContext] The context in which the callback will be called (usually 'this') +* @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 = function (game, x, y, key, callback, callbackContext, overFrame, outFrame, downFrame) { + x = x || 0; y = y || 0; key = key || null; @@ -65,11 +73,10 @@ Phaser.Button.prototype.constructor = Phaser.Button; * exactly like setting them in the constructor * * @method setFrames -* @param [overFrame] {string|number} 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 [outFrame] {string|number} 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 [downFrame] {string|number} 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. +* @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) { if (overFrame !== null) diff --git a/src/sound/Sound.js b/src/sound/Sound.js index e51264ae..d45543f7 100644 --- a/src/sound/Sound.js +++ b/src/sound/Sound.js @@ -3,26 +3,70 @@ * * @class Sound * @constructor -* @param game {Phaser.Game} reference to the current game instance. -* @param key {string} Asset key for the sound. -* @param volume {number} default value for the volume. -* @param loop {bool} 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) { volume = volume || 1; if (typeof loop == 'undefined') { loop = false; } + /** + * A reference to the currently running Game. + * @property game + * @public + * @type {Phaser.Game} + */ this.game = game; + + /** + * Name of the sound + * @property name + * @public + * @type {string} + */ this.name = ''; + + /** + * Asset key for the sound. + * @property key + * @public + * @type {string} + */ this.key = key; + + /** + * Whether or not the sound will loop. + * @property loop + * @public + * @type {bool} + */ this.loop = loop; + + /** + * The global audio volume. A value between 0 (silence) and 1 (full volume) + * @property _volume + * @private + * @type {number} + */ this._volume = volume; + + /** + * The sound markers, empty by default + * @property markers + * @public + * @type {object} + */ this.markers = {}; /** * Reference to AudioContext instance. + * @property context + * @public + * @type {AudioContext} */ this.context = null; @@ -31,9 +75,28 @@ Phaser.Sound = function (game, key, volume, loop) { */ this._buffer = null; + /** + * Boolean indicating whether the game is on "mute" + * @property _muted + * @private + * @type {bool} + */ this._muted = false; + /** + * Boolean indicating whether the sound should start automatically + * @property autoplay + * @public + * @type {bool} + */ this.autoplay = false; + + /** + * The total duration of the sound, in milliseconds + * @property autoplay + * @public + * @type {bool} + */ this.totalDuration = 0; this.startTime = 0; this.currentTime = 0; @@ -188,11 +251,11 @@ Phaser.Sound.prototype = { /** * Play this sound, or a marked section of it. - - * @param marker {string} Assets key of the sound you want to play. - * @param position {number} the starting position - * @param [volume] {number} volume of the sound you want to play. - * @param [loop] {bool} loop when it finished playing? (Default to false) + * @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) * @return {Sound} The playing sound object. */ play: function (marker, position, volume, loop, forceRestart) { @@ -366,6 +429,14 @@ 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) + */ restart: function (marker, position, volume, loop) { marker = marker || ''; @@ -377,6 +448,10 @@ Phaser.Sound.prototype = { }, + /** + * Pauses the sound + * @method pause + */ pause: function () { if (this.isPlaying && this._sound) @@ -388,7 +463,10 @@ Phaser.Sound.prototype = { } }, - + /** + * Resumes the sound + * @method pause + */ resume: function () { if (this.paused && this._sound) @@ -419,6 +497,7 @@ Phaser.Sound.prototype = { /** * Stop playing this sound. + * @method stop */ stop: function () { @@ -470,13 +549,20 @@ Object.defineProperty(Phaser.Sound.prototype, "isDecoded", { Object.defineProperty(Phaser.Sound.prototype, "mute", { - /** - * Mute sounds. + + /** + * 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; @@ -518,10 +604,18 @@ Object.defineProperty(Phaser.Sound.prototype, "mute", { 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 88501bbb..5464b6f6 100644 --- a/src/sound/SoundManager.js +++ b/src/sound/SoundManager.js @@ -3,20 +3,47 @@ * * @class SoundManager * @constructor -* @param game {Phaser.Game} reference to the current game instance. +* @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} + */ this.game = game; this.onSoundDecode = new Phaser.Signal; + + /** + * Boolean indicating whether the game is on "mute" + * @property _muted + * @private + * @type {bool} + */ this._muted = false; this._unlockSource = null; + + /** + * The global audio volume. A value between 0 (silence) and 1 (full volume) + * @property _volume + * @private + * @type {number} + */ this._volume = 1; - this._muted = false; + + /** + * An array containing all the sounds + * @property _sounds + * @private + * @type {array} + */ this._sounds = []; + this.context = null; this.usingWebAudio = true; this.usingAudioTag = false; @@ -30,6 +57,10 @@ Phaser.SoundManager = function (game) { Phaser.SoundManager.prototype = { + /** + * Initialises the sound manager + * @method boot + */ boot: function () { if (this.game.device.iOS && this.game.device.webAudio == false) @@ -108,6 +139,10 @@ Phaser.SoundManager.prototype = { }, + /** + * Enables the audio, usually after the first touch + * @method unlock + */ unlock: function () { if (this.touchLocked == false) @@ -138,6 +173,10 @@ Phaser.SoundManager.prototype = { }, + /** + * Stops all the sounds in the game + * @method stopAll + */ stopAll: function () { for (var i = 0; i < this._sounds.length; i++) @@ -150,6 +189,10 @@ Phaser.SoundManager.prototype = { }, + /** + * Pauses all the sounds in the game + * @method pauseAll + */ pauseAll: function () { for (var i = 0; i < this._sounds.length; i++) @@ -162,6 +205,10 @@ Phaser.SoundManager.prototype = { }, + /** + * resumes every sound in the game + * @method resumeAll + */ resumeAll: function () { for (var i = 0; i < this._sounds.length; i++) @@ -176,8 +223,9 @@ 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] {Sound} its bufer will be set to decoded data. + * @param [sound] {Phaser.Sound} its bufer will be set to decoded data. */ decode: function (key, sound) { @@ -205,6 +253,10 @@ Phaser.SoundManager.prototype = { }, + /** + * updates every sound in the game + * @method update + */ update: function () { if (this.touchLocked) @@ -232,11 +284,10 @@ Phaser.SoundManager.prototype = { /** * * @method add - * @param key {string} Asset key for the sound. - * @param volume {number} default value for the volume. - * @param loop {bool} 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; @@ -258,6 +309,8 @@ 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 () { @@ -265,6 +318,11 @@ Object.defineProperty(Phaser.SoundManager.prototype, "mute", { }, + /** + * Mute sounds. + * @method mute + * @return {bool} whether or not the game is on "mute" + */ set: function (value) { value = value || null; @@ -316,14 +374,16 @@ Object.defineProperty(Phaser.SoundManager.prototype, "mute", { } } } - }, + } - enumerable: true, - configurable: true }); 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) @@ -338,7 +398,9 @@ Object.defineProperty(Phaser.SoundManager.prototype, "volume", { }, /** - * The global audio volume. A value between 0 (silence) and 1 (full 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) { diff --git a/src/system/Canvas.js b/src/system/Canvas.js index 444484d6..51c44c6b 100644 --- a/src/system/Canvas.js +++ b/src/system/Canvas.js @@ -5,8 +5,22 @@ * @module Phaser.Canvas */ -Phaser.Canvas = { +/** +* The Canvas class handles everything related to the tag as a DOM Element, like styles, offset, aspect ratio +* +* @class Canvas +* @static +*/ +Phaser.Canvas = { + /** + * Creates the tag + * + * @method create + * @param {number} width The desired width + * @param {number} height The desired height + * @return {HTMLCanvasElement} the newly created tag + */ create: function (width, height) { width = width || 256; @@ -23,6 +37,10 @@ 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 */ getOffset: function (element, point) { diff --git a/src/utils/Utils.js b/src/utils/Utils.js index 19282111..9aee2e8f 100644 --- a/src/utils/Utils.js +++ b/src/utils/Utils.js @@ -1,4 +1,15 @@ +/** +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License +* @module Phaser.Utils +*/ +/** +* +* @class Utils +* @static +*/ Phaser.Utils = { /** @@ -6,6 +17,11 @@ Phaser.Utils = { * 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) **/ pad: function (str, len, pad, dir) { @@ -37,7 +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 + */ isPlainObject: function (obj) { // Not plain objects: @@ -67,11 +87,20 @@ Phaser.Utils = { return true; }, + // deep, target, objects to copy to the target object // This is a slightly modified version of jQuery.extend (http://api.jquery.com/jQuery.extend/) // deep (boolean) // target (object to add to) // objects ... (objects to recurse and copy from) + + /** + * This is a slightly modified version of jQuery.extend (http://api.jquery.com/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 + */ extend: function () { var options, name, src, copy, copyIsArray, clone, @@ -147,17 +176,18 @@ Phaser.Utils = { // Global functions that PIXI needs -/** + /** * Converts a hex color number to an [R, G, B] array * * @method HEXtoRGB - * @param hex {Number} + * @param {Number} hex + * @return {array} */ function HEXtoRGB(hex) { return [(hex >> 16 & 0xFF) / 255, ( hex >> 8 & 0xFF) / 255, (hex & 0xFF)/ 255]; } -/** + /** * A polyfill for Function.prototype.bind * * @method bind