From 13a2cc2feb0309ff7abaa8c905137cbc54edf905 Mon Sep 17 00:00:00 2001 From: photonstorm Date: Mon, 25 Nov 2013 03:13:04 +0000 Subject: [PATCH] Updating all files to adhere to the JSHint settings and fixing lots of documentation errors on the way. --- .jshintrc | 4 +- README.md | 2 +- src/PixiPatch.js | 2 +- src/animation/AnimationManager.js | 440 ++-- src/animation/AnimationParser.js | 63 +- src/animation/Frame.js | 188 +- src/animation/FrameData.js | 48 +- src/core/Camera.js | 79 +- src/core/Filter.js | 8 +- src/core/Game.js | 626 +++--- src/core/Group.js | 1957 ++++++++--------- src/core/LinkedList.js | 170 +- src/core/Plugin.js | 46 +- src/core/PluginManager.js | 40 +- src/core/Signal.js | 483 ++-- src/core/SignalBinding.js | 32 +- src/core/Stage.js | 34 +- src/core/State.js | 86 +- src/core/StateManager.js | 569 +++-- src/core/World.js | 64 +- src/gameobjects/BitmapData.js | 1746 +++++++-------- src/gameobjects/BitmapText.js | 82 +- src/gameobjects/Button.js | 134 +- src/gameobjects/Events.js | 67 +- src/gameobjects/GameObjectFactory.js | 16 +- src/gameobjects/Graphics.js | 16 +- src/gameobjects/RenderTexture.js | 326 +-- src/gameobjects/Sprite.js | 120 +- src/gameobjects/Text.js | 94 +- src/gameobjects/TileSprite.js | 35 +- src/geom/Circle.js | 47 +- src/geom/Point.js | 46 +- src/geom/Polygon.js | 4 +- src/geom/Rectangle.js | 41 +- src/input/Input.js | 133 +- src/input/InputHandler.js | 493 +++-- src/input/Key.js | 138 +- src/input/Keyboard.js | 77 +- src/input/MSPointer.js | 81 +- src/input/Mouse.js | 139 +- src/input/Pointer.js | 170 +- src/input/Touch.js | 102 +- src/loader/Cache.js | 4 +- src/loader/Loader.js | 8 +- src/math/Math.js | 14 +- src/particles/arcade/Emitter.js | 2 +- .../advanced/collision/GridBroadphase.js | 2 +- src/physics/advanced/math/polyk.js | 8 +- src/physics/advanced/objects/Body.js | 2 +- src/physics/arcade/ArcadePhysics.js | 46 +- src/physics/arcade/Body.js | 10 +- src/pixi/display/DisplayObjectContainer.js | 2 +- src/pixi/extras/Spine.js | 12 +- src/pixi/filters/CrossHatchFilter.js | 8 +- src/pixi/loaders/AssetLoader.js | 2 +- src/pixi/primitives/Graphics.js | 10 +- src/pixi/renderers/webgl/WebGLBatch.js | 6 +- src/pixi/renderers/webgl/WebGLGraphics.js | 2 +- src/pixi/renderers/webgl/WebGLRenderGroup.js | 4 +- src/pixi/renderers/webgl/WebGLRenderer.js | 2 +- src/sound/Sound.js | 8 +- src/sound/SoundManager.js | 12 +- src/system/StageScaleMode.js | 22 +- src/tilemap/Tile.js | 4 +- src/tilemap/TilemapLayer.js | 2 +- src/tilemap/TilemapParser.js | 6 +- src/time/Timer.js | 2 +- src/utils/Debug.js | 2 +- 68 files changed, 4622 insertions(+), 4628 deletions(-) diff --git a/.jshintrc b/.jshintrc index aa00563c..49e2fdd0 100644 --- a/.jshintrc +++ b/.jshintrc @@ -35,7 +35,7 @@ "eqnull" : true, // Tolerate use of `== null`. "evil" : false, // Tolerate use of `eval`. "expr" : false, // Tolerate `ExpressionStatement` as Programs. - "forin" : true, // Tolerate `for in` loops without `hasOwnPrototype`. + "forin" : false, // Tolerate `for in` loops without `hasOwnPrototype`. "freeze" : true, // Prohibits overwriting prototypes of native objects such as Array and Date. "funcscope" : true, // This option suppresses warnings about declaring variables inside of control structures while accessing them later from the outside. "immed" : false, // Require immediate invocations to be wrapped in parens e.g. `( function(){}() );` @@ -69,7 +69,7 @@ "noempty" : true, // Prohibit use of empty blocks. "nonew" : true, // Prohibit use of constructors for side-effects. "plusplus" : false, // Prohibit use of `++` & `--`. - "quotmark" : true, // This option enforces the consistency of quotation marks used throughout your code. + "quotmark" : false, // This option enforces the consistency of quotation marks used throughout your code. "sub" : true, // Tolerate all forms of subscript notation besides dot notation e.g. `dict['key']` instead of `dict.key`. "trailing" : true // Prohibit trailing whitespaces. } diff --git a/README.md b/README.md index 3226c481..bfe3705a 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,7 @@ Version 1.1.3 - in build * Updated: If you specify 'null' as a Group parent it will now revert to using the World as the parent (before only 'undefined' worked) * Updated: Skip preupdate/update for PIXI hierarchies in which an ancestor doesn't exist (thanks cocoademon) * Updated: Loader.audio can now accept either an array of URL strings or a single URL string (thanks crazysam + kevinthompson) - +* Updated: MSPointer updated to support IE11 by dropping the prefix from the event listeners. You can view the complete Change Log for all previous versions at https://github.com/photonstorm/phaser/changelog.md diff --git a/src/PixiPatch.js b/src/PixiPatch.js index 5f831c03..db56ae7b 100644 --- a/src/PixiPatch.js +++ b/src/PixiPatch.js @@ -53,7 +53,7 @@ PIXI.CanvasRenderer.prototype.renderDisplayObject = function(displayObject) continue; } - if (!displayObject.renderable || displayObject.alpha == 0) + if (!displayObject.renderable || displayObject.alpha === 0) { displayObject = displayObject._iNext; continue; diff --git a/src/animation/AnimationManager.js b/src/animation/AnimationManager.js index 0de12ac3..043ae6c9 100644 --- a/src/animation/AnimationManager.js +++ b/src/animation/AnimationManager.js @@ -17,49 +17,49 @@ Phaser.AnimationManager = function (sprite) { /** * @property {Phaser.Sprite} sprite - A reference to the parent Sprite that owns this AnimationManager. */ - this.sprite = sprite; + this.sprite = sprite; /** * @property {Phaser.Game} game - A reference to the currently running Game. */ - this.game = sprite.game; + this.game = sprite.game; - /** - * @property {Phaser.Frame} currentFrame - The currently displayed Frame of animation, if any. - * @default - */ - this.currentFrame = null; - - /** - * @property {boolean} updateIfVisible - Should the animation data continue to update even if the Sprite.visible is set to false. - * @default - */ - this.updateIfVisible = true; + /** + * @property {Phaser.Frame} currentFrame - The currently displayed Frame of animation, if any. + * @default + */ + this.currentFrame = null; + + /** + * @property {boolean} updateIfVisible - Should the animation data continue to update even if the Sprite.visible is set to false. + * @default + */ + this.updateIfVisible = true; - /** - * @property {boolean} isLoaded - Set to true once animation data has been loaded. - * @default - */ - this.isLoaded = false; + /** + * @property {boolean} isLoaded - Set to true once animation data has been loaded. + * @default + */ + this.isLoaded = false; - /** - * @property {Phaser.FrameData} _frameData - A temp. var for holding the currently playing Animations FrameData. - * @private - * @default - */ - this._frameData = null; + /** + * @property {Phaser.FrameData} _frameData - A temp. var for holding the currently playing Animations FrameData. + * @private + * @default + */ + this._frameData = null; - /** - * @property {object} _anims - An internal object that stores all of the Animation instances. - * @private - */ - this._anims = {}; + /** + * @property {object} _anims - An internal object that stores all of the Animation instances. + * @private + */ + this._anims = {}; - /** - * @property {object} _outputFrames - An internal object to help avoid gc. - * @private - */ - this._outputFrames = []; + /** + * @property {object} _outputFrames - An internal object to help avoid gc. + * @private + */ + this._outputFrames = []; }; @@ -73,226 +73,226 @@ Phaser.AnimationManager.prototype = { * @private * @param {Phaser.FrameData} frameData - The FrameData set to load. */ - loadFrameData: function (frameData) { + loadFrameData: function (frameData) { - this._frameData = frameData; - this.frame = 0; - this.isLoaded = true; + this._frameData = frameData; + this.frame = 0; + this.isLoaded = true; - }, + }, - /** - * Adds a new animation under the given key. Optionally set the frames, frame rate and loop. - * Animations added in this way are played back with the play function. - * + /** + * Adds a new animation under the given key. Optionally set the frames, frame rate and loop. + * Animations added in this way are played back with the play function. + * * @method Phaser.AnimationManager#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] - 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) { + * @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] - 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) { - if (this._frameData == null) - { - console.warn('No FrameData available for Phaser.Animation ' + name); - return; - } + if (this._frameData == null) + { + console.warn('No FrameData available for Phaser.Animation ' + name); + return; + } - frameRate = frameRate || 60; + frameRate = frameRate || 60; - if (typeof loop === 'undefined') { loop = false; } + if (typeof loop === 'undefined') { loop = false; } - // If they didn't set the useNumericIndex then let's at least try and guess it - if (typeof useNumericIndex === 'undefined') - { - if (frames && typeof frames[0] === 'number') - { - useNumericIndex = true; - } - else - { - useNumericIndex = false; - } - } + // If they didn't set the useNumericIndex then let's at least try and guess it + if (typeof useNumericIndex === 'undefined') + { + if (frames && typeof frames[0] === 'number') + { + useNumericIndex = true; + } + else + { + useNumericIndex = false; + } + } - // Create the signals the AnimationManager will emit - if (this.sprite.events.onAnimationStart == null) - { - this.sprite.events.onAnimationStart = new Phaser.Signal(); - this.sprite.events.onAnimationComplete = new Phaser.Signal(); - this.sprite.events.onAnimationLoop = new Phaser.Signal(); - } + // Create the signals the AnimationManager will emit + if (this.sprite.events.onAnimationStart == null) + { + this.sprite.events.onAnimationStart = new Phaser.Signal(); + this.sprite.events.onAnimationComplete = new Phaser.Signal(); + this.sprite.events.onAnimationLoop = new Phaser.Signal(); + } - this._outputFrames.length = 0; + this._outputFrames.length = 0; - this._frameData.getFrameIndexes(frames, useNumericIndex, this._outputFrames); + this._frameData.getFrameIndexes(frames, useNumericIndex, this._outputFrames); - this._anims[name] = new Phaser.Animation(this.game, this.sprite, name, this._frameData, this._outputFrames, frameRate, loop); - this.currentAnim = this._anims[name]; - this.currentFrame = this.currentAnim.currentFrame; - this.sprite.setTexture(PIXI.TextureCache[this.currentFrame.uuid]); + this._anims[name] = new Phaser.Animation(this.game, this.sprite, name, this._frameData, this._outputFrames, frameRate, loop); + this.currentAnim = this._anims[name]; + this.currentFrame = this.currentAnim.currentFrame; + this.sprite.setTexture(PIXI.TextureCache[this.currentFrame.uuid]); - return this._anims[name]; + return this._anims[name]; - }, + }, - /** - * Check whether the frames in the given array are valid and exist. - * + /** + * Check whether the frames in the given array are valid and exist. + * * @method Phaser.AnimationManager#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. - */ - validateFrames: function (frames, useNumericIndex) { + * @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) { - if (typeof useNumericIndex == 'undefined') { useNumericIndex = true; } + if (typeof useNumericIndex == 'undefined') { useNumericIndex = true; } - for (var i = 0; i < frames.length; i++) - { - if (useNumericIndex == true) - { - if (frames[i] > this._frameData.total) - { - return false; - } - } - else - { - if (this._frameData.checkFrameName(frames[i]) == false) - { - return false; - } - } - } + for (var i = 0; i < frames.length; i++) + { + if (useNumericIndex === true) + { + if (frames[i] > this._frameData.total) + { + return false; + } + } + else + { + if (this._frameData.checkFrameName(frames[i]) === false) + { + return false; + } + } + } - return true; + return true; - }, + }, - /** - * Play an animation based on the given key. The animation should previously have been added via sprite.animations.add() - * 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 Phaser.AnimationManager#play - * @param {string} name - The name of the animation to be played, e.g. "fire", "walk", "jump". + /** + * Play an animation based on the given key. The animation should previously have been added via sprite.animations.add() + * 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 Phaser.AnimationManager#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=false] - Should the animation be looped after playback. If not provided the previously set loop value of the Animation is used. * @param {boolean} [killOnComplete=false] - If set to true when the animation completes (only happens if loop=false) the parent Sprite will be killed. * @return {Phaser.Animation} A reference to playing Animation instance. - */ - play: function (name, frameRate, loop, killOnComplete) { + */ + play: function (name, frameRate, loop, killOnComplete) { - if (this._anims[name]) - { - if (this.currentAnim == this._anims[name]) - { - if (this.currentAnim.isPlaying == false) - { - this.currentAnim.paused = false; - return this.currentAnim.play(frameRate, loop, killOnComplete); - } - } - else - { - this.currentAnim = this._anims[name]; - this.currentAnim.paused = false; - return this.currentAnim.play(frameRate, loop, killOnComplete); - } - } + if (this._anims[name]) + { + if (this.currentAnim == this._anims[name]) + { + if (this.currentAnim.isPlaying === false) + { + this.currentAnim.paused = false; + return this.currentAnim.play(frameRate, loop, killOnComplete); + } + } + else + { + this.currentAnim = this._anims[name]; + this.currentAnim.paused = false; + return this.currentAnim.play(frameRate, loop, killOnComplete); + } + } - }, + }, - /** - * Stop playback of an animation. If a name is given that specific animation is stopped, otherwise the current animation is stopped. - * The currentAnim property of the AnimationManager is automatically set to the animation given. - * - * @method Phaser.AnimationManager#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) - */ - stop: function (name, resetFrame) { + /** + * Stop playback of an animation. If a name is given that specific animation is stopped, otherwise the current animation is stopped. + * The currentAnim property of the AnimationManager is automatically set to the animation given. + * + * @method Phaser.AnimationManager#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) + */ + stop: function (name, resetFrame) { - if (typeof resetFrame == 'undefined') { resetFrame = false; } + if (typeof resetFrame == 'undefined') { resetFrame = false; } - if (typeof name == 'string') - { - if (this._anims[name]) - { - this.currentAnim = this._anims[name]; - this.currentAnim.stop(resetFrame); - } - } - else - { - if (this.currentAnim) - { - this.currentAnim.stop(resetFrame); - } - } + if (typeof name == 'string') + { + if (this._anims[name]) + { + this.currentAnim = this._anims[name]; + this.currentAnim.stop(resetFrame); + } + } + else + { + if (this.currentAnim) + { + this.currentAnim.stop(resetFrame); + } + } - }, + }, - /** - * The main update function is called by the Sprites update loop. It's responsible for updating animation frames and firing related events. - * - * @method Phaser.AnimationManager#update - * @protected + /** + * The main update function is called by the Sprites update loop. It's responsible for updating animation frames and firing related events. + * + * @method Phaser.AnimationManager#update + * @protected * @return {boolean} True if a new animation frame has been set, otherwise false. - */ - update: function () { + */ + update: function () { - if (this.updateIfVisible && this.sprite.visible == false) - { - return false; - } + if (this.updateIfVisible && this.sprite.visible === false) + { + return false; + } - if (this.currentAnim && this.currentAnim.update() == true) - { - this.currentFrame = this.currentAnim.currentFrame; - this.sprite.currentFrame = this.currentFrame; - return true; - } + if (this.currentAnim && this.currentAnim.update() === true) + { + this.currentFrame = this.currentAnim.currentFrame; + this.sprite.currentFrame = this.currentFrame; + return true; + } - return false; + return false; - }, + }, - /** - * Returns an animation that was previously added by name. - * - * @method Phaser.AnimationManager#getAnimation - * @param {string} name - The name of the animation to be returned, e.g. "fire". + /** + * Returns an animation that was previously added by name. + * + * @method Phaser.AnimationManager#getAnimation + * @param {string} name - The name of the animation to be returned, e.g. "fire". * @return {Phaser.Animation|boolean} The Animation instance, if found, otherwise false. - */ - getAnimation: function (name) { + */ + getAnimation: function (name) { - if (typeof name == 'string') - { - if (this._anims[name]) - { - return this._anims[name]; - } - } + if (typeof name == 'string') + { + if (this._anims[name]) + { + return this._anims[name]; + } + } - return false; + return false; - }, + }, /** * Refreshes the current frame data back to the parent Sprite and also resets the texture data. * * @method Phaser.AnimationManager#refreshFrame */ - refreshFrame: function () { + refreshFrame: function () { this.sprite.currentFrame = this.currentFrame; - this.sprite.setTexture(PIXI.TextureCache[this.currentFrame.uuid]); + this.sprite.setTexture(PIXI.TextureCache[this.currentFrame.uuid]); - }, + }, /** * Destroys all references this AnimationManager contains. Sets the _anims to a new object and nulls the current animation. @@ -316,7 +316,7 @@ Phaser.AnimationManager.prototype = { * @property {Phaser.FrameData} frameData - The current animations FrameData. * @readonly */ -Object.defineProperty(Phaser.AnimationManager.prototype, "frameData", { +Object.defineProperty(Phaser.AnimationManager.prototype, 'frameData', { get: function () { return this._frameData; @@ -329,7 +329,7 @@ Object.defineProperty(Phaser.AnimationManager.prototype, "frameData", { * @property {number} frameTotal - The total number of frames in the currently loaded FrameData, or -1 if no FrameData is loaded. * @readonly */ -Object.defineProperty(Phaser.AnimationManager.prototype, "frameTotal", { +Object.defineProperty(Phaser.AnimationManager.prototype, 'frameTotal', { get: function () { @@ -349,7 +349,7 @@ Object.defineProperty(Phaser.AnimationManager.prototype, "frameTotal", { * @name Phaser.AnimationManager#paused * @property {boolean} paused - Gets and sets the paused state of the current animation. */ -Object.defineProperty(Phaser.AnimationManager.prototype, "paused", { +Object.defineProperty(Phaser.AnimationManager.prototype, 'paused', { get: function () { @@ -369,15 +369,15 @@ Object.defineProperty(Phaser.AnimationManager.prototype, "paused", { * @name Phaser.AnimationManager#frame * @property {number} frame - Gets or sets the current frame index and updates the Texture Cache for display. */ -Object.defineProperty(Phaser.AnimationManager.prototype, "frame", { +Object.defineProperty(Phaser.AnimationManager.prototype, 'frame', { get: function () { - if (this.currentFrame) - { - return this._frameIndex; - } - + if (this.currentFrame) + { + return this._frameIndex; + } + }, set: function (value) { @@ -387,7 +387,7 @@ Object.defineProperty(Phaser.AnimationManager.prototype, "frame", { this.currentFrame = this._frameData.getFrame(value); this._frameIndex = value; this.sprite.currentFrame = this.currentFrame; - this.sprite.setTexture(PIXI.TextureCache[this.currentFrame.uuid]); + this.sprite.setTexture(PIXI.TextureCache[this.currentFrame.uuid]); } } @@ -398,14 +398,14 @@ Object.defineProperty(Phaser.AnimationManager.prototype, "frame", { * @name Phaser.AnimationManager#frameName * @property {string} frameName - Gets or sets the current frame name and updates the Texture Cache for display. */ -Object.defineProperty(Phaser.AnimationManager.prototype, "frameName", { +Object.defineProperty(Phaser.AnimationManager.prototype, 'frameName', { get: function () { - if (this.currentFrame) - { - return this.currentFrame.name; - } + if (this.currentFrame) + { + return this.currentFrame.name; + } }, @@ -416,11 +416,11 @@ Object.defineProperty(Phaser.AnimationManager.prototype, "frameName", { this.currentFrame = this._frameData.getFrameByName(value); this._frameIndex = this.currentFrame.index; this.sprite.currentFrame = this.currentFrame; - this.sprite.setTexture(PIXI.TextureCache[this.currentFrame.uuid]); + this.sprite.setTexture(PIXI.TextureCache[this.currentFrame.uuid]); } else { - console.warn("Cannot set frameName: " + value); + console.warn('Cannot set frameName: ' + value); } } diff --git a/src/animation/AnimationParser.js b/src/animation/AnimationParser.js index 7484d85c..a3b4acf7 100644 --- a/src/animation/AnimationParser.js +++ b/src/animation/AnimationParser.js @@ -55,7 +55,7 @@ Phaser.AnimationParser = { } // Zero or smaller than frame sizes? - if (width == 0 || height == 0 || width < frameWidth || height < frameHeight || total === 0) + if (width === 0 || height === 0 || width < frameWidth || height < frameHeight || total === 0) { console.warn("Phaser.AnimationParser.spriteSheet: width/height zero or width/height < given frameWidth/frameHeight"); return null; @@ -124,13 +124,13 @@ Phaser.AnimationParser = { newFrame = data.addFrame(new Phaser.Frame( i, - frames[i].frame.x, - frames[i].frame.y, - frames[i].frame.w, - frames[i].frame.h, - frames[i].filename, + frames[i].frame.x, + frames[i].frame.y, + frames[i].frame.w, + frames[i].frame.h, + frames[i].filename, uuid - )); + )); PIXI.TextureCache[uuid] = new PIXI.Texture(PIXI.BaseTextureCache[cacheKey], { x: frames[i].frame.x, @@ -142,12 +142,12 @@ Phaser.AnimationParser = { if (frames[i].trimmed) { newFrame.setTrim( - frames[i].trimmed, - frames[i].sourceSize.w, - frames[i].sourceSize.h, - frames[i].spriteSourceSize.x, - frames[i].spriteSourceSize.y, - frames[i].spriteSourceSize.w, + frames[i].trimmed, + frames[i].sourceSize.w, + frames[i].sourceSize.h, + frames[i].spriteSourceSize.x, + frames[i].spriteSourceSize.y, + frames[i].spriteSourceSize.w, frames[i].spriteSourceSize.h ); @@ -196,10 +196,10 @@ Phaser.AnimationParser = { newFrame = data.addFrame(new Phaser.Frame( i, - frames[key].frame.x, - frames[key].frame.y, - frames[key].frame.w, - frames[key].frame.h, + frames[key].frame.x, + frames[key].frame.y, + frames[key].frame.w, + frames[key].frame.h, key, uuid )); @@ -214,12 +214,12 @@ Phaser.AnimationParser = { if (frames[key].trimmed) { newFrame.setTrim( - frames[key].trimmed, - frames[key].sourceSize.w, - frames[key].sourceSize.h, - frames[key].spriteSourceSize.x, - frames[key].spriteSourceSize.y, - frames[key].spriteSourceSize.w, + frames[key].trimmed, + frames[key].sourceSize.w, + frames[key].sourceSize.h, + frames[key].spriteSourceSize.x, + frames[key].spriteSourceSize.y, + frames[key].spriteSourceSize.w, frames[key].spriteSourceSize.h ); @@ -261,6 +261,7 @@ Phaser.AnimationParser = { var newFrame; var uuid; + var name; var frame; var x; var y; @@ -278,20 +279,20 @@ Phaser.AnimationParser = { frame = frames[i].attributes; name = frame.name.nodeValue; - x = parseInt(frame.x.nodeValue); - y = parseInt(frame.y.nodeValue); - width = parseInt(frame.width.nodeValue); - height = parseInt(frame.height.nodeValue); + x = parseInt(frame.x.nodeValue, 10); + y = parseInt(frame.y.nodeValue, 10); + width = parseInt(frame.width.nodeValue, 10); + height = parseInt(frame.height.nodeValue, 10); frameX = null; frameY = null; if (frame.frameX) { - frameX = Math.abs(parseInt(frame.frameX.nodeValue)); - frameY = Math.abs(parseInt(frame.frameY.nodeValue)); - frameWidth = parseInt(frame.frameWidth.nodeValue); - frameHeight = parseInt(frame.frameHeight.nodeValue); + frameX = Math.abs(parseInt(frame.frameX.nodeValue, 10)); + frameY = Math.abs(parseInt(frame.frameY.nodeValue, 10)); + frameWidth = parseInt(frame.frameWidth.nodeValue, 10); + frameHeight = parseInt(frame.frameHeight.nodeValue, 10); } newFrame = data.addFrame(new Phaser.Frame(i, x, y, width, height, name, uuid)); diff --git a/src/animation/Frame.js b/src/animation/Frame.js index bba87347..60f1a2b0 100644 --- a/src/animation/Frame.js +++ b/src/animation/Frame.js @@ -19,124 +19,124 @@ */ Phaser.Frame = function (index, x, y, width, height, name, uuid) { - /** - * @property {number} index - The index of this Frame within the FrameData set it is being added to. - */ - this.index = index; - - /** - * @property {number} x - X position within the image to cut from. - */ - this.x = x; + /** + * @property {number} index - The index of this Frame within the FrameData set it is being added to. + */ + this.index = index; + + /** + * @property {number} x - X position within the image to cut from. + */ + this.x = x; - /** - * @property {number} y - Y position within the image to cut from. - */ - this.y = y; + /** + * @property {number} y - Y position within the image to cut from. + */ + this.y = y; - /** - * @property {number} width - Width of the frame. - */ - this.width = width; + /** + * @property {number} width - Width of the frame. + */ + this.width = width; - /** - * @property {number} height - Height of the frame. - */ - this.height = height; + /** + * @property {number} height - Height of the frame. + */ + this.height = height; - /** - * @property {string} name - Useful for Texture Atlas files (is set to the filename value). - */ - this.name = name; + /** + * @property {string} name - Useful for Texture Atlas files (is set to the filename value). + */ + this.name = name; - /** - * @property {string} uuid - A link to the PIXI.TextureCache entry. - */ - this.uuid = uuid; + /** + * @property {string} uuid - A link to the PIXI.TextureCache entry. + */ + this.uuid = uuid; - /** - * @property {number} centerX - Center X position within the image to cut from. - */ + /** + * @property {number} centerX - Center X position within the image to cut from. + */ this.centerX = Math.floor(width / 2); - /** - * @property {number} centerY - Center Y position within the image to cut from. - */ + /** + * @property {number} centerY - Center Y position within the image to cut from. + */ this.centerY = Math.floor(height / 2); - /** - * @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); + /** + * @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); - /** - * @property {boolean} rotated - Rotated? (not yet implemented) - * @default - */ - this.rotated = false; + /** + * @property {boolean} rotated - Rotated? (not yet implemented) + * @default + */ + this.rotated = false; - /** - * @property {string} rotationDirection - Either 'cw' or 'ccw', rotation is always 90 degrees. - * @default 'cw' - */ - this.rotationDirection = 'cw'; + /** + * @property {string} rotationDirection - Either 'cw' or 'ccw', rotation is always 90 degrees. + * @default 'cw' + */ + this.rotationDirection = 'cw'; - /** - * @property {boolean} trimmed - Was it trimmed when packed? - * @default - */ - this.trimmed = false; + /** + * @property {boolean} trimmed - Was it trimmed when packed? + * @default + */ + this.trimmed = false; - /** - * @property {number} sourceSizeW - Width of the original sprite. - */ + /** + * @property {number} sourceSizeW - Width of the original sprite. + */ this.sourceSizeW = width; - /** - * @property {number} sourceSizeH - Height of the original sprite. - */ + /** + * @property {number} sourceSizeH - Height of the original sprite. + */ this.sourceSizeH = height; - /** - * @property {number} spriteSourceSizeX - X position of the trimmed sprite inside original sprite. - * @default - */ - this.spriteSourceSizeX = 0; + /** + * @property {number} spriteSourceSizeX - X position of the trimmed sprite inside original sprite. + * @default + */ + this.spriteSourceSizeX = 0; - /** - * @property {number} spriteSourceSizeY - Y position of the trimmed sprite inside original sprite. - * @default - */ - this.spriteSourceSizeY = 0; + /** + * @property {number} spriteSourceSizeY - Y position of the trimmed sprite inside original sprite. + * @default + */ + this.spriteSourceSizeY = 0; - /** - * @property {number} spriteSourceSizeW - Width of the trimmed sprite. - * @default - */ - this.spriteSourceSizeW = 0; + /** + * @property {number} spriteSourceSizeW - Width of the trimmed sprite. + * @default + */ + this.spriteSourceSizeW = 0; - /** - * @property {number} spriteSourceSizeH - Height of the trimmed sprite. - * @default - */ - this.spriteSourceSizeH = 0; + /** + * @property {number} spriteSourceSizeH - Height of the trimmed sprite. + * @default + */ + this.spriteSourceSizeH = 0; }; Phaser.Frame.prototype = { - /** - * If the frame was trimmed when added to the Texture Atlas this records the trim and source data. - * - * @method Phaser.Frame#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. - */ + /** + * If the frame was trimmed when added to the Texture Atlas this records the trim and source data. + * + * @method Phaser.Frame#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. + */ setTrim: function (trimmed, actualWidth, actualHeight, destX, destY, destWidth, destHeight) { this.trimmed = trimmed; @@ -147,8 +147,8 @@ Phaser.Frame.prototype = { this.height = actualHeight; this.sourceSizeW = actualWidth; this.sourceSizeH = actualHeight; - this.centerX = Math.floor(actualWidth / 2); - this.centerY = Math.floor(actualHeight / 2); + this.centerX = Math.floor(actualWidth / 2); + this.centerY = Math.floor(actualHeight / 2); this.spriteSourceSizeX = destX; this.spriteSourceSizeY = destY; this.spriteSourceSizeW = destWidth; diff --git a/src/animation/FrameData.js b/src/animation/FrameData.js index 59a7b549..6588ac21 100644 --- a/src/animation/FrameData.js +++ b/src/animation/FrameData.js @@ -12,17 +12,17 @@ */ Phaser.FrameData = function () { - /** - * @property {Array} _frames - Local array of frames. - * @private - */ + /** + * @property {Array} _frames - Local array of frames. + * @private + */ this._frames = []; - /** - * @property {Array} _frameNames - Local array of frame names for name to index conversions. - * @private - */ + /** + * @property {Array} _frameNames - Local array of frame names for name to index conversions. + * @private + */ this._frameNames = []; }; @@ -51,13 +51,13 @@ Phaser.FrameData.prototype = { }, - /** - * Get a Frame by its numerical index. + /** + * Get a Frame by its numerical index. * * @method Phaser.FrameData#getFrame - * @param {number} index - The index of the frame you want to get. - * @return {Phaser.Frame} The frame, if found. - */ + * @param {number} index - The index of the frame you want to get. + * @return {Phaser.Frame} The frame, if found. + */ getFrame: function (index) { if (this._frames.length > index) @@ -105,15 +105,15 @@ Phaser.FrameData.prototype = { }, - /** - * Returns a range of frames based on the given start and end frame indexes and returns them in an Array. + /** + * Returns a range of frames based on the given start and end frame indexes and returns them in an Array. * * @method Phaser.FrameData#getFrameRange * @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. - */ + * @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) { if (typeof output === "undefined") { output = []; } @@ -127,8 +127,8 @@ Phaser.FrameData.prototype = { }, - /** - * Returns all of the Frames in this FrameData set where the frame index is found in the input array. + /** + * Returns all of the Frames in this FrameData set where the frame index is found in the input array. * The frames are returned in the output array, or if none is provided in a new Array object. * * @method Phaser.FrameData#getFrames @@ -136,13 +136,13 @@ Phaser.FrameData.prototype = { * @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) { if (typeof useNumericIndex === "undefined") { useNumericIndex = true; } if (typeof output === "undefined") { output = []; } - if (typeof frames === "undefined" || frames.length == 0) + if (typeof frames === "undefined" || frames.length === 0) { // No input array, so we loop through all frames for (var i = 0; i < this._frames.length; i++) @@ -189,7 +189,7 @@ Phaser.FrameData.prototype = { if (typeof useNumericIndex === "undefined") { useNumericIndex = true; } if (typeof output === "undefined") { output = []; } - if (typeof frames === "undefined" || frames.length == 0) + if (typeof frames === "undefined" || frames.length === 0) { // No frames array, so we loop through all frames for (var i = 0, len = this._frames.length; i < len; i++) diff --git a/src/core/Camera.js b/src/core/Camera.js index ec8025b1..151e51ac 100644 --- a/src/core/Camera.js +++ b/src/core/Camera.js @@ -19,35 +19,35 @@ */ Phaser.Camera = function (game, id, x, y, width, height) { - /** - * @property {Phaser.Game} game - A reference to the currently running Game. - */ - this.game = game; + /** + * @property {Phaser.Game} game - A reference to the currently running Game. + */ + this.game = game; - /** - * @property {Phaser.World} world - A reference to the game world. - */ - this.world = game.world; + /** + * @property {Phaser.World} world - A reference to the game world. + */ + this.world = game.world; - /** - * @property {number} id - Reserved for future multiple camera set-ups. - * @default - */ - this.id = 0; + /** + * @property {number} id - Reserved for future multiple camera set-ups. + * @default + */ + this.id = 0; - /** - * Camera view. - * The view into the world we wish to render (by default the game dimensions). + /** + * Camera view. + * The view into the world we wish to render (by default the game dimensions). * The x/y values are in world coordinates, not screen coordinates, the width/height is how many pixels to render. * Objects outside of this view are not rendered (unless set to ignore the Camera, i.e. UI?). - * @property {Phaser.Rectangle} view - */ + * @property {Phaser.Rectangle} view + */ this.view = new Phaser.Rectangle(x, y, width, height); /** - * @property {Phaser.Rectangle} screenView - Used by Sprites to work out Camera culling. - */ - this.screenView = new Phaser.Rectangle(x, y, width, height); + * @property {Phaser.Rectangle} screenView - Used by Sprites to work out Camera culling. + */ + this.screenView = new Phaser.Rectangle(x, y, width, height); /** * The Camera is bound to this Rectangle and cannot move outside of it. By default it is enabled and set to the size of the World. @@ -58,36 +58,36 @@ Phaser.Camera = function (game, id, x, y, width, height) { this.bounds = new Phaser.Rectangle(x, y, width, height); /** - * @property {Phaser.Rectangle} deadzone - Moving inside this Rectangle will not cause camera moving. - */ + * @property {Phaser.Rectangle} deadzone - Moving inside this Rectangle will not cause camera moving. + */ this.deadzone = null; - /** - * @property {boolean} visible - Whether this camera is visible or not. - * @default - */ + /** + * @property {boolean} visible - Whether this camera is visible or not. + * @default + */ this.visible = true; - /** - * @property {boolean} atLimit - Whether this camera is flush with the World Bounds or not. + /** + * @property {boolean} atLimit - Whether this camera is flush with the World Bounds or not. */ this.atLimit = { x: false, y: false }; - /** - * @property {Phaser.Sprite} target - If the camera is tracking a Sprite, this is a reference to it, otherwise null. + /** + * @property {Phaser.Sprite} target - If the camera is tracking a Sprite, this is a reference to it, otherwise null. * @default */ this.target = null; - /** - * @property {number} edge - Edge property. + /** + * @property {number} edge - Edge property. * @private * @default */ this._edge = 0; this.displayObject = null; - + }; /** @@ -116,7 +116,7 @@ Phaser.Camera.FOLLOW_TOPDOWN_TIGHT = 3; Phaser.Camera.prototype = { - /** + /** * Tells this camera which sprite to follow. * @method Phaser.Camera#follow * @param {Phaser.Sprite} target - The object you want the camera to track. Set to null to not follow anything. @@ -149,6 +149,9 @@ Phaser.Camera.prototype = { break; case Phaser.Camera.FOLLOW_LOCKON: + this.deadzone = null; + break; + default: this.deadzone = null; break; @@ -167,7 +170,7 @@ Phaser.Camera.prototype = { }, - /** + /** * Move the camera focus on a location instantly. * @method Phaser.Camera#focusOnXY * @param {number} x - X position. @@ -179,7 +182,7 @@ Phaser.Camera.prototype = { }, - /** + /** * Update focusing and scrolling. * @method Phaser.Camera#update */ @@ -348,7 +351,7 @@ Object.defineProperty(Phaser.Camera.prototype, "x", { * @property {number} y - Gets or sets the cameras y position. */ Object.defineProperty(Phaser.Camera.prototype, "y", { - + get: function () { return this.view.y; }, diff --git a/src/core/Filter.js b/src/core/Filter.js index 3d95d920..c3c67303 100644 --- a/src/core/Filter.js +++ b/src/core/Filter.js @@ -16,9 +16,9 @@ */ Phaser.Filter = function (game, uniforms, fragmentSrc) { - /** - * @property {Phaser.Game} game - A reference to the currently running game. - */ + /** + * @property {Phaser.Game} game - A reference to the currently running game. + */ this.game = game; /** @@ -86,7 +86,7 @@ Phaser.Filter.prototype = { this.uniforms.mouse.y = pointer.y; } - this.uniforms.time.value = this.game.time.totalElapsedSeconds(); + this.uniforms.time.value = this.game.time.totalElapsedSeconds(); }, diff --git a/src/core/Game.js b/src/core/Game.js index 7a221f24..7742a8a7 100644 --- a/src/core/Game.js +++ b/src/core/Game.js @@ -24,380 +24,380 @@ */ Phaser.Game = function (width, height, renderer, parent, state, transparent, antialias) { - width = width || 800; - height = height || 600; - renderer = renderer || Phaser.AUTO; - parent = parent || ''; - state = state || null; + width = width || 800; + height = height || 600; + renderer = renderer || Phaser.AUTO; + parent = parent || ''; + state = state || null; - if (typeof transparent == 'undefined') { transparent = false; } - if (typeof antialias == 'undefined') { antialias = true; } + if (typeof transparent == 'undefined') { transparent = false; } + if (typeof antialias == 'undefined') { antialias = true; } - /** - * @property {number} id - Phaser Game ID (for when Pixi supports multiple instances). - */ - this.id = Phaser.GAMES.push(this) - 1; + /** + * @property {number} id - Phaser Game ID (for when Pixi supports multiple instances). + */ + this.id = Phaser.GAMES.push(this) - 1; - /** - * @property {HTMLElement} parent - The Games DOM parent. - */ - this.parent = parent; + /** + * @property {HTMLElement} parent - The Games DOM parent. + */ + this.parent = parent; - // Do some more intelligent size parsing here, so they can set "100%" for example, maybe pass the scale mode in here too? + // Do some more intelligent size parsing here, so they can set "100%" for example, maybe pass the scale mode in here too? - /** - * @property {number} width - The Game width (in pixels). - */ - this.width = width; + /** + * @property {number} width - The Game width (in pixels). + */ + this.width = width; - /** - * @property {number} height - The Game height (in pixels). - */ - this.height = height; + /** + * @property {number} height - The Game height (in pixels). + */ + this.height = height; - /** - * @property {boolean} transparent - Use a transparent canvas background or not. - */ - this.transparent = transparent; + /** + * @property {boolean} transparent - Use a transparent canvas background or not. + */ + this.transparent = transparent; - /** - * @property {boolean} antialias - Anti-alias graphics (in WebGL this helps with edges, in Canvas2D it retains pixel-art quality). - */ - this.antialias = antialias; + /** + * @property {boolean} antialias - Anti-alias graphics (in WebGL this helps with edges, in Canvas2D it retains pixel-art quality). + */ + this.antialias = antialias; - /** - * @property {number} renderer - The Pixi Renderer - * @default - */ - this.renderer = null; + /** + * @property {number} renderer - The Pixi Renderer + * @default + */ + this.renderer = null; - /** - * @property {number} state - The StateManager. - */ - this.state = new Phaser.StateManager(this, state); + /** + * @property {number} state - The StateManager. + */ + this.state = new Phaser.StateManager(this, state); - /** - * @property {boolean} _paused - Is game paused? - * @private - * @default - */ - this._paused = false; + /** + * @property {boolean} _paused - Is game paused? + * @private + * @default + */ + this._paused = false; - /** - * @property {number} renderType - The Renderer this Phaser.Game will use. Either Phaser.RENDERER_AUTO, Phaser.RENDERER_CANVAS or Phaser.RENDERER_WEBGL. - */ - this.renderType = renderer; + /** + * @property {number} renderType - The Renderer this Phaser.Game will use. Either Phaser.RENDERER_AUTO, Phaser.RENDERER_CANVAS or Phaser.RENDERER_WEBGL. + */ + this.renderType = renderer; - /** - * @property {boolean} _loadComplete - Whether load complete loading or not. - * @private - * @default - */ - this._loadComplete = false; + /** + * @property {boolean} _loadComplete - Whether load complete loading or not. + * @private + * @default + */ + this._loadComplete = false; - /** - * @property {boolean} isBooted - Whether the game engine is booted, aka available. - * @default - */ - this.isBooted = false; + /** + * @property {boolean} isBooted - Whether the game engine is booted, aka available. + * @default + */ + this.isBooted = false; - /** - * @property {boolean} id -Is game running or paused? - * @default - */ - this.isRunning = false; + /** + * @property {boolean} id -Is game running or paused? + * @default + */ + this.isRunning = false; - /** - * @property {Phaser.RequestAnimationFrame} raf - Automatically handles the core game loop via requestAnimationFrame or setTimeout - * @default - */ - this.raf = null; + /** + * @property {Phaser.RequestAnimationFrame} raf - Automatically handles the core game loop via requestAnimationFrame or setTimeout + * @default + */ + this.raf = null; - /** - * @property {Phaser.GameObjectFactory} add - Reference to the GameObject Factory. - * @default - */ + /** + * @property {Phaser.GameObjectFactory} add - Reference to the GameObject Factory. + * @default + */ this.add = null; /** - * @property {Phaser.Cache} cache - Reference to the assets cache. - * @default - */ + * @property {Phaser.Cache} cache - Reference to the assets cache. + * @default + */ this.cache = null; /** - * @property {Phaser.Input} input - Reference to the input manager - * @default - */ + * @property {Phaser.Input} input - Reference to the input manager + * @default + */ this.input = null; /** - * @property {Phaser.Loader} load - Reference to the assets loader. - * @default - */ + * @property {Phaser.Loader} load - Reference to the assets loader. + * @default + */ this.load = null; /** - * @property {Phaser.Math} math - Reference to the math helper. - * @default - */ + * @property {Phaser.Math} math - Reference to the math helper. + * @default + */ this.math = null; /** - * @property {Phaser.Net} net - Reference to the network class. - * @default - */ + * @property {Phaser.Net} net - Reference to the network class. + * @default + */ this.net = null; /** - * @property {Phaser.SoundManager} sound - Reference to the sound manager. - * @default - */ + * @property {Phaser.SoundManager} sound - Reference to the sound manager. + * @default + */ this.sound = null; /** - * @property {Phaser.Stage} stage - Reference to the stage. - * @default - */ + * @property {Phaser.Stage} stage - Reference to the stage. + * @default + */ this.stage = null; /** - * @property {Phaser.TimeManager} time - Reference to game clock. - * @default - */ + * @property {Phaser.TimeManager} time - Reference to game clock. + * @default + */ this.time = null; /** - * @property {Phaser.TweenManager} tweens - Reference to the tween manager. - * @default - */ + * @property {Phaser.TweenManager} tweens - Reference to the tween manager. + * @default + */ this.tweens = null; /** - * @property {Phaser.World} world - Reference to the world. - * @default - */ + * @property {Phaser.World} world - Reference to the world. + * @default + */ this.world = null; /** - * @property {Phaser.Physics.PhysicsManager} physics - Reference to the physics manager. - * @default - */ + * @property {Phaser.Physics.PhysicsManager} physics - Reference to the physics manager. + * @default + */ this.physics = null; /** - * @property {Phaser.RandomDataGenerator} rnd - Instance of repeatable random data generator helper. - * @default - */ + * @property {Phaser.RandomDataGenerator} rnd - Instance of repeatable random data generator helper. + * @default + */ this.rnd = null; /** - * @property {Phaser.Device} device - Contains device information and capabilities. - * @default - */ + * @property {Phaser.Device} device - Contains device information and capabilities. + * @default + */ this.device = null; /** - * @property {Phaser.Physics.PhysicsManager} camera - A handy reference to world.camera. - * @default - */ - this.camera = null; + * @property {Phaser.Physics.PhysicsManager} camera - A handy reference to world.camera. + * @default + */ + this.camera = null; - /** - * @property {HTMLCanvasElement} canvas - A handy reference to renderer.view. - * @default - */ - this.canvas = null; - - /** - * @property {Context} context - A handy reference to renderer.context (only set for CANVAS games) - * @default - */ - this.context = null; + /** + * @property {HTMLCanvasElement} canvas - A handy reference to renderer.view. + * @default + */ + this.canvas = null; /** - * @property {Phaser.Utils.Debug} debug - A set of useful debug utilitie. - * @default - */ - this.debug = null; + * @property {Context} context - A handy reference to renderer.context (only set for CANVAS games) + * @default + */ + this.context = null; - /** - * @property {Phaser.Particles} particles - The Particle Manager. - * @default - */ - this.particles = null; + /** + * @property {Phaser.Utils.Debug} debug - A set of useful debug utilitie. + * @default + */ + this.debug = null; - var _this = this; + /** + * @property {Phaser.Particles} particles - The Particle Manager. + * @default + */ + this.particles = null; + + var _this = this; this._onBoot = function () { return _this.boot(); } - if (document.readyState === 'complete' || document.readyState === 'interactive') - { - window.setTimeout(this._onBoot, 0); - } - else - { - document.addEventListener('DOMContentLoaded', this._onBoot, false); - window.addEventListener('load', this._onBoot, false); - } + if (document.readyState === 'complete' || document.readyState === 'interactive') + { + window.setTimeout(this._onBoot, 0); + } + else + { + document.addEventListener('DOMContentLoaded', this._onBoot, false); + window.addEventListener('load', this._onBoot, false); + } - return this; + return this; }; Phaser.Game.prototype = { - /** - * Initialize engine sub modules and start the game. - * - * @method Phaser.Game#boot - * @protected - */ - boot: function () { + /** + * Initialize engine sub modules and start the game. + * + * @method Phaser.Game#boot + * @protected + */ + boot: function () { - if (this.isBooted) - { - return; - } + if (this.isBooted) + { + return; + } - if (!document.body) - { - window.setTimeout(this._onBoot, 20); - } - else - { - document.removeEventListener('DOMContentLoaded', this._onBoot); - window.removeEventListener('load', this._onBoot); + if (!document.body) + { + window.setTimeout(this._onBoot, 20); + } + else + { + document.removeEventListener('DOMContentLoaded', this._onBoot); + window.removeEventListener('load', this._onBoot); - this.onPause = new Phaser.Signal; - this.onResume = new Phaser.Signal; + this.onPause = new Phaser.Signal(); + this.onResume = new Phaser.Signal(); - this.isBooted = true; + this.isBooted = true; - this.device = new Phaser.Device(); - this.math = Phaser.Math; - this.rnd = new Phaser.RandomDataGenerator([(Date.now() * Math.random()).toString()]); + this.device = new Phaser.Device(); + this.math = Phaser.Math; + this.rnd = new Phaser.RandomDataGenerator([(Date.now() * Math.random()).toString()]); - this.stage = new Phaser.Stage(this, this.width, this.height); + this.stage = new Phaser.Stage(this, this.width, this.height); - this.setUpRenderer(); + this.setUpRenderer(); - this.world = new Phaser.World(this); - this.add = new Phaser.GameObjectFactory(this); - this.cache = new Phaser.Cache(this); - this.load = new Phaser.Loader(this); - this.time = new Phaser.Time(this); - this.tweens = new Phaser.TweenManager(this); - this.input = new Phaser.Input(this); - this.sound = new Phaser.SoundManager(this); - this.physics = new Phaser.Physics.Arcade(this); - this.particles = new Phaser.Particles(this); - this.plugins = new Phaser.PluginManager(this, this); - this.net = new Phaser.Net(this); - this.debug = new Phaser.Utils.Debug(this); + this.world = new Phaser.World(this); + this.add = new Phaser.GameObjectFactory(this); + this.cache = new Phaser.Cache(this); + this.load = new Phaser.Loader(this); + this.time = new Phaser.Time(this); + this.tweens = new Phaser.TweenManager(this); + this.input = new Phaser.Input(this); + this.sound = new Phaser.SoundManager(this); + this.physics = new Phaser.Physics.Arcade(this); + this.particles = new Phaser.Particles(this); + this.plugins = new Phaser.PluginManager(this, this); + this.net = new Phaser.Net(this); + this.debug = new Phaser.Utils.Debug(this); - this.stage.boot(); - this.world.boot(); - this.input.boot(); - this.sound.boot(); - this.state.boot(); + this.stage.boot(); + this.world.boot(); + this.input.boot(); + this.sound.boot(); + this.state.boot(); - this.load.onLoadComplete.add(this.loadComplete, this); + this.load.onLoadComplete.add(this.loadComplete, this); - this.showDebugHeader(); + this.showDebugHeader(); - this.isRunning = true; + this.isRunning = true; this._loadComplete = false; - this.raf = new Phaser.RequestAnimationFrame(this); - this.raf.start(); + this.raf = new Phaser.RequestAnimationFrame(this); + this.raf.start(); - } + } - }, + }, - /** + /** * Displays a Phaser version debug header in the console. * * @method Phaser.Game#showDebugHeader * @protected */ - showDebugHeader: function () { + showDebugHeader: function () { - var v = Phaser.DEV_VERSION; - var r = 'Canvas'; - var a = 'HTML Audio'; + var v = Phaser.DEV_VERSION; + var r = 'Canvas'; + var a = 'HTML Audio'; - if (this.renderType == Phaser.WEBGL) - { - r = 'WebGL'; - } + if (this.renderType == Phaser.WEBGL) + { + r = 'WebGL'; + } - if (this.device.webAudio) - { - a = 'WebAudio'; - } + if (this.device.webAudio) + { + a = 'WebAudio'; + } - if (this.device.chrome) - { - var args = [ - '%c %c %c Phaser v' + v + ' - Renderer: ' + r + ' - Audio: ' + a + ' %c %c ', - 'background: #00bff3', - 'background: #0072bc', - 'color: #ffffff; background: #003471', - 'background: #0072bc', - 'background: #00bff3' - ]; + if (this.device.chrome) + { + var args = [ + '%c %c %c Phaser v' + v + ' - Renderer: ' + r + ' - Audio: ' + a + ' %c %c ', + 'background: #00bff3', + 'background: #0072bc', + 'color: #ffffff; background: #003471', + 'background: #0072bc', + 'background: #00bff3' + ]; - console.log.apply(console, args); - } - else - { - console.log('Phaser v' + v + ' - Renderer: ' + r + ' - Audio: ' + a); - } + console.log.apply(console, args); + } + else + { + console.log('Phaser v' + v + ' - Renderer: ' + r + ' - Audio: ' + a); + } - }, + }, - /** - * Checks if the device is capable of using the requested renderer and sets it up or an alternative if not. - * - * @method Phaser.Game#setUpRenderer - * @protected - */ - setUpRenderer: function () { + /** + * Checks if the device is capable of using the requested renderer and sets it up or an alternative if not. + * + * @method Phaser.Game#setUpRenderer + * @protected + */ + setUpRenderer: function () { - if (this.renderType === Phaser.CANVAS || (this.renderType === Phaser.AUTO && this.device.webGL == false)) - { - if (this.device.canvas) - { - this.renderType = Phaser.CANVAS; - this.renderer = new PIXI.CanvasRenderer(this.width, this.height, this.stage.canvas, this.transparent); - Phaser.Canvas.setSmoothingEnabled(this.renderer.context, this.antialias); - this.canvas = this.renderer.view; - this.context = this.renderer.context; - } - else - { - throw new Error('Phaser.Game - cannot create Canvas or WebGL context, aborting.'); - } - } - else - { - // They requested WebGL, and their browser supports it - this.renderType = Phaser.WEBGL; - this.renderer = new PIXI.WebGLRenderer(this.width, this.height, this.stage.canvas, this.transparent, this.antialias); - this.canvas = this.renderer.view; - this.context = null; - } + if (this.renderType === Phaser.CANVAS || (this.renderType === Phaser.AUTO && this.device.webGL === false)) + { + if (this.device.canvas) + { + this.renderType = Phaser.CANVAS; + this.renderer = new PIXI.CanvasRenderer(this.width, this.height, this.stage.canvas, this.transparent); + Phaser.Canvas.setSmoothingEnabled(this.renderer.context, this.antialias); + this.canvas = this.renderer.view; + this.context = this.renderer.context; + } + else + { + throw new Error('Phaser.Game - cannot create Canvas or WebGL context, aborting.'); + } + } + else + { + // They requested WebGL, and their browser supports it + this.renderType = Phaser.WEBGL; + this.renderer = new PIXI.WebGLRenderer(this.width, this.height, this.stage.canvas, this.transparent, this.antialias); + this.canvas = this.renderer.view; + this.context = null; + } Phaser.Canvas.addToDOM(this.renderer.view, this.parent, true); Phaser.Canvas.setTouchAction(this.renderer.view); - }, + }, - /** + /** * Called when the load has finished, after preload was run. * * @method Phaser.Game#loadComplete @@ -411,61 +411,61 @@ Phaser.Game.prototype = { }, - /** + /** * The core game loop. * * @method Phaser.Game#update * @protected - * @param {number} time - The current time as provided by RequestAnimationFrame. + * @param {number} time - The current time as provided by RequestAnimationFrame. */ - update: function (time) { + update: function (time) { - this.time.update(time); + this.time.update(time); - if (this._paused) - { - this.renderer.render(this.stage._stage); - this.plugins.render(); - this.state.render(); - } - else - { - this.plugins.preUpdate(); - this.physics.preUpdate(); + if (this._paused) + { + this.renderer.render(this.stage._stage); + this.plugins.render(); + this.state.render(); + } + else + { + this.plugins.preUpdate(); + this.physics.preUpdate(); - this.stage.update(); - this.input.update(); - this.tweens.update(); - this.sound.update(); - this.world.update(); - this.particles.update(); - this.state.update(); - this.plugins.update(); + this.stage.update(); + this.input.update(); + this.tweens.update(); + this.sound.update(); + this.world.update(); + this.particles.update(); + this.state.update(); + this.plugins.update(); - this.world.postUpdate(); + this.world.postUpdate(); this.plugins.postUpdate(); - this.renderer.render(this.stage._stage); - this.plugins.render(); - this.state.render(); + this.renderer.render(this.stage._stage); + this.plugins.render(); + this.state.render(); - this.plugins.postRender(); - } + this.plugins.postRender(); + } - }, + }, - /** + /** * Nuke the entire game from orbit * * @method Phaser.Game#destroy */ destroy: function () { - this.raf.stop(); + this.raf.stop(); - this.input.destroy(); + this.input.destroy(); - this.state.destroy(); + this.state.destroy(); this.state = null; this.cache = null; @@ -495,22 +495,22 @@ Object.defineProperty(Phaser.Game.prototype, "paused", { set: function (value) { - if (value === true) - { - if (this._paused == false) - { - this._paused = true; - this.onPause.dispatch(this); - } - } - else - { - if (this._paused) - { - this._paused = false; - this.onResume.dispatch(this); - } - } + if (value === true) + { + if (this._paused === false) + { + this._paused = true; + this.onPause.dispatch(this); + } + } + else + { + if (this._paused) + { + this._paused = false; + this.onResume.dispatch(this); + } + } } diff --git a/src/core/Group.js b/src/core/Group.js index 053df527..fb1287bd 100644 --- a/src/core/Group.js +++ b/src/core/Group.js @@ -16,77 +16,77 @@ */ Phaser.Group = function (game, parent, name, useStage) { - if (typeof parent === 'undefined' || typeof parent === null) - { - parent = game.world; - } + if (typeof parent === 'undefined' || typeof parent === null) + { + parent = game.world; + } - if (typeof useStage === 'undefined') - { - useStage = false; - } + if (typeof useStage === 'undefined') + { + useStage = false; + } /** - * @property {Phaser.Game} game - A reference to the currently running Game. - */ - this.game = game; - + * @property {Phaser.Game} game - A reference to the currently running Game. + */ + this.game = game; + /** - * @property {string} name - A name for this Group. Not used internally but useful for debugging. - */ - this.name = name || 'group'; + * @property {string} name - A name for this Group. Not used internally but useful for debugging. + */ + this.name = name || 'group'; - if (useStage) - { - this._container = this.game.stage._stage; - } - else - { - this._container = new PIXI.DisplayObjectContainer(); - this._container.name = this.name; + if (useStage) + { + this._container = this.game.stage._stage; + } + else + { + this._container = new PIXI.DisplayObjectContainer(); + this._container.name = this.name; - if (parent) - { - if (parent instanceof Phaser.Group) - { - parent._container.addChild(this._container); - parent._container.updateTransform(); - } - else - { - parent.addChild(this._container); - parent.updateTransform(); - } - } - else - { - this.game.stage._stage.addChild(this._container); - this.game.stage._stage.updateTransform(); - } - } + if (parent) + { + if (parent instanceof Phaser.Group) + { + parent._container.addChild(this._container); + parent._container.updateTransform(); + } + else + { + parent.addChild(this._container); + parent.updateTransform(); + } + } + else + { + this.game.stage._stage.addChild(this._container); + this.game.stage._stage.updateTransform(); + } + } - /** - * @property {number} type - Internal Phaser Type value. - * @protected - */ - this.type = Phaser.GROUP; + /** + * @property {number} type - Internal Phaser Type value. + * @protected + */ + this.type = Phaser.GROUP; - /** - * @property {boolean} exists - If exists is true the the Group is updated, otherwise it is skipped. - * @default - */ - this.exists = true; + /** + * @property {boolean} exists - If exists is true the the Group is updated, otherwise it is skipped. + * @default + */ + this.exists = true; /** * @property {Phaser.Point} scale - Replaces the PIXI.Point with a slightly more flexible one. - */ + */ this.scale = new Phaser.Point(1, 1); /** * The cursor is a simple way to iterate through the objects in a Group using the Group.next and Group.previous functions. * The cursor is set to the first child added to the Group and doesn't change unless you call next, previous or set it directly with Group.cursor. * @property {any} cursor - The current display object that the Group cursor is pointing to. - */ + */ this.cursor = null; }; @@ -131,446 +131,446 @@ Phaser.Group.prototype = { * @see Phaser.Group#create * @see Phaser.Group#addAt * @method Phaser.Group#add - * @param {*} child - An instance of Phaser.Sprite, Phaser.Button or any other display object.. - * @return {*} The child that was added to the Group. + * @param {*} child - An instance of Phaser.Sprite, Phaser.Button or any other display object.. + * @return {*} The child that was added to the Group. */ - add: function (child) { + add: function (child) { - if (child.group !== this) - { - child.group = this; + if (child.group !== this) + { + child.group = this; - if (child.events) - { - child.events.onAddedToGroup.dispatch(child, this); - } + if (child.events) + { + child.events.onAddedToGroup.dispatch(child, this); + } - this._container.addChild(child); + this._container.addChild(child); - child.updateTransform(); + child.updateTransform(); - if (this.cursor === null) - { - this.cursor = child; - } - } + if (this.cursor === null) + { + this.cursor = child; + } + } - return child; + return child; - }, + }, /** * Adds an existing object to this Group. The object can be an instance of Phaser.Sprite, Phaser.Button or any other display object. * The child is added to the Group at the location specified by the index value, this allows you to control child ordering. - * + * * @method Phaser.Group#addAt - * @param {*} child - An instance of Phaser.Sprite, Phaser.Button or any other display object.. - * @param {number} index - The index within the Group to insert the child to. - * @return {*} The child that was added to the Group. - */ - addAt: function (child, index) { + * @param {*} child - An instance of Phaser.Sprite, Phaser.Button or any other display object.. + * @param {number} index - The index within the Group to insert the child to. + * @return {*} The child that was added to the Group. + */ + addAt: function (child, index) { - if (child.group !== this) - { - child.group = this; + if (child.group !== this) + { + child.group = this; - if (child.events) - { - child.events.onAddedToGroup.dispatch(child, this); - } + if (child.events) + { + child.events.onAddedToGroup.dispatch(child, this); + } - this._container.addChildAt(child, index); + this._container.addChildAt(child, index); - child.updateTransform(); + child.updateTransform(); - if (this.cursor === null) - { - this.cursor = child; - } - } + if (this.cursor === null) + { + this.cursor = child; + } + } - return child; + return child; - }, + }, /** - * Returns the child found at the given index within this Group. - * + * Returns the child found at the given index within this Group. + * * @method Phaser.Group#getAt * @memberof Phaser.Group - * @param {number} index - The index to return the child from. - * @return {*} The child that was found at the given index. - */ - getAt: function (index) { + * @param {number} index - The index to return the child from. + * @return {*} The child that was found at the given index. + */ + getAt: function (index) { - return this._container.getChildAt(index); + return this._container.getChildAt(index); - }, + }, /** - * Automatically creates a new Phaser.Sprite object and adds it to the top of this Group. - * Useful if you don't need to create the Sprite instances before-hand. - * + * Automatically creates a new Phaser.Sprite object and adds it to the top of this Group. + * Useful if you don't need to create the Sprite instances before-hand. + * * @method Phaser.Group#create - * @param {number} x - The x coordinate to display the newly created Sprite at. The value is in relation to the Group.x point. - * @param {number} y - The y coordinate to display the newly created Sprite at. The value is in relation to the Group.y point. - * @param {string} key - The Game.cache key of the image that this Sprite will use. - * @param {number|string} [frame] - If the Sprite image contains multiple frames you can specify which one to use here. - * @param {boolean} [exists=true] - The default exists state of the Sprite. - * @return {Phaser.Sprite} The child that was created. - */ - create: function (x, y, key, frame, exists) { + * @param {number} x - The x coordinate to display the newly created Sprite at. The value is in relation to the Group.x point. + * @param {number} y - The y coordinate to display the newly created Sprite at. The value is in relation to the Group.y point. + * @param {string} key - The Game.cache key of the image that this Sprite will use. + * @param {number|string} [frame] - If the Sprite image contains multiple frames you can specify which one to use here. + * @param {boolean} [exists=true] - The default exists state of the Sprite. + * @return {Phaser.Sprite} The child that was created. + */ + create: function (x, y, key, frame, exists) { - if (typeof exists == 'undefined') { exists = true; } + if (typeof exists == 'undefined') { exists = true; } - var child = new Phaser.Sprite(this.game, x, y, key, frame); + var child = new Phaser.Sprite(this.game, x, y, key, frame); - child.group = this; - child.exists = exists; - child.visible = exists; - child.alive = exists; + child.group = this; + child.exists = exists; + child.visible = exists; + child.alive = exists; - if (child.events) - { - child.events.onAddedToGroup.dispatch(child, this); - } + if (child.events) + { + child.events.onAddedToGroup.dispatch(child, this); + } - this._container.addChild(child); - - child.updateTransform(); + this._container.addChild(child); + + child.updateTransform(); - if (this.cursor === null) - { - this.cursor = child; - } + if (this.cursor === null) + { + this.cursor = child; + } - return child; + return child; - }, + }, /** - * Automatically creates multiple Phaser.Sprite objects and adds them to the top of this Group. - * Useful if you need to quickly generate a pool of identical sprites, such as bullets. By default the sprites will be set to not exist - * and will be positioned at 0, 0 (relative to the Group.x/y) - * + * Automatically creates multiple Phaser.Sprite objects and adds them to the top of this Group. + * Useful if you need to quickly generate a pool of identical sprites, such as bullets. By default the sprites will be set to not exist + * and will be positioned at 0, 0 (relative to the Group.x/y) + * * @method Phaser.Group#createMultiple - * @param {number} quantity - The number of Sprites to create. - * @param {string} key - The Game.cache key of the image that this Sprite will use. - * @param {number|string} [frame] - If the Sprite image contains multiple frames you can specify which one to use here. - * @param {boolean} [exists=false] - The default exists state of the Sprite. - */ - createMultiple: function (quantity, key, frame, exists) { + * @param {number} quantity - The number of Sprites to create. + * @param {string} key - The Game.cache key of the image that this Sprite will use. + * @param {number|string} [frame] - If the Sprite image contains multiple frames you can specify which one to use here. + * @param {boolean} [exists=false] - The default exists state of the Sprite. + */ + createMultiple: function (quantity, key, frame, exists) { - if (typeof exists == 'undefined') { exists = false; } + if (typeof exists == 'undefined') { exists = false; } - for (var i = 0; i < quantity; i++) - { - var child = new Phaser.Sprite(this.game, 0, 0, key, frame); + for (var i = 0; i < quantity; i++) + { + var child = new Phaser.Sprite(this.game, 0, 0, key, frame); - child.group = this; - child.exists = exists; - child.visible = exists; - child.alive = exists; + child.group = this; + child.exists = exists; + child.visible = exists; + child.alive = exists; - if (child.events) - { - child.events.onAddedToGroup.dispatch(child, this); - } + if (child.events) + { + child.events.onAddedToGroup.dispatch(child, this); + } - this._container.addChild(child); - child.updateTransform(); + this._container.addChild(child); + child.updateTransform(); - if (this.cursor === null) - { - this.cursor = child; - } + if (this.cursor === null) + { + this.cursor = child; + } - } + } - }, + }, /** - * Advances the Group cursor to the next object in the Group. If it's at the end of the Group it wraps around to the first object. - * + * Advances the Group cursor to the next object in the Group. If it's at the end of the Group it wraps around to the first object. + * * @method Phaser.Group#next - */ - next: function () { + */ + next: function () { - if (this.cursor) - { - // Wrap the cursor? - if (this.cursor == this._container.last) - { - this.cursor = this._container._iNext; - } - else - { - this.cursor = this.cursor._iNext; - } - } + if (this.cursor) + { + // Wrap the cursor? + if (this.cursor == this._container.last) + { + this.cursor = this._container._iNext; + } + else + { + this.cursor = this.cursor._iNext; + } + } - }, + }, /** - * Moves the Group cursor to the previous object in the Group. If it's at the start of the Group it wraps around to the last object. - * + * Moves the Group cursor to the previous object in the Group. If it's at the start of the Group it wraps around to the last object. + * * @method Phaser.Group#previous - */ - previous: function () { + */ + previous: function () { - if (this.cursor) - { - // Wrap the cursor? - if (this.cursor == this._container._iNext) - { - this.cursor = this._container.last; - } - else - { - this.cursor = this.cursor._iPrev; - } - } + if (this.cursor) + { + // Wrap the cursor? + if (this.cursor == this._container._iNext) + { + this.cursor = this._container.last; + } + else + { + this.cursor = this.cursor._iPrev; + } + } - }, + }, - childTest: function (prefix, child) { + childTest: function (prefix, child) { - var s = prefix + ' next: '; + var s = prefix + ' next: '; - if (child._iNext) - { - s = s + child._iNext.name; - } - else - { - s = s + '-null-'; - } + if (child._iNext) + { + s = s + child._iNext.name; + } + else + { + s = s + '-null-'; + } - s = s + ' ' + prefix + ' prev: '; + s = s + ' ' + prefix + ' prev: '; - if (child._iPrev) - { - s = s + child._iPrev.name; - } - else - { - s = s + '-null-'; - } + if (child._iPrev) + { + s = s + child._iPrev.name; + } + else + { + s = s + '-null-'; + } - console.log(s); + console.log(s); - }, + }, - swapIndex: function (index1, index2) { + swapIndex: function (index1, index2) { - var child1 = this.getAt(index1); - var child2 = this.getAt(index2); + var child1 = this.getAt(index1); + var child2 = this.getAt(index2); - console.log('swapIndex ', index1, ' with ', index2); + console.log('swapIndex ', index1, ' with ', index2); - this.swap(child1, child2); + this.swap(child1, child2); - }, + }, - /** - * Swaps the position of two children in this Group. Both children must be in this Group. - * You cannot swap a child with itself, or swap un-parented children, doing so will return false. - * + /** + * Swaps the position of two children in this Group. Both children must be in this Group. + * You cannot swap a child with itself, or swap un-parented children, doing so will return false. + * * @method Phaser.Group#swap - * @param {*} child1 - The first child to swap. - * @param {*} child2 - The second child to swap. + * @param {*} child1 - The first child to swap. + * @param {*} child2 - The second child to swap. * @return {boolean} True if the swap was successful, otherwise false. - */ - swap: function (child1, child2) { + */ + swap: function (child1, child2) { - if (child1 === child2 || !child1.parent || !child2.parent || child1.group !== this || child2.group !== this) - { - return false; - } + if (child1 === child2 || !child1.parent || !child2.parent || child1.group !== this || child2.group !== this) + { + return false; + } - // Cache the values - var child1Prev = child1._iPrev; - var child1Next = child1._iNext; - var child2Prev = child2._iPrev; - var child2Next = child2._iNext; + // Cache the values + var child1Prev = child1._iPrev; + var child1Next = child1._iNext; + var child2Prev = child2._iPrev; + var child2Next = child2._iNext; - var endNode = this._container.last._iNext; - var currentNode = this.game.stage._stage; - - do - { - if (currentNode !== child1 && currentNode !== child2) - { - if (currentNode.first === child1) - { - currentNode.first = child2; - } - else if (currentNode.first === child2) - { - currentNode.first = child1; - } + var endNode = this._container.last._iNext; + var currentNode = this.game.stage._stage; + + do + { + if (currentNode !== child1 && currentNode !== child2) + { + if (currentNode.first === child1) + { + currentNode.first = child2; + } + else if (currentNode.first === child2) + { + currentNode.first = child1; + } - if (currentNode.last === child1) - { - currentNode.last = child2; - } - else if (currentNode.last === child2) - { - currentNode.last = child1; - } - } + if (currentNode.last === child1) + { + currentNode.last = child2; + } + else if (currentNode.last === child2) + { + currentNode.last = child1; + } + } - currentNode = currentNode._iNext; - } - while (currentNode != endNode) + currentNode = currentNode._iNext; + } + while (currentNode != endNode) - if (child1._iNext == child2) - { - // This is a downward (A to B) neighbour swap - child1._iNext = child2Next; - child1._iPrev = child2; - child2._iNext = child1; - child2._iPrev = child1Prev; + if (child1._iNext == child2) + { + // This is a downward (A to B) neighbour swap + child1._iNext = child2Next; + child1._iPrev = child2; + child2._iNext = child1; + child2._iPrev = child1Prev; - if (child1Prev) { child1Prev._iNext = child2; } - if (child2Next) { child2Next._iPrev = child1; } + if (child1Prev) { child1Prev._iNext = child2; } + if (child2Next) { child2Next._iPrev = child1; } - if (child1.__renderGroup) - { - child1.__renderGroup.updateTexture(child1); - } + if (child1.__renderGroup) + { + child1.__renderGroup.updateTexture(child1); + } - if (child2.__renderGroup) - { - child2.__renderGroup.updateTexture(child2); - } + if (child2.__renderGroup) + { + child2.__renderGroup.updateTexture(child2); + } - return true; - } - else if (child2._iNext == child1) - { - // This is an upward (B to A) neighbour swap - child1._iNext = child2; - child1._iPrev = child2Prev; - child2._iNext = child1Next; - child2._iPrev = child1; + return true; + } + else if (child2._iNext == child1) + { + // This is an upward (B to A) neighbour swap + child1._iNext = child2; + child1._iPrev = child2Prev; + child2._iNext = child1Next; + child2._iPrev = child1; - if (child2Prev) { child2Prev._iNext = child1; } - if (child1Next) { child1Next._iPrev = child2; } + if (child2Prev) { child2Prev._iNext = child1; } + if (child1Next) { child1Next._iPrev = child2; } - if (child1.__renderGroup) - { - child1.__renderGroup.updateTexture(child1); - } + if (child1.__renderGroup) + { + child1.__renderGroup.updateTexture(child1); + } - if (child2.__renderGroup) - { - child2.__renderGroup.updateTexture(child2); - } + if (child2.__renderGroup) + { + child2.__renderGroup.updateTexture(child2); + } - return true; - } - else - { - // Children are far apart - child1._iNext = child2Next; - child1._iPrev = child2Prev; - child2._iNext = child1Next; - child2._iPrev = child1Prev; + return true; + } + else + { + // Children are far apart + child1._iNext = child2Next; + child1._iPrev = child2Prev; + child2._iNext = child1Next; + child2._iPrev = child1Prev; - if (child1Prev) { child1Prev._iNext = child2; } - if (child1Next) { child1Next._iPrev = child2; } - if (child2Prev) { child2Prev._iNext = child1; } - if (child2Next) { child2Next._iPrev = child1; } + if (child1Prev) { child1Prev._iNext = child2; } + if (child1Next) { child1Next._iPrev = child2; } + if (child2Prev) { child2Prev._iNext = child1; } + if (child2Next) { child2Next._iPrev = child1; } - if (child1.__renderGroup) - { - child1.__renderGroup.updateTexture(child1); - } + if (child1.__renderGroup) + { + child1.__renderGroup.updateTexture(child1); + } - if (child2.__renderGroup) - { - child2.__renderGroup.updateTexture(child2); - } + if (child2.__renderGroup) + { + child2.__renderGroup.updateTexture(child2); + } - return true; - } + return true; + } - return false; - - }, + return false; + + }, - /** - * Brings the given child to the top of this Group so it renders above all other children. - * + /** + * Brings the given child to the top of this Group so it renders above all other children. + * * @method Phaser.Group#bringToTop - * @param {*} child - The child to bring to the top of this Group. + * @param {*} child - The child to bring to the top of this Group. * @return {*} The child that was moved. - */ - bringToTop: function (child) { + */ + bringToTop: function (child) { - if (child.group === this) - { - this.remove(child); - this.add(child); - } + if (child.group === this) + { + this.remove(child); + this.add(child); + } - return child; + return child; - }, + }, - /** - * Get the index position of the given child in this Group. - * + /** + * Get the index position of the given child in this Group. + * * @method Phaser.Group#getIndex - * @param {*} child - The child to get the index for. + * @param {*} child - The child to get the index for. * @return {number} The index of the child or -1 if it's not a member of this Group. - */ - getIndex: function (child) { + */ + getIndex: function (child) { - return this._container.children.indexOf(child); + return this._container.children.indexOf(child); - }, + }, - /** - * Replaces a child of this Group with the given newChild. The newChild cannot be a member of this Group. - * + /** + * Replaces a child of this Group with the given newChild. The newChild cannot be a member of this Group. + * * @method Phaser.Group#replace - * @param {*} oldChild - The child in this Group that will be replaced. - * @param {*} newChild - The child to be inserted into this group. - */ - replace: function (oldChild, newChild) { + * @param {*} oldChild - The child in this Group that will be replaced. + * @param {*} newChild - The child to be inserted into this group. + */ + replace: function (oldChild, newChild) { - if (!this._container.first._iNext) - { - return; - } + if (!this._container.first._iNext) + { + return; + } - var index = this.getIndex(oldChild); - - if (index != -1) - { - if (newChild.parent != undefined) - { - newChild.events.onRemovedFromGroup.dispatch(newChild, this); - newChild.parent.removeChild(newChild); - } + var index = this.getIndex(oldChild); + + if (index != -1) + { + if (newChild.parent !== undefined) + { + newChild.events.onRemovedFromGroup.dispatch(newChild, this); + newChild.parent.removeChild(newChild); + } - this._container.removeChild(oldChild); - this._container.addChildAt(newChild, index); + this._container.removeChild(oldChild); + this._container.addChildAt(newChild, index); - newChild.events.onAddedToGroup.dispatch(newChild, this); - newChild.updateTransform(); + newChild.events.onAddedToGroup.dispatch(newChild, this); + newChild.updateTransform(); - if (this.cursor == oldChild) - { - this.cursor = this._container._iNext; - } - } + if (this.cursor == oldChild) + { + this.cursor = this._container._iNext; + } + } - }, + }, - /** + /** * Sets the given property to the given value on the child. The operation controls the assignment of the value. * * @method Phaser.Group#setProperty @@ -579,62 +579,60 @@ Phaser.Group.prototype = { * @param {*} value - The value that will be set. * @param {number} [operation=0] - Controls how the value is assigned. A value of 0 replaces the value with the new one. A value of 1 adds it, 2 subtracts it, 3 multiplies it and 4 divides it. */ - setProperty: function (child, key, value, operation) { + setProperty: function (child, key, value, operation) { - operation = operation || 0; + operation = operation || 0; - // As ugly as this approach looks, and although it's limited to a depth of only 4, it's extremely fast. - // Much faster than a for loop or object iteration. There are no checks, so if the key isn't valid then it'll fail - // but as you are likely to call this from inner loops that have to perform well, I'll take that trade off. + // As ugly as this approach looks, and although it's limited to a depth of only 4, it's extremely fast. + // Much faster than a for loop or object iteration. There are no checks, so if the key isn't valid then it'll fail + // but as you are likely to call this from inner loops that have to perform well, I'll take that trade off. - // 0 = Equals - // 1 = Add - // 2 = Subtract - // 3 = Multiply - // 4 = Divide + // 0 = Equals + // 1 = Add + // 2 = Subtract + // 3 = Multiply + // 4 = Divide - var len = key.length; + var len = key.length; - if (len == 1) - { - if (operation == 0) { child[key[0]] = value; } - else if (operation == 1) { child[key[0]] += value; } - else if (operation == 2) { child[key[0]] -= value; } - else if (operation == 3) { child[key[0]] *= value; } - else if (operation == 4) { child[key[0]] /= value; } - } - else if (len == 2) - { - if (operation == 0) { child[key[0]][key[1]] = value; } - else if (operation == 1) { child[key[0]][key[1]] += value; } - else if (operation == 2) { child[key[0]][key[1]] -= value; } - else if (operation == 3) { child[key[0]][key[1]] *= value; } - else if (operation == 4) { child[key[0]][key[1]] /= value; } - } - else if (len == 3) - { - if (operation == 0) { child[key[0]][key[1]][key[2]] = value; } - else if (operation == 1) { child[key[0]][key[1]][key[2]] += value; } - else if (operation == 2) { child[key[0]][key[1]][key[2]] -= value; } - else if (operation == 3) { child[key[0]][key[1]][key[2]] *= value; } - else if (operation == 4) { child[key[0]][key[1]][key[2]] /= value; } - } - else if (len == 4) - { - if (operation == 0) { child[key[0]][key[1]][key[2]][key[3]] = value; } - else if (operation == 1) { child[key[0]][key[1]][key[2]][key[3]] += value; } - else if (operation == 2) { child[key[0]][key[1]][key[2]][key[3]] -= value; } - else if (operation == 3) { child[key[0]][key[1]][key[2]][key[3]] *= value; } - else if (operation == 4) { child[key[0]][key[1]][key[2]][key[3]] /= value; } - } - else - { - // TODO - Deep property scane - } + if (len == 1) + { + if (operation === 0) { child[key[0]] = value; } + else if (operation == 1) { child[key[0]] += value; } + else if (operation == 2) { child[key[0]] -= value; } + else if (operation == 3) { child[key[0]] *= value; } + else if (operation == 4) { child[key[0]] /= value; } + } + else if (len == 2) + { + if (operation === 0) { child[key[0]][key[1]] = value; } + else if (operation == 1) { child[key[0]][key[1]] += value; } + else if (operation == 2) { child[key[0]][key[1]] -= value; } + else if (operation == 3) { child[key[0]][key[1]] *= value; } + else if (operation == 4) { child[key[0]][key[1]] /= value; } + } + else if (len == 3) + { + if (operation === 0) { child[key[0]][key[1]][key[2]] = value; } + else if (operation == 1) { child[key[0]][key[1]][key[2]] += value; } + else if (operation == 2) { child[key[0]][key[1]][key[2]] -= value; } + else if (operation == 3) { child[key[0]][key[1]][key[2]] *= value; } + else if (operation == 4) { child[key[0]][key[1]][key[2]] /= value; } + } + else if (len == 4) + { + if (operation === 0) { child[key[0]][key[1]][key[2]][key[3]] = value; } + else if (operation == 1) { child[key[0]][key[1]][key[2]][key[3]] += value; } + else if (operation == 2) { child[key[0]][key[1]][key[2]][key[3]] -= value; } + else if (operation == 3) { child[key[0]][key[1]][key[2]][key[3]] *= value; } + else if (operation == 4) { child[key[0]][key[1]][key[2]][key[3]] /= value; } + } + + // TODO - Deep property scane - }, + }, - /** + /** * This function allows you to quickly set the same property across all children of this Group to a new value. * The operation parameter controls how the new value is assigned to the property, from simple replacement to addition and multiplication. * @@ -645,34 +643,34 @@ Phaser.Group.prototype = { * @param {boolean} [checkVisible=false] - If set then only children with visible=true will be updated. * @param {number} [operation=0] - Controls how the value is assigned. A value of 0 replaces the value with the new one. A value of 1 adds it, 2 subtracts it, 3 multiplies it and 4 divides it. */ - setAll: function (key, value, checkAlive, checkVisible, operation) { + setAll: function (key, value, checkAlive, checkVisible, operation) { - key = key.split('.'); + key = key.split('.'); - if (typeof checkAlive === 'undefined') { checkAlive = false; } - if (typeof checkVisible === 'undefined') { checkVisible = false; } + if (typeof checkAlive === 'undefined') { checkAlive = false; } + if (typeof checkVisible === 'undefined') { checkVisible = false; } - operation = operation || 0; + operation = operation || 0; - if (this._container.children.length > 0 && this._container.first._iNext) - { - var currentNode = this._container.first._iNext; - - do - { - if ((checkAlive == false || (checkAlive && currentNode.alive)) && (checkVisible == false || (checkVisible && currentNode.visible))) - { - this.setProperty(currentNode, key, value, operation); - } + if (this._container.children.length > 0 && this._container.first._iNext) + { + var currentNode = this._container.first._iNext; + + do + { + if ((checkAlive === false || (checkAlive && currentNode.alive)) && (checkVisible === false || (checkVisible && currentNode.visible))) + { + this.setProperty(currentNode, key, value, operation); + } - currentNode = currentNode._iNext; - } - while (currentNode != this._container.last._iNext) - } + currentNode = currentNode._iNext; + } + while (currentNode != this._container.last._iNext) + } - }, + }, - /** + /** * 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. * @@ -682,13 +680,13 @@ Phaser.Group.prototype = { * @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) { + addAll: function (property, amount, checkAlive, checkVisible) { - this.setAll(property, amount, checkAlive, checkVisible, 1); + this.setAll(property, amount, checkAlive, checkVisible, 1); - }, + }, - /** + /** * 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. * @@ -698,13 +696,13 @@ Phaser.Group.prototype = { * @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) { + subAll: function (property, amount, checkAlive, checkVisible) { - this.setAll(property, amount, checkAlive, checkVisible, 2); + this.setAll(property, amount, checkAlive, checkVisible, 2); - }, + }, - /** + /** * Multiplies the given property by the amount on all children in this Group. * Group.multiplyAll('x', 2) will x2 the child.x value. * @@ -714,13 +712,13 @@ Phaser.Group.prototype = { * @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) { + multiplyAll: function (property, amount, checkAlive, checkVisible) { - this.setAll(property, amount, checkAlive, checkVisible, 3); + this.setAll(property, amount, checkAlive, checkVisible, 3); - }, + }, - /** + /** * Divides the given property by the amount on all children in this Group. * Group.divideAll('x', 2) will half the child.x value. * @@ -730,13 +728,13 @@ Phaser.Group.prototype = { * @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) { + divideAll: function (property, amount, checkAlive, checkVisible) { - this.setAll(property, amount, checkAlive, checkVisible, 4); + this.setAll(property, amount, checkAlive, checkVisible, 4); - }, + }, - /** + /** * 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. * @@ -745,30 +743,30 @@ Phaser.Group.prototype = { * @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) { + callAllExists: function (callback, existsValue) { - var args = Array.prototype.splice.call(arguments, 2); + var args = Array.prototype.splice.call(arguments, 2); - if (this._container.children.length > 0 && this._container.first._iNext) - { - var currentNode = this._container.first._iNext; - - do - { - if (currentNode.exists == existsValue && currentNode[callback]) - { - currentNode[callback].apply(currentNode, args); - } + if (this._container.children.length > 0 && this._container.first._iNext) + { + var currentNode = this._container.first._iNext; + + do + { + if (currentNode.exists == existsValue && currentNode[callback]) + { + currentNode[callback].apply(currentNode, args); + } - currentNode = currentNode._iNext; - } - while (currentNode != this._container.last._iNext) + currentNode = currentNode._iNext; + } + while (currentNode != this._container.last._iNext) - } + } - }, + }, - /** + /** * Calls a function on all of the children that have exists=true in this Group. * * @method Phaser.Group#callbackFromArray @@ -777,51 +775,51 @@ Phaser.Group.prototype = { * @param {number} length - The size of the array (pre-calculated in callAll). * @protected */ - callbackFromArray: function (child, callback, length) { + callbackFromArray: function (child, callback, length) { - // Kinda looks like a Christmas tree + // Kinda looks like a Christmas tree - if (length == 1) - { - if (child[callback[0]]) - { - return child[callback[0]]; - } - } - else if (length == 2) - { - if (child[callback[0]][callback[1]]) - { - return child[callback[0]][callback[1]]; - } - } - else if (length == 3) - { - if (child[callback[0]][callback[1]][callback[2]]) - { - return child[callback[0]][callback[1]][callback[2]]; - } - } - else if (length == 4) - { - if (child[callback[0]][callback[1]][callback[2]][callback[3]]) - { - return child[callback[0]][callback[1]][callback[2]][callback[3]]; - } - } - else - { - if (child[callback]) - { - return child[callback]; - } - } + if (length == 1) + { + if (child[callback[0]]) + { + return child[callback[0]]; + } + } + else if (length == 2) + { + if (child[callback[0]][callback[1]]) + { + return child[callback[0]][callback[1]]; + } + } + else if (length == 3) + { + if (child[callback[0]][callback[1]][callback[2]]) + { + return child[callback[0]][callback[1]][callback[2]]; + } + } + else if (length == 4) + { + if (child[callback[0]][callback[1]][callback[2]][callback[3]]) + { + return child[callback[0]][callback[1]][callback[2]][callback[3]]; + } + } + else + { + if (child[callback]) + { + return child[callback]; + } + } - return false; + return false; - }, + }, - /** + /** * 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 method parameter and context you can add as many extra parameters as you like, which will all be passed to the child. * @@ -830,341 +828,342 @@ Phaser.Group.prototype = { * @param {string} [context=''] - A string containing the context under which the method will be executed. Leave to '' to default to the child. * @param {...*} parameter - Additional parameters that will be passed to the method. */ - callAll: function (method, context) { + callAll: function (method, context) { - if (typeof method === 'undefined') - { - return; - } + if (typeof method === 'undefined') + { + return; + } - // Extract the method into an array - method = method.split('.'); + // Extract the method into an array + method = method.split('.'); - var methodLength = method.length; + var methodLength = method.length; - if (typeof context === 'undefined') - { - context = null; - } - else - { - // Extract the context into an array - if (typeof context === 'string') - { - context = context.split('.'); - var contextLength = context.length; - } - } + if (typeof context === 'undefined') + { + context = null; + } + else + { + // Extract the context into an array + if (typeof context === 'string') + { + context = context.split('.'); + var contextLength = context.length; + } + } - var args = Array.prototype.splice.call(arguments, 2); - var callback = null; + var args = Array.prototype.splice.call(arguments, 2); + var callback = null; + var callbackContext = null; - if (this._container.children.length > 0 && this._container.first._iNext) - { - var child = this._container.first._iNext; - - do - { - callback = this.callbackFromArray(child, method, methodLength); + if (this._container.children.length > 0 && this._container.first._iNext) + { + var child = this._container.first._iNext; + + do + { + callback = this.callbackFromArray(child, method, methodLength); - if (context && callback) - { - callbackContext = this.callbackFromArray(child, context, contextLength); - - if (callback) - { - callback.apply(callbackContext, args); - } - } - else if (callback) - { - callback.apply(child, args); - } + if (context && callback) + { + callbackContext = this.callbackFromArray(child, context, contextLength); + + if (callback) + { + callback.apply(callbackContext, args); + } + } + else if (callback) + { + callback.apply(child, args); + } - child = child._iNext; - } - while (child != this._container.last._iNext) + child = child._iNext; + } + while (child != this._container.last._iNext) - } + } - }, + }, - /** - * Allows you to call your own function on each member of this Group. You must pass the callback and context in which it will run. - * 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. - * For example: Group.forEach(awardBonusGold, this, true, 100, 500) - * - * @method Phaser.Group#forEach - * @param {function} callback - The function that will be called. Each child of the Group will be passed to it as its first parameter. + /** + * Allows you to call your own function on each member of this Group. You must pass the callback and context in which it will run. + * 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. + * For example: Group.forEach(awardBonusGold, this, true, 100, 500) + * + * @method Phaser.Group#forEach + * @param {function} callback - The function that will be called. Each child of the Group will be passed to it as its first parameter. * @param {Object} callbackContext - The context in which the function should be called (usually 'this'). * @param {boolean} checkExists - If set only children with exists=true will be passed to the callback, otherwise all children will be passed. - */ - forEach: function (callback, callbackContext, checkExists) { + */ + forEach: function (callback, callbackContext, checkExists) { - if (typeof checkExists === 'undefined') - { - checkExists = false; - } + if (typeof checkExists === 'undefined') + { + checkExists = false; + } - var args = Array.prototype.splice.call(arguments, 3); - args.unshift(null); + var args = Array.prototype.splice.call(arguments, 3); + args.unshift(null); - if (this._container.children.length > 0 && this._container.first._iNext) - { - var currentNode = this._container.first._iNext; - - do - { - if (checkExists == false || (checkExists && currentNode.exists)) - { - args[0] = currentNode; - callback.apply(callbackContext, args); - } + if (this._container.children.length > 0 && this._container.first._iNext) + { + var currentNode = this._container.first._iNext; + + do + { + if (checkExists === false || (checkExists && currentNode.exists)) + { + args[0] = currentNode; + callback.apply(callbackContext, args); + } - currentNode = currentNode._iNext; - } - while (currentNode != this._container.last._iNext); + currentNode = currentNode._iNext; + } + while (currentNode != this._container.last._iNext); - } + } - }, + }, - /** - * Allows you to call your own function on each alive member of this Group (where child.alive=true). You must pass the callback and context in which it will run. - * You can add as many parameters as you like, which will all be passed to the callback along with the child. - * For example: Group.forEachAlive(causeDamage, this, 500) - * - * @method Phaser.Group#forEachAlive - * @param {function} callback - The function that will be called. Each child of the Group will be passed to it as its first parameter. + /** + * Allows you to call your own function on each alive member of this Group (where child.alive=true). You must pass the callback and context in which it will run. + * You can add as many parameters as you like, which will all be passed to the callback along with the child. + * For example: Group.forEachAlive(causeDamage, this, 500) + * + * @method Phaser.Group#forEachAlive + * @param {function} callback - The function that will be called. Each child of the Group will be passed to it as its first parameter. * @param {Object} callbackContext - The context in which the function should be called (usually 'this'). - */ - forEachExists: function (callback, callbackContext) { + */ + forEachExists: function (callback, callbackContext) { - var args = Array.prototype.splice.call(arguments, 2); - args.unshift(null); + var args = Array.prototype.splice.call(arguments, 2); + args.unshift(null); - this.iterate('exists', true, Phaser.Group.RETURN_TOTAL, callback, callbackContext, args); + this.iterate('exists', true, Phaser.Group.RETURN_TOTAL, callback, callbackContext, args); - }, + }, - /** - * Allows you to call your own function on each alive member of this Group (where child.alive=true). You must pass the callback and context in which it will run. - * You can add as many parameters as you like, which will all be passed to the callback along with the child. - * For example: Group.forEachAlive(causeDamage, this, 500) - * - * @method Phaser.Group#forEachAlive - * @param {function} callback - The function that will be called. Each child of the Group will be passed to it as its first parameter. + /** + * Allows you to call your own function on each alive member of this Group (where child.alive=true). You must pass the callback and context in which it will run. + * You can add as many parameters as you like, which will all be passed to the callback along with the child. + * For example: Group.forEachAlive(causeDamage, this, 500) + * + * @method Phaser.Group#forEachAlive + * @param {function} callback - The function that will be called. Each child of the Group will be passed to it as its first parameter. * @param {Object} callbackContext - The context in which the function should be called (usually 'this'). - */ - forEachAlive: function (callback, callbackContext) { + */ + forEachAlive: function (callback, callbackContext) { - var args = Array.prototype.splice.call(arguments, 2); - args.unshift(null); + var args = Array.prototype.splice.call(arguments, 2); + args.unshift(null); - this.iterate('alive', true, Phaser.Group.RETURN_TOTAL, callback, callbackContext, args); + this.iterate('alive', true, Phaser.Group.RETURN_TOTAL, callback, callbackContext, args); - }, + }, - /** - * Allows you to call your own function on each dead member of this Group (where alive=false). You must pass the callback and context in which it will run. - * You can add as many parameters as you like, which will all be passed to the callback along with the child. - * For example: Group.forEachDead(bringToLife, this) - * - * @method Phaser.Group#forEachDead - * @param {function} callback - The function that will be called. Each child of the Group will be passed to it as its first parameter. + /** + * Allows you to call your own function on each dead member of this Group (where alive=false). You must pass the callback and context in which it will run. + * You can add as many parameters as you like, which will all be passed to the callback along with the child. + * For example: Group.forEachDead(bringToLife, this) + * + * @method Phaser.Group#forEachDead + * @param {function} callback - The function that will be called. Each child of the Group will be passed to it as its first parameter. * @param {Object} callbackContext - The context in which the function should be called (usually 'this'). - */ - forEachDead: function (callback, callbackContext) { + */ + forEachDead: function (callback, callbackContext) { - var args = Array.prototype.splice.call(arguments, 2); - args.unshift(null); + var args = Array.prototype.splice.call(arguments, 2); + args.unshift(null); - this.iterate('alive', false, Phaser.Group.RETURN_TOTAL, callback, callbackContext, args); + this.iterate('alive', false, Phaser.Group.RETURN_TOTAL, callback, callbackContext, args); - }, + }, - /** - * Call this function to sort the group according to a particular value and order. - * For example to depth sort Sprites for Zelda-style game you might call `group.sort('y', Phaser.Group.SORT_ASCENDING)` at the bottom of your `State.update()`. - * - * @method Phaser.Group#sort - * @param {string} [index='y'] - The `string` name of the property you want to sort on. - * @param {number} [order=Phaser.Group.SORT_ASCENDING] - The `Group` constant that defines the sort order. Possible values are Phaser.Group.SORT_ASCENDING and Phaser.Group.SORT_DESCENDING. - */ - sort: function (index, order) { + /** + * Call this function to sort the group according to a particular value and order. + * For example to depth sort Sprites for Zelda-style game you might call `group.sort('y', Phaser.Group.SORT_ASCENDING)` at the bottom of your `State.update()`. + * + * @method Phaser.Group#sort + * @param {string} [index='y'] - The `string` name of the property you want to sort on. + * @param {number} [order=Phaser.Group.SORT_ASCENDING] - The `Group` constant that defines the sort order. Possible values are Phaser.Group.SORT_ASCENDING and Phaser.Group.SORT_DESCENDING. + */ + sort: function (index, order) { - if (typeof index === 'undefined') { index = 'y'; } - if (typeof order === 'undefined') { order = Phaser.Group.SORT_ASCENDING; } + if (typeof index === 'undefined') { index = 'y'; } + if (typeof order === 'undefined') { order = Phaser.Group.SORT_ASCENDING; } - var swapped; - var temp; + var swapped; + var temp; - do { + do { - swapped = false; + swapped = false; - for (var i = 0, len = this._container.children.length - 1; i < len; i++) - { - if (order == Phaser.Group.SORT_ASCENDING) - { - if (this._container.children[i][index] > this._container.children[i + 1][index]) - { - this.swap(this.getAt(i), this.getAt(i + 1)); - temp = this._container.children[i]; - this._container.children[i] = this._container.children[i + 1]; - this._container.children[i + 1] = temp; - swapped = true; - } - } - else - { - if (this._container.children[i][index] < this._container.children[i + 1][index]) - { - this.swap(this.getAt(i), this.getAt(i + 1)); - temp = this._container.children[i]; - this._container.children[i] = this._container.children[i + 1]; - this._container.children[i + 1] = temp; - swapped = true; - } - } - } - } while (swapped); + for (var i = 0, len = this._container.children.length - 1; i < len; i++) + { + if (order == Phaser.Group.SORT_ASCENDING) + { + if (this._container.children[i][index] > this._container.children[i + 1][index]) + { + this.swap(this.getAt(i), this.getAt(i + 1)); + temp = this._container.children[i]; + this._container.children[i] = this._container.children[i + 1]; + this._container.children[i + 1] = temp; + swapped = true; + } + } + else + { + if (this._container.children[i][index] < this._container.children[i + 1][index]) + { + this.swap(this.getAt(i), this.getAt(i + 1)); + temp = this._container.children[i]; + this._container.children[i] = this._container.children[i + 1]; + this._container.children[i + 1] = temp; + swapped = true; + } + } + } + } while (swapped); - }, + }, - /** - * Iterates over the children of the Group. When a child has a property matching key that equals the given value, it is considered as a match. - * Matched children can be sent to the optional callback, or simply returned or counted. - * You can add as many callback parameters as you like, which will all be passed to the callback along with the child, after the callbackContext parameter. - * - * @method Phaser.Group#iterate - * @param {string} key - The child property to check, i.e. 'exists', 'alive', 'health' - * @param {any} value - If child.key === this value it will be considered a match. Note that a strict comparison is used. - * @param {number} returnType - How to return the data from this method. Either Phaser.Group.RETURN_NONE, Phaser.Group.RETURN_TOTAL or Phaser.Group.RETURN_CHILD. - * @param {function} [callback=null] - Optional function that will be called on each matching child. Each child of the Group will be passed to it as its first parameter. + /** + * Iterates over the children of the Group. When a child has a property matching key that equals the given value, it is considered as a match. + * Matched children can be sent to the optional callback, or simply returned or counted. + * You can add as many callback parameters as you like, which will all be passed to the callback along with the child, after the callbackContext parameter. + * + * @method Phaser.Group#iterate + * @param {string} key - The child property to check, i.e. 'exists', 'alive', 'health' + * @param {any} value - If child.key === this value it will be considered a match. Note that a strict comparison is used. + * @param {number} returnType - How to return the data from this method. Either Phaser.Group.RETURN_NONE, Phaser.Group.RETURN_TOTAL or Phaser.Group.RETURN_CHILD. + * @param {function} [callback=null] - Optional function that will be called on each matching child. Each child of the Group will be passed to it as its first parameter. * @param {Object} [callbackContext] - The context in which the function should be called (usually 'this'). - */ - iterate: function (key, value, returnType, callback, callbackContext, args) { + */ + iterate: function (key, value, returnType, callback, callbackContext, args) { - if (returnType == Phaser.Group.RETURN_TOTAL && this._container.children.length == 0) - { - return -1; - } + if (returnType == Phaser.Group.RETURN_TOTAL && this._container.children.length === 0) + { + return -1; + } - if (typeof callback === 'undefined') - { - callback = false; - } + if (typeof callback === 'undefined') + { + callback = false; + } - var total = 0; + var total = 0; - if (this._container.children.length > 0 && this._container.first._iNext) - { - var currentNode = this._container.first._iNext; - - do - { - if (currentNode[key] === value) - { - total++; + if (this._container.children.length > 0 && this._container.first._iNext) + { + var currentNode = this._container.first._iNext; + + do + { + if (currentNode[key] === value) + { + total++; - if (callback) - { - args[0] = currentNode; - callback.apply(callbackContext, args); - } + if (callback) + { + args[0] = currentNode; + callback.apply(callbackContext, args); + } - if (returnType == Phaser.Group.RETURN_CHILD) - { - return currentNode; - } - } + if (returnType == Phaser.Group.RETURN_CHILD) + { + return currentNode; + } + } - currentNode = currentNode._iNext; - } - while (currentNode != this._container.last._iNext); - } + currentNode = currentNode._iNext; + } + while (currentNode != this._container.last._iNext); + } - if (returnType == Phaser.Group.RETURN_TOTAL) - { - return total; - } - else if (returnType == Phaser.Group.RETURN_CHILD) - { - return null; - } + if (returnType == Phaser.Group.RETURN_TOTAL) + { + return total; + } + else if (returnType == Phaser.Group.RETURN_CHILD) + { + return null; + } - }, + }, - /** + /** * Call this function to retrieve the first object with exists == (the given state) in the Group. * * @method Phaser.Group#getFirstExists * @param {boolean} state - True or false. * @return {Any} The first child, or null if none found. */ - getFirstExists: function (state) { + getFirstExists: function (state) { - if (typeof state !== 'boolean') - { - state = true; - } + if (typeof state !== 'boolean') + { + state = true; + } - return this.iterate('exists', state, Phaser.Group.RETURN_CHILD); + return this.iterate('exists', state, Phaser.Group.RETURN_CHILD); - }, + }, - /** - * Call this function to retrieve the first object with alive == true in the group. + /** + * Call this function to retrieve the first object with alive === true in the group. * This is handy for checking if everything has been wiped out, or choosing a squad leader, etc. * * @method Phaser.Group#getFirstAlive * @return {Any} The first alive child, or null if none found. */ - getFirstAlive: function () { + getFirstAlive: function () { - return this.iterate('alive', true, Phaser.Group.RETURN_CHILD); + return this.iterate('alive', true, Phaser.Group.RETURN_CHILD); - }, + }, - /** - * Call this function to retrieve the first object with alive == false in the group. + /** + * Call this function to retrieve the first object with alive === false in the group. * This is handy for checking if everything has been wiped out, or choosing a squad leader, etc. * * @method Phaser.Group#getFirstDead * @return {Any} The first dead child, or null if none found. */ - getFirstDead: function () { + getFirstDead: function () { - return this.iterate('alive', false, Phaser.Group.RETURN_CHILD); + return this.iterate('alive', false, Phaser.Group.RETURN_CHILD); - }, + }, - /** + /** * Call this function to find out how many members of the group are alive. * * @method Phaser.Group#countLiving * @return {number} The number of children flagged as alive. Returns -1 if Group is empty. */ - countLiving: function () { + countLiving: function () { - return this.iterate('alive', true, Phaser.Group.RETURN_TOTAL); + return this.iterate('alive', true, Phaser.Group.RETURN_TOTAL); - }, + }, - /** + /** * Call this function to find out how many members of the group are dead. * * @method Phaser.Group#countDead * @return {number} The number of children flagged as dead. Returns -1 if Group is empty. */ - countDead: function () { + countDead: function () { - return this.iterate('alive', false, Phaser.Group.RETURN_TOTAL); + return this.iterate('alive', false, Phaser.Group.RETURN_TOTAL); - }, + }, - /** + /** * Returns a member at random from the group. * * @method Phaser.Group#getRandom @@ -1172,276 +1171,276 @@ Phaser.Group.prototype = { * @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) { + getRandom: function (startIndex, length) { - if (this._container.children.length == 0) - { - return null; - } + if (this._container.children.length === 0) + { + return null; + } - startIndex = startIndex || 0; - length = length || this._container.children.length; + startIndex = startIndex || 0; + length = length || this._container.children.length; return this.game.math.getRandom(this._container.children, startIndex, length); - }, + }, - /** - * Removes the given child from this Group and sets its group property to null. - * - * @method Phaser.Group#remove - * @param {Any} child - The child to remove. - */ - remove: function (child) { + /** + * Removes the given child from this Group and sets its group property to null. + * + * @method Phaser.Group#remove + * @param {Any} child - The child to remove. + */ + remove: function (child) { - if (child.events) - { - child.events.onRemovedFromGroup.dispatch(child, this); - } + if (child.events) + { + child.events.onRemovedFromGroup.dispatch(child, this); + } - this._container.removeChild(child); + this._container.removeChild(child); - if (this.cursor == child) - { - if (this._container._iNext) - { - this.cursor = this._container._iNext; - } - else - { - this.cursor = null; - } - } + if (this.cursor == child) + { + if (this._container._iNext) + { + this.cursor = this._container._iNext; + } + else + { + this.cursor = null; + } + } - child.group = null; + child.group = null; - }, + }, - /** - * Removes all children from this Group, setting all group properties to null. - * The Group container remains on the display list. - * - * @method Phaser.Group#removeAll - */ - removeAll: function () { + /** + * Removes all children from this Group, setting all group properties to null. + * The Group container remains on the display list. + * + * @method Phaser.Group#removeAll + */ + removeAll: function () { - if (this._container.children.length == 0) - { - return; - } + if (this._container.children.length === 0) + { + return; + } - do - { - if (this._container.children[0].events) - { - this._container.children[0].events.onRemovedFromGroup.dispatch(this._container.children[0], this); - } - this._container.removeChild(this._container.children[0]); - } - while (this._container.children.length > 0); + do + { + if (this._container.children[0].events) + { + this._container.children[0].events.onRemovedFromGroup.dispatch(this._container.children[0], this); + } + this._container.removeChild(this._container.children[0]); + } + while (this._container.children.length > 0); - this.cursor = null; + this.cursor = null; - }, + }, - /** - * Removes all children from this Group whos index falls beteen the given startIndex and endIndex values. - * - * @method Phaser.Group#removeBetween - * @param {number} startIndex - The index to start removing children from. - * @param {number} endIndex - The index to stop removing children from. Must be higher than startIndex and less than the length of the Group. - */ - removeBetween: function (startIndex, endIndex) { + /** + * Removes all children from this Group whos index falls beteen the given startIndex and endIndex values. + * + * @method Phaser.Group#removeBetween + * @param {number} startIndex - The index to start removing children from. + * @param {number} endIndex - The index to stop removing children from. Must be higher than startIndex and less than the length of the Group. + */ + removeBetween: function (startIndex, endIndex) { - if (this._container.children.length == 0) - { - return; - } + if (this._container.children.length === 0) + { + return; + } - if (startIndex > endIndex || startIndex < 0 || endIndex > this._container.children.length) - { - return false; - } + if (startIndex > endIndex || startIndex < 0 || endIndex > this._container.children.length) + { + return false; + } - for (var i = startIndex; i < endIndex; i++) - { - var child = this._container.children[i]; - child.events.onRemovedFromGroup.dispatch(child, this); - this._container.removeChild(child); - - if (this.cursor == child) - { - if (this._container._iNext) - { - this.cursor = this._container._iNext; - } - else - { - this.cursor = null; - } - } - } + for (var i = startIndex; i < endIndex; i++) + { + var child = this._container.children[i]; + child.events.onRemovedFromGroup.dispatch(child, this); + this._container.removeChild(child); + + if (this.cursor == child) + { + if (this._container._iNext) + { + this.cursor = this._container._iNext; + } + else + { + this.cursor = null; + } + } + } - }, + }, - /** - * Destroys this Group. Removes all children, then removes the container from the display list and nulls references. - * - * @method Phaser.Group#destroy - */ - destroy: function () { + /** + * Destroys this Group. Removes all children, then removes the container from the display list and nulls references. + * + * @method Phaser.Group#destroy + */ + destroy: function () { - this.removeAll(); + this.removeAll(); - this._container.parent.removeChild(this._container); + this._container.parent.removeChild(this._container); - this._container = null; + this._container = null; - this.game = null; + this.game = null; - this.exists = false; + this.exists = false; - this.cursor = null; + this.cursor = null; - }, + }, - validate: function () { + validate: function () { - var testObject = this.game.stage._stage.last._iNext; - var displayObject = this.game.stage._stage; - var nextObject = null; - var prevObject = null; - var count = 0; + var testObject = this.game.stage._stage.last._iNext; + var displayObject = this.game.stage._stage; + var nextObject = null; + var prevObject = null; + var count = 0; - do - { - if (count > 0) - { - // check next - if (displayObject !== nextObject) - { - console.log('check next fail'); - return false; - } + do + { + if (count > 0) + { + // check next + if (displayObject !== nextObject) + { + console.log('check next fail'); + return false; + } - // check previous - if (displayObject._iPrev !== prevObject) - { - console.log('check previous fail'); - return false; - } - } + // check previous + if (displayObject._iPrev !== prevObject) + { + console.log('check previous fail'); + return false; + } + } - // Set the next object - nextObject = displayObject._iNext; - prevObject = displayObject; + // Set the next object + nextObject = displayObject._iNext; + prevObject = displayObject; - displayObject = displayObject._iNext; + displayObject = displayObject._iNext; - count++; + count++; - } - while(displayObject != testObject) + } + while(displayObject != testObject) - return true; + return true; - }, + }, - /** - * Dumps out a list of Group children and their index positions to the browser console. Useful for group debugging. - * - * @method Phaser.Group#dump - * @param {boolean} [full=false] - If full the dump will include the entire display list, start from the Stage. Otherwise it will only include this container. - */ - dump: function (full) { + /** + * Dumps out a list of Group children and their index positions to the browser console. Useful for group debugging. + * + * @method Phaser.Group#dump + * @param {boolean} [full=false] - If full the dump will include the entire display list, start from the Stage. Otherwise it will only include this container. + */ + dump: function (full) { - if (typeof full == 'undefined') - { - full = false; - } + if (typeof full == 'undefined') + { + full = false; + } - var spacing = 20; - var output = "\n" + Phaser.Utils.pad('Node', spacing) + "|" + Phaser.Utils.pad('Next', spacing) + "|" + Phaser.Utils.pad('Previous', spacing) + "|" + Phaser.Utils.pad('First', spacing) + "|" + Phaser.Utils.pad('Last', spacing); + var spacing = 20; + var output = "\n" + Phaser.Utils.pad('Node', spacing) + "|" + Phaser.Utils.pad('Next', spacing) + "|" + Phaser.Utils.pad('Previous', spacing) + "|" + Phaser.Utils.pad('First', spacing) + "|" + Phaser.Utils.pad('Last', spacing); - console.log(output); + console.log(output); - var output = Phaser.Utils.pad('----------', spacing) + "|" + Phaser.Utils.pad('----------', spacing) + "|" + Phaser.Utils.pad('----------', spacing) + "|" + Phaser.Utils.pad('----------', spacing) + "|" + Phaser.Utils.pad('----------', spacing); - console.log(output); + var output = Phaser.Utils.pad('----------', spacing) + "|" + Phaser.Utils.pad('----------', spacing) + "|" + Phaser.Utils.pad('----------', spacing) + "|" + Phaser.Utils.pad('----------', spacing) + "|" + Phaser.Utils.pad('----------', spacing); + console.log(output); - if (full) - { - var testObject = this.game.stage._stage.last._iNext; - var displayObject = this.game.stage._stage; - } - else - { - var testObject = this._container.last._iNext; - var displayObject = this._container; - } - - do - { - var name = displayObject.name || '*'; + if (full) + { + var testObject = this.game.stage._stage.last._iNext; + var displayObject = this.game.stage._stage; + } + else + { + var testObject = this._container.last._iNext; + var displayObject = this._container; + } + + do + { + var name = displayObject.name || '*'; - if (this.cursor == displayObject) - { - var name = '> ' + name; - } + if (this.cursor == displayObject) + { + var name = '> ' + name; + } - var nameNext = '-'; - var namePrev = '-'; - var nameFirst = '-'; - var nameLast = '-'; + var nameNext = '-'; + var namePrev = '-'; + var nameFirst = '-'; + var nameLast = '-'; - if (displayObject._iNext) - { - nameNext = displayObject._iNext.name; - } + if (displayObject._iNext) + { + nameNext = displayObject._iNext.name; + } - if (displayObject._iPrev) - { - namePrev = displayObject._iPrev.name; - } + if (displayObject._iPrev) + { + namePrev = displayObject._iPrev.name; + } - if (displayObject.first) - { - nameFirst = displayObject.first.name; - } + if (displayObject.first) + { + nameFirst = displayObject.first.name; + } - if (displayObject.last) - { - nameLast = displayObject.last.name; - } + if (displayObject.last) + { + nameLast = displayObject.last.name; + } - if (typeof nameNext === 'undefined') - { - nameNext = '-'; - } + if (typeof nameNext === 'undefined') + { + nameNext = '-'; + } - if (typeof namePrev === 'undefined') - { - namePrev = '-'; - } + if (typeof namePrev === 'undefined') + { + namePrev = '-'; + } - if (typeof nameFirst === 'undefined') - { - nameFirst = '-'; - } + if (typeof nameFirst === 'undefined') + { + nameFirst = '-'; + } - if (typeof nameLast === 'undefined') - { - nameLast = '-'; - } + if (typeof nameLast === 'undefined') + { + nameLast = '-'; + } - var output = Phaser.Utils.pad(name, spacing) + "|" + Phaser.Utils.pad(nameNext, spacing) + "|" + Phaser.Utils.pad(namePrev, spacing) + "|" + Phaser.Utils.pad(nameFirst, spacing) + "|" + Phaser.Utils.pad(nameLast, spacing); - console.log(output); + var output = Phaser.Utils.pad(name, spacing) + "|" + Phaser.Utils.pad(nameNext, spacing) + "|" + Phaser.Utils.pad(namePrev, spacing) + "|" + Phaser.Utils.pad(nameFirst, spacing) + "|" + Phaser.Utils.pad(nameLast, spacing); + console.log(output); - displayObject = displayObject._iNext; + displayObject = displayObject._iNext; - } - while(displayObject != testObject) + } + while(displayObject != testObject) - } + } }; @@ -1453,7 +1452,7 @@ Phaser.Group.prototype = { Object.defineProperty(Phaser.Group.prototype, "total", { get: function () { - return this.iterate('exists', true, Phaser.Group.RETURN_TOTAL); + return this.iterate('exists', true, Phaser.Group.RETURN_TOTAL); // return this._container.children.length; } @@ -1467,7 +1466,7 @@ Object.defineProperty(Phaser.Group.prototype, "total", { Object.defineProperty(Phaser.Group.prototype, "length", { get: function () { - return this.iterate('exists', true, Phaser.Group.RETURN_TOTAL); + return this.iterate('exists', true, Phaser.Group.RETURN_TOTAL); // return this._container.children.length; } diff --git a/src/core/LinkedList.js b/src/core/LinkedList.js index 4e3abeb0..42358592 100644 --- a/src/core/LinkedList.js +++ b/src/core/LinkedList.js @@ -13,141 +13,141 @@ Phaser.LinkedList = function () { /** - * @property {object} next - Next element in the list. - * @default - */ + * @property {object} next - Next element in the list. + * @default + */ this.next = null; /** - * @property {object} prev - Previous element in the list. - * @default - */ + * @property {object} prev - Previous element in the list. + * @default + */ this.prev = null; /** - * @property {object} first - First element in the list. - * @default - */ + * @property {object} first - First element in the list. + * @default + */ this.first = null; /** - * @property {object} last - Last element in the list. - * @default - */ + * @property {object} last - Last element in the list. + * @default + */ this.last = null; /** - * @property {object} game - Number of elements in the list. - * @default - */ + * @property {object} game - Number of elements in the list. + * @default + */ this.total = 0; }; Phaser.LinkedList.prototype = { - /** + /** * Adds a new element to this linked list. - * - * @method Phaser.LinkedList#add - * @param {object} child - The element to add to this list. Can be a Phaser.Sprite or any other object you need to quickly iterate through. - * @return {object} The child that was added. + * + * @method Phaser.LinkedList#add + * @param {object} child - The element to add to this list. Can be a Phaser.Sprite or any other object you need to quickly iterate through. + * @return {object} The child that was added. */ add: function (child) { - // If the list is empty - if (this.total == 0 && this.first == null && this.last == null) - { - this.first = child; - this.last = child; - this.next = child; - child.prev = this; - this.total++; - return child; - } + // If the list is empty + if (this.total === 0 && this.first == null && this.last == null) + { + this.first = child; + this.last = child; + this.next = child; + child.prev = this; + this.total++; + return child; + } - // Get gets appended to the end of the list, regardless of anything, and it won't have any children of its own (non-nested list) - this.last.next = child; + // Get gets appended to the end of the list, regardless of anything, and it won't have any children of its own (non-nested list) + this.last.next = child; - child.prev = this.last; + child.prev = this.last; - this.last = child; + this.last = child; - this.total++; + this.total++; - return child; + return child; }, - /** + /** * Removes the given element from this linked list if it exists. - * - * @method Phaser.LinkedList#remove - * @param {object} child - The child to be removed from the list. + * + * @method Phaser.LinkedList#remove + * @param {object} child - The child to be removed from the list. */ remove: function (child) { - if (child == this.first) - { - // It was 'first', make 'first' point to first.next - this.first = this.first.next; - } - else if (child == this.last) - { - // It was 'last', make 'last' point to last.prev - this.last = this.last.prev; - } + if (child == this.first) + { + // It was 'first', make 'first' point to first.next + this.first = this.first.next; + } + else if (child == this.last) + { + // It was 'last', make 'last' point to last.prev + this.last = this.last.prev; + } - if (child.prev) - { - // make child.prev.next point to childs.next instead of child - child.prev.next = child.next; - } + if (child.prev) + { + // make child.prev.next point to childs.next instead of child + child.prev.next = child.next; + } - if (child.next) - { - // make child.next.prev point to child.prev instead of child - child.next.prev = child.prev; - } + if (child.next) + { + // make child.next.prev point to child.prev instead of child + child.next.prev = child.prev; + } - child.next = child.prev = null; + child.next = child.prev = null; - if (this.first == null ) - { - this.last = null; - } + if (this.first == null ) + { + this.last = null; + } - this.total--; + this.total--; }, - /** + /** * Calls a function on all members of this list, using the member as the context for the callback. * The function must exist on the member. - * - * @method Phaser.LinkedList#callAll - * @param {function} callback - The function to call. + * + * @method Phaser.LinkedList#callAll + * @param {function} callback - The function to call. */ callAll: function (callback) { - if (!this.first || !this.last) - { - return; - } + if (!this.first || !this.last) + { + return; + } - var entity = this.first; - - do - { - if (entity && entity[callback]) - { - entity[callback].call(entity); - } + var entity = this.first; + + do + { + if (entity && entity[callback]) + { + entity[callback].call(entity); + } - entity = entity.next; + entity = entity.next; - } - while(entity != this.last.next) + } + while(entity != this.last.next) } diff --git a/src/core/Plugin.js b/src/core/Plugin.js index 68a03029..c54933fb 100644 --- a/src/core/Plugin.js +++ b/src/core/Plugin.js @@ -17,38 +17,38 @@ Phaser.Plugin = function (game, parent) { if (typeof parent === 'undefined') { parent = null; } - /** - * @property {Phaser.Game} game - A reference to the currently running game. - */ + /** + * @property {Phaser.Game} game - A reference to the currently running game. + */ this.game = game; /** - * @property {Any} parent - The parent of this plugin. If added to the PluginManager the parent will be set to that, otherwise it will be null. - */ + * @property {Any} parent - The parent of this plugin. If added to the PluginManager the parent will be set to that, otherwise it will be null. + */ this.parent = parent; /** - * @property {boolean} active - A Plugin with active=true has its preUpdate and update methods called by the parent, otherwise they are skipped. - * @default - */ + * @property {boolean} active - A Plugin with active=true has its preUpdate and update methods called by the parent, otherwise they are skipped. + * @default + */ this.active = false; /** - * @property {boolean} visible - A Plugin with visible=true has its render and postRender methods called by the parent, otherwise they are skipped. - * @default - */ + * @property {boolean} visible - A Plugin with visible=true has its render and postRender methods called by the parent, otherwise they are skipped. + * @default + */ this.visible = false; /** - * @property {boolean} hasPreUpdate - A flag to indicate if this plugin has a preUpdate method. - * @default - */ + * @property {boolean} hasPreUpdate - A flag to indicate if this plugin has a preUpdate method. + * @default + */ this.hasPreUpdate = false; /** - * @property {boolean} hasUpdate - A flag to indicate if this plugin has an update method. - * @default - */ + * @property {boolean} hasUpdate - A flag to indicate if this plugin has an update method. + * @default + */ this.hasUpdate = false; /** @@ -58,15 +58,15 @@ Phaser.Plugin = function (game, parent) { this.hasPostUpdate = false; /** - * @property {boolean} hasRender - A flag to indicate if this plugin has a render method. - * @default - */ + * @property {boolean} hasRender - A flag to indicate if this plugin has a render method. + * @default + */ this.hasRender = false; /** - * @property {boolean} hasPostRender - A flag to indicate if this plugin has a postRender method. - * @default - */ + * @property {boolean} hasPostRender - A flag to indicate if this plugin has a postRender method. + * @default + */ this.hasPostRender = false; }; diff --git a/src/core/PluginManager.js b/src/core/PluginManager.js index 0323b21a..5838e94c 100644 --- a/src/core/PluginManager.js +++ b/src/core/PluginManager.js @@ -1,3 +1,5 @@ +/* jshint newcap: false */ + /** * @author Richard Davey * @copyright 2013 Photon Storm Ltd. @@ -5,7 +7,7 @@ */ /** -* Description. +* The Plugin Manager is responsible for the loading, running and unloading of Phaser Plugins. * * @class Phaser.PluginManager * @classdesc Phaser - PluginManager @@ -15,27 +17,27 @@ */ Phaser.PluginManager = function(game, parent) { - /** - * @property {Phaser.Game} game - A reference to the currently running game. - */ + /** + * @property {Phaser.Game} game - A reference to the currently running game. + */ this.game = game; /** - * @property {Description} _parent - Description. - * @private - */ + * @property {Description} _parent - Description. + * @private + */ this._parent = parent; /** - * @property {array} plugins - Description. - */ + * @property {array} plugins - Description. + */ this.plugins = []; /** - * @property {array} _pluginsLength - Description. - * @private - * @default - */ + * @property {array} _pluginsLength - Description. + * @private + * @default + */ this._pluginsLength = 0; }; @@ -131,7 +133,7 @@ Phaser.PluginManager.prototype = { */ remove: function (plugin) { - if (this._pluginsLength == 0) + if (this._pluginsLength === 0) { return; } @@ -170,7 +172,7 @@ Phaser.PluginManager.prototype = { */ preUpdate: function () { - if (this._pluginsLength == 0) + if (this._pluginsLength === 0) { return; } @@ -193,7 +195,7 @@ Phaser.PluginManager.prototype = { */ update: function () { - if (this._pluginsLength == 0) + if (this._pluginsLength === 0) { return; } @@ -217,7 +219,7 @@ Phaser.PluginManager.prototype = { */ postUpdate: function () { - if (this._pluginsLength == 0) + if (this._pluginsLength === 0) { return; } @@ -240,7 +242,7 @@ Phaser.PluginManager.prototype = { */ render: function () { - if (this._pluginsLength == 0) + if (this._pluginsLength === 0) { return; } @@ -263,7 +265,7 @@ Phaser.PluginManager.prototype = { */ postRender: function () { - if (this._pluginsLength == 0) + if (this._pluginsLength === 0) { return; } diff --git a/src/core/Signal.js b/src/core/Signal.js index 08aa10f6..05b18376 100644 --- a/src/core/Signal.js +++ b/src/core/Signal.js @@ -12,286 +12,291 @@ */ Phaser.Signal = function () { - /** - * @property {Array.} _bindings - Description. - * @private - */ - this._bindings = []; - - /** - * @property {Description} _prevParams - Description. - * @private - */ - this._prevParams = null; + /** + * @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; + // enforce dispatch to aways work on same context (#47) + var self = this; - /** - * @property {Description} dispatch - Description. - */ - this.dispatch = function(){ - Phaser.Signal.prototype.dispatch.apply(self, arguments); - }; + /** + * @property {Description} dispatch - Description. + */ + this.dispatch = function(){ + Phaser.Signal.prototype.dispatch.apply(self, arguments); + }; }; Phaser.Signal.prototype = { - /** + /** * If Signal should keep record of previously dispatched parameters and - * automatically execute listener during `add()`/`addOnce()` if Signal was - * already dispatched before. - * @property {boolean} memorize - */ - memorize: false, + * automatically execute listener during `add()`/`addOnce()` if Signal was + * already dispatched before. + * @property {boolean} memorize + */ + memorize: false, - /** - * @property {boolean} _shouldPropagate - * @private - */ - _shouldPropagate: true, + /** + * @property {boolean} _shouldPropagate + * @private + */ + _shouldPropagate: true, - /** - * If Signal is active and should broadcast events. - *

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 {boolean} active + /** + * 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 {boolean} active * @default */ - active: true, + active: true, - /** - * @method Phaser.Signal#validateListener - * @param {function} listener - Signal handler function. - * @param {Description} fnName - Description. - * @private + /** + * @method Phaser.Signal#validateListener + * @param {function} listener - Signal handler function. + * @param {Description} fnName - Description. + * @private */ - validateListener: function (listener, fnName) { - if (typeof listener !== 'function') { - throw new Error( 'listener is a required param of {fn}() and should be a Function.'.replace('{fn}', fnName) ); - } - }, + validateListener: function (listener, fnName) { + if (typeof listener !== 'function') { + throw new Error( 'listener is a required param of {fn}() and should be a Function.'.replace('{fn}', fnName) ); + } + }, - /** - * @method Phaser.Signal#_registerListener - * @param {function} listener - Signal handler function. - * @param {boolean} isOnce - Description. - * @param {object} [listenerContext] - Description. - * @param {number} [priority] - The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0). - * @return {Phaser.SignalBinding} An Object representing the binding between the Signal and listener. - * @private - */ - _registerListener: function (listener, isOnce, listenerContext, priority) { + /** + * @method Phaser.Signal#_registerListener + * @param {function} listener - Signal handler function. + * @param {boolean} isOnce - Description. + * @param {object} [listenerContext] - Description. + * @param {number} [priority] - The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0). + * @return {Phaser.SignalBinding} An Object representing the binding between the Signal and listener. + * @private + */ + _registerListener: function (listener, isOnce, listenerContext, priority) { - var prevIndex = this._indexOfListener(listener, listenerContext), - binding; + var prevIndex = this._indexOfListener(listener, listenerContext), + binding; - if (prevIndex !== -1) { - binding = this._bindings[prevIndex]; - if (binding.isOnce() !== isOnce) { - throw new Error('You cannot add'+ (isOnce? '' : 'Once') +'() then add'+ (!isOnce? '' : 'Once') +'() the same listener without removing the relationship first.'); - } - } else { - binding = new Phaser.SignalBinding(this, listener, isOnce, listenerContext, priority); - this._addBinding(binding); - } + if (prevIndex !== -1) { + binding = this._bindings[prevIndex]; + if (binding.isOnce() !== isOnce) { + throw new Error('You cannot add'+ (isOnce? '' : 'Once') +'() then add'+ (!isOnce? '' : 'Once') +'() the same listener without removing the relationship first.'); + } + } else { + binding = new Phaser.SignalBinding(this, listener, isOnce, listenerContext, priority); + this._addBinding(binding); + } - if (this.memorize && this._prevParams){ - binding.execute(this._prevParams); - } + if (this.memorize && this._prevParams){ + binding.execute(this._prevParams); + } - return binding; - }, + return binding; + }, - /** - * @method Phaser.Signal#_addBinding - * @param {Phaser.SignalBinding} binding - An Object representing the binding between the Signal and listener. - * @private - */ - _addBinding: function (binding) { - //simplified insertion sort - var n = this._bindings.length; - do { --n; } while (this._bindings[n] && binding._priority <= this._bindings[n]._priority); - this._bindings.splice(n + 1, 0, binding); - }, + /** + * @method Phaser.Signal#_addBinding + * @param {Phaser.SignalBinding} binding - An Object representing the binding between the Signal and listener. + * @private + */ + _addBinding: function (binding) { + //simplified insertion sort + var n = this._bindings.length; + do { --n; } while (this._bindings[n] && binding._priority <= this._bindings[n]._priority); + this._bindings.splice(n + 1, 0, binding); + }, - /** - * @method Phaser.Signal#_indexOfListener - * @param {function} listener - Signal handler function. - * @return {number} Description. - * @private - */ - _indexOfListener: function (listener, context) { - var n = this._bindings.length, - cur; - while (n--) { - cur = this._bindings[n]; - if (cur._listener === listener && cur.context === context) { - return n; - } - } - return -1; - }, + /** + * @method Phaser.Signal#_indexOfListener + * @param {function} listener - Signal handler function. + * @return {number} Description. + * @private + */ + _indexOfListener: function (listener, context) { + var n = this._bindings.length, + cur; + while (n--) { + cur = this._bindings[n]; + if (cur._listener === listener && cur.context === context) { + return n; + } + } + return -1; + }, - /** - * Check if listener was attached to Signal. - * - * @method Phaser.Signal#has - * @param {Function} listener - Signal handler function. - * @param {Object} [context] - Context on which listener will be executed (object that should represent the `this` variable inside listener function). - * @return {boolean} If Signal has the specified listener. - */ - has: function (listener, context) { - return this._indexOfListener(listener, context) !== -1; - }, + /** + * Check if listener was attached to Signal. + * + * @method Phaser.Signal#has + * @param {Function} listener - Signal handler function. + * @param {Object} [context] - Context on which listener will be executed (object that should represent the `this` variable inside listener function). + * @return {boolean} If Signal has the specified listener. + */ + has: function (listener, context) { + return this._indexOfListener(listener, context) !== -1; + }, - /** - * Add a listener to the signal. - * - * @method Phaser.Signal#add - * @param {function} listener - Signal handler function. - * @param {object} [listenerContext] Context on which listener will be executed (object that should represent the `this` variable inside listener function). - * @param {number} [priority] The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0). - * @return {Phaser.SignalBinding} An Object representing the binding between the Signal and listener. - */ - add: function (listener, listenerContext, priority) { - this.validateListener(listener, 'add'); - return this._registerListener(listener, false, listenerContext, priority); - }, + /** + * Add a listener to the signal. + * + * @method Phaser.Signal#add + * @param {function} listener - Signal handler function. + * @param {object} [listenerContext] Context on which listener will be executed (object that should represent the `this` variable inside listener function). + * @param {number} [priority] The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0). + * @return {Phaser.SignalBinding} An Object representing the binding between the Signal and listener. + */ + add: function (listener, listenerContext, priority) { + this.validateListener(listener, 'add'); + return this._registerListener(listener, false, listenerContext, priority); + }, - /** - * Add listener to the signal that should be removed after first execution (will be executed only once). - * - * @method Phaser.Signal#addOnce - * @param {function} listener Signal handler function. - * @param {object} [listenerContext] Context on which listener will be executed (object that should represent the `this` variable inside listener function). - * @param {number} [priority] The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0) - * @return {Phaser.SignalBinding} An Object representing the binding between the Signal and listener. - */ - addOnce: function (listener, listenerContext, priority) { - this.validateListener(listener, 'addOnce'); - return this._registerListener(listener, true, listenerContext, priority); - }, + /** + * Add listener to the signal that should be removed after first execution (will be executed only once). + * + * @method Phaser.Signal#addOnce + * @param {function} listener Signal handler function. + * @param {object} [listenerContext] Context on which listener will be executed (object that should represent the `this` variable inside listener function). + * @param {number} [priority] The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0) + * @return {Phaser.SignalBinding} An Object representing the binding between the Signal and listener. + */ + addOnce: function (listener, listenerContext, priority) { + this.validateListener(listener, 'addOnce'); + return this._registerListener(listener, true, listenerContext, priority); + }, - /** - * Remove a single listener from the dispatch queue. - * - * @method Phaser.Signal#remove - * @param {function} listener Handler function that should be removed. - * @param {object} [context] Execution context (since you can add the same handler multiple times if executing in a different context). - * @return {function} Listener handler function. - */ - remove: function (listener, context) { + /** + * Remove a single listener from the dispatch queue. + * + * @method Phaser.Signal#remove + * @param {function} listener Handler function that should be removed. + * @param {object} [context] Execution context (since you can add the same handler multiple times if executing in a different context). + * @return {function} Listener handler function. + */ + remove: function (listener, context) { - this.validateListener(listener, 'remove'); + this.validateListener(listener, 'remove'); - var i = this._indexOfListener(listener, context); + var i = this._indexOfListener(listener, context); - if (i !== -1) - { - this._bindings[i]._destroy(); //no reason to a Phaser.SignalBinding exist if it isn't attached to a signal - this._bindings.splice(i, 1); - } + if (i !== -1) + { + this._bindings[i]._destroy(); //no reason to a Phaser.SignalBinding exist if it isn't attached to a signal + this._bindings.splice(i, 1); + } - return listener; + return listener; - }, + }, - /** - * Remove all listeners from the Signal. - * - * @method Phaser.Signal#removeAll - */ - removeAll: function () { - var n = this._bindings.length; - while (n--) { - this._bindings[n]._destroy(); - } - this._bindings.length = 0; - }, + /** + * Remove all listeners from the Signal. + * + * @method Phaser.Signal#removeAll + */ + removeAll: function () { + var n = this._bindings.length; + while (n--) { + this._bindings[n]._destroy(); + } + this._bindings.length = 0; + }, - /** - * Gets the total number of listeneres attached to ths Signal. - * - * @method Phaser.Signal#getNumListeners - * @return {number} Number of listeners attached to the Signal. - */ - getNumListeners: function () { - return this._bindings.length; - }, + /** + * Gets the total number of listeneres attached to ths Signal. + * + * @method Phaser.Signal#getNumListeners + * @return {number} Number of listeners attached to the Signal. + */ + getNumListeners: function () { + return this._bindings.length; + }, - /** - * Stop propagation of the event, blocking the dispatch to next listeners on the queue. - *

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

- * @see Signal.prototype.disable - * - * @method Phaser.Signal#halt - */ - halt: function () { - this._shouldPropagate = false; - }, + /** + * Stop propagation of the event, blocking the dispatch to next listeners on the queue. + *

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

+ * @see Signal.prototype.disable + * + * @method Phaser.Signal#halt + */ + halt: function () { + this._shouldPropagate = false; + }, - /** - * Dispatch/Broadcast Signal to all listeners added to the queue. - * - * @method Phaser.Signal#dispatch - * @param {any} [params] - Parameters that should be passed to each handler. - */ - dispatch: function (params) { - if (! this.active) { - return; - } + /** + * Dispatch/Broadcast Signal to all listeners added to the queue. + * + * @method Phaser.Signal#dispatch + * @param {...} [params] - Parameters that should be passed to each handler. + */ + dispatch: function () { - var paramsArr = Array.prototype.slice.call(arguments), - n = this._bindings.length, - bindings; + if (!this.active) + { + return; + } - if (this.memorize) { - this._prevParams = paramsArr; - } + var paramsArr = Array.prototype.slice.call(arguments); + var n = this._bindings.length; + var bindings; - if (! n) { - //should come after memorize - return; - } + if (this.memorize) + { + this._prevParams = paramsArr; + } - bindings = this._bindings.slice(); //clone array in case add/remove items during dispatch - this._shouldPropagate = true; //in case `halt` was called before dispatch or during the previous dispatch. + if (!n) + { + // Should come after memorize + return; + } - //execute all callbacks until end of the list or until a callback returns `false` or stops propagation - //reverse loop since listeners with higher priority will be added at the end of the list - do { n--; } while (bindings[n] && this._shouldPropagate && bindings[n].execute(paramsArr) !== false); - }, + bindings = this._bindings.slice(); //clone array in case add/remove items during dispatch + this._shouldPropagate = true; //in case `halt` was called before dispatch or during the previous dispatch. - /** - * Forget memorized arguments. - * @see Signal.memorize - * - * @method Phaser.Signal#forget - */ - forget: function(){ - this._prevParams = null; - }, + //execute all callbacks until end of the list or until a callback returns `false` or stops propagation + //reverse loop since listeners with higher priority will be added at the end of the list + do { n--; } while (bindings[n] && this._shouldPropagate && bindings[n].execute(paramsArr) !== false); + + }, - /** - * Remove all bindings from signal and destroy any reference to external objects (destroy Signal object). - *

IMPORTANT: calling any method on the signal instance after calling dispose will throw errors.

- * - * @method Phaser.Signal#dispose - */ - dispose: function () { - this.removeAll(); - delete this._bindings; - delete this._prevParams; - }, + /** + * Forget memorized arguments. + * @see Signal.memorize + * + * @method Phaser.Signal#forget + */ + forget: function(){ + this._prevParams = null; + }, - /** - * - * @method Phaser.Signal#toString - * @return {string} String representation of the object. - */ - toString: function () { - return '[Phaser.Signal active:'+ this.active +' numListeners:'+ this.getNumListeners() +']'; - } + /** + * Remove all bindings from signal and destroy any reference to external objects (destroy Signal object). + *

IMPORTANT: calling any method on the signal instance after calling dispose will throw errors.

+ * + * @method Phaser.Signal#dispose + */ + dispose: function () { + this.removeAll(); + delete this._bindings; + delete this._prevParams; + }, + + /** + * + * @method Phaser.Signal#toString + * @return {string} String representation of the object. + */ + toString: function () { + return '[Phaser.Signal active:'+ this.active +' numListeners:'+ this.getNumListeners() +']'; + } }; diff --git a/src/core/SignalBinding.js b/src/core/SignalBinding.js index 58d9903b..d5c47acd 100644 --- a/src/core/SignalBinding.js +++ b/src/core/SignalBinding.js @@ -25,33 +25,33 @@ Phaser.SignalBinding = function (signal, listener, isOnce, listenerContext, priority) { /** - * @property {Phaser.Game} _listener - Handler function bound to the signal. - * @private - */ + * @property {Phaser.Game} _listener - Handler function bound to the signal. + * @private + */ this._listener = listener; /** - * @property {boolean} _isOnce - If binding should be executed just once. - * @private - */ + * @property {boolean} _isOnce - If binding should be executed just once. + * @private + */ this._isOnce = isOnce; /** - * @property {object|undefined|null} context - Context on which listener will be executed (object that should represent the `this` variable inside listener function). - * @memberof SignalBinding.prototype - */ + * @property {object|undefined|null} context - Context on which listener will be executed (object that should represent the `this` variable inside listener function). + * @memberof SignalBinding.prototype + */ this.context = listenerContext; /** - * @property {Signal} _signal - Reference to Signal object that listener is currently bound to. - * @private - */ + * @property {Signal} _signal - Reference to Signal object that listener is currently bound to. + * @private + */ this._signal = signal; /** - * @property {number} _priority - Listener priority. - * @private - */ + * @property {number} _priority - Listener priority. + * @private + */ this._priority = priority || 0; }; @@ -62,7 +62,7 @@ Phaser.SignalBinding.prototype = { * If binding is active and should be executed. * @property {boolean} active * @default - */ + */ active: true, /** diff --git a/src/core/Stage.js b/src/core/Stage.js index c19b69c0..fdd20717 100644 --- a/src/core/Stage.js +++ b/src/core/Stage.js @@ -17,26 +17,26 @@ Phaser.Stage = function (game, width, height) { /** - * @property {Phaser.Game} game - A reference to the currently running Game. - */ - this.game = game; + * @property {Phaser.Game} game - A reference to the currently running Game. + */ + this.game = game; /** - * @property {string} game - Background color of the stage (defaults to black). Set via the public backgroundColor property. - * @private - * @default 'rgb(0,0,0)' - */ + * @property {string} game - Background color of the stage (defaults to black). Set via the public backgroundColor property. + * @private + * @default 'rgb(0,0,0)' + */ this._backgroundColor = 'rgb(0,0,0)'; /** - * @property {Phaser.Point} offset - Get the offset values (for input and other things). - */ - this.offset = new Phaser.Point; + * @property {Phaser.Point} offset - Get the offset values (for input and other things). + */ + this.offset = new Phaser.Point(); /** * @property {HTMLCanvasElement} canvas - Reference to the newly created <canvas> element. */ - this.canvas = Phaser.Canvas.create(width, height); + this.canvas = Phaser.Canvas.create(width, height); this.canvas.style['-webkit-full-screen'] = 'width: 100%; height: 100%'; /** @@ -49,7 +49,7 @@ Phaser.Stage = function (game, width, height) { /** * @property {number} scaleMode - The current scaleMode. - */ + */ this.scaleMode = Phaser.StageScaleMode.NO_SCALE; /** @@ -126,7 +126,7 @@ Phaser.Stage.prototype = { }, - /** + /** * This method is called when the document visibility is changed. * @method Phaser.Stage#visibilityChange * @param {Event} event - Its type will be used to decide whether the game should be paused or not. @@ -138,16 +138,16 @@ Phaser.Stage.prototype = { return; } - if (event.type == 'pagehide' || event.type == 'blur' || document['hidden'] == true || document['webkitHidden'] == true) + if (event.type == 'pagehide' || event.type == 'blur' || document['hidden'] === true || document['webkitHidden'] === true) { - this.game.paused = true; + this.game.paused = true; } else { - this.game.paused = false; + this.game.paused = false; } - }, + } }; diff --git a/src/core/State.js b/src/core/State.js index a853b945..38a99f21 100644 --- a/src/core/State.js +++ b/src/core/State.js @@ -15,86 +15,86 @@ Phaser.State = function () { /** - * @property {Phaser.Game} game - A reference to the currently running Game. - */ + * @property {Phaser.Game} game - A reference to the currently running Game. + */ this.game = null; - /** - * @property {Phaser.GameObjectFactory} add - Reference to the GameObjectFactory. - * @default - */ + /** + * @property {Phaser.GameObjectFactory} add - Reference to the GameObjectFactory. + * @default + */ this.add = null; /** - * @property {Phaser.Physics.PhysicsManager} camera - A handy reference to world.camera. - * @default - */ + * @property {Phaser.Camera} camera - A handy reference to world.camera. + * @default + */ this.camera = null; /** - * @property {Phaser.Cache} cache - Reference to the assets cache. - * @default - */ + * @property {Phaser.Cache} cache - Reference to the assets cache. + * @default + */ this.cache = null; /** - * @property {Phaser.Input} input - Reference to the input manager - * @default - */ + * @property {Phaser.Input} input - Reference to the input manager + * @default + */ this.input = null; /** - * @property {Phaser.Loader} load - Reference to the assets loader. - * @default - */ + * @property {Phaser.Loader} load - Reference to the assets loader. + * @default + */ this.load = null; /** - * @property {Phaser.Math} math - Reference to the math helper. - * @default - */ + * @property {Phaser.Math} math - Reference to the math helper. + * @default + */ this.math = null; /** - * @property {Phaser.SoundManager} sound - Reference to the sound manager. - * @default - */ + * @property {Phaser.SoundManager} sound - Reference to the sound manager. + * @default + */ this.sound = null; /** - * @property {Phaser.Stage} stage - Reference to the stage. - * @default - */ + * @property {Phaser.Stage} stage - Reference to the stage. + * @default + */ this.stage = null; /** - * @property {Phaser.TimeManager} time - Reference to game clock. - * @default - */ + * @property {Phaser.TimeManager} time - Reference to game clock. + * @default + */ this.time = null; /** - * @property {Phaser.TweenManager} tweens - Reference to the tween manager. - * @default - */ + * @property {Phaser.TweenManager} tweens - Reference to the tween manager. + * @default + */ this.tweens = null; /** - * @property {Phaser.World} world - Reference to the world. - * @default - */ + * @property {Phaser.World} world - Reference to the world. + * @default + */ this.world = null; - /** - * @property {Description} add - Description. - * @default - */ + /** + * @property {Phaser.Particles} particles - The Particle Manager for the game. It is called during the game update loop and in turn updates any Emitters attached to it. + * @default + */ this.particles = null; /** - * @property {Phaser.Physics.PhysicsManager} physics - Reference to the physics manager. - * @default - */ + * @property {Phaser.Physics.PhysicsManager} physics - Reference to the physics manager. + * @default + */ this.physics = null; }; diff --git a/src/core/StateManager.js b/src/core/StateManager.js index bb0058a9..65d08460 100644 --- a/src/core/StateManager.js +++ b/src/core/StateManager.js @@ -1,3 +1,5 @@ +/* jshint newcap: false */ + /** * @author Richard Davey * @copyright 2013 Photon Storm Ltd. @@ -14,148 +16,117 @@ */ Phaser.StateManager = function (game, pendingState) { - /** - * A reference to the currently running game. - * @property {Phaser.Game} game. - */ - this.game = game; + /** + * @property {Phaser.Game} game - A reference to the currently running game. + */ + this.game = game; - /** - * Description. - * @property {Description} states. - */ - this.states = {}; + /** + * @property {Object} states - The object containing Phaser.States. + */ + this.states = {}; + + /** + * @property {Phaser.State} _pendingState - The state to be switched to in the next frame. + * @private + */ + this._pendingState = null; + + if (pendingState !== null) + { + this._pendingState = pendingState; + } + + /** + * @property {boolean} _created - Flag that sets if the State has been created or not. + * @private + */ + this._created = false; + + /** + * @property {string} current - The current active State object (defaults to null). + */ + this.current = ''; + + /** + * @property {function} onInitCallback - This will be called when the state is started (i.e. set as the current active state). + */ + this.onInitCallback = null; + + /** + * @property {function} onPreloadCallback - This will be called when init states (loading assets...). + */ + this.onPreloadCallback = null; + + /** + * @property {function} onCreateCallback - This will be called when create states (setup states...). + */ + this.onCreateCallback = null; + + /** + * @property {function} onUpdateCallback - This will be called when State is updated, this doesn't happen during load (@see onLoadUpdateCallback). + */ + this.onUpdateCallback = null; + + /** + * @property {function} onRenderCallback - This will be called when the State is rendered, this doesn't happen during load (see onLoadRenderCallback). + */ + this.onRenderCallback = null; + + /** + * @property {function} onPreRenderCallback - This will be called before the State is rendered and before the stage is cleared. + */ + this.onPreRenderCallback = null; + + /** + * @property {function} onLoadUpdateCallback - This will be called when the State is updated but only during the load process. + */ + this.onLoadUpdateCallback = null; + + /** + * @property {function} onLoadRenderCallback - This will be called when the State is rendered but only during the load process. + */ + this.onLoadRenderCallback = null; + + /** + * @property {function} onPausedCallback - This will be called when the state is paused. + */ + this.onPausedCallback = null; + + /** + * @property {function} onShutDownCallback - This will be called when the state is shut down (i.e. swapped to another state). + */ + this.onShutDownCallback = null; - if (pendingState !== null) - { - this._pendingState = pendingState; - } }; Phaser.StateManager.prototype = { - - /** - * A reference to the currently running game. - * @property {Phaser.Game} game. - */ - game: null, - /** - * The state to be switched to in the next frame. - * @property {State} _pendingState - * @private - */ - _pendingState: null, + /** + * The Boot handler is called by Phaser.Game when it first starts up. + * @method Phaser.StateManager#boot + * @private + */ + boot: function () { - /** - * Flag that sets if the State has been created or not. - * @property {boolean}_created - * @private - */ - _created: false, + if (this._pendingState !== null) + { + if (typeof this._pendingState === 'string') + { + // State was already added, so just start it + this.start(this._pendingState, false, false); + } + else + { + this.add('default', this._pendingState, true); + } - /** - * The state to be switched to in the next frame. - * @property {Description} states - */ - states: {}, + } - /** - * The current active State object (defaults to null). - * @property {string} current - */ - current: '', - - /** - * This will be called when the state is started (i.e. set as the current active state). - * @property {function} onInitCallback - */ - onInitCallback: null, + }, - /** - * This will be called when init states (loading assets...). - * @property {function} onPreloadCallback - */ - onPreloadCallback: null, - - /** - * This will be called when create states (setup states...). - * @property {function} onCreateCallback - */ - onCreateCallback: null, - - /** - * This will be called when State is updated, this doesn't happen during load (@see onLoadUpdateCallback). - * @property {function} onUpdateCallback - */ - onUpdateCallback: null, - - /** - * This will be called when the State is rendered, this doesn't happen during load (see onLoadRenderCallback). - * @property {function} onRenderCallback - */ - onRenderCallback: null, - - /** - * This will be called before the State is rendered and before the stage is cleared. - * @property {function} onPreRenderCallback - */ - onPreRenderCallback: null, - - /** - * This will be called when the State is updated but only during the load process. - * @property {function} onLoadUpdateCallback - */ - onLoadUpdateCallback: null, - - /** - * This will be called when the State is rendered but only during the load process. - * @property {function} onLoadRenderCallback - */ - onLoadRenderCallback: null, - - /** - * This will be called when states paused. - * @property {function} onPausedCallback - */ - onPausedCallback: null, - - /** - * This will be called when the state is shut down (i.e. swapped to another state). - * @property {function} onShutDownCallback - */ - onShutDownCallback: null, - - /** - * Description. - * @method Phaser.StateManager#boot - * @private - */ - boot: function () { - - // console.log('Phaser.StateManager.boot'); - - if (this._pendingState !== null) - { - // console.log('_pendingState found'); - // console.log(typeof this._pendingState); - - if (typeof this._pendingState === 'string') - { - // State was already added, so just start it - this.start(this._pendingState, false, false); - } - else - { - this.add('default', this._pendingState, true); - } - - } - - }, - - /** + /** * Add a new State. * @method Phaser.StateManager#add * @param key {string} - A unique key you use to reference this state, i.e. "MainMenu", "Level1". @@ -166,78 +137,69 @@ Phaser.StateManager.prototype = { if (typeof autoStart === "undefined") { autoStart = false; } - // console.log('Phaser.StateManager.addState', key); - // console.log(typeof state); - // console.log('autoStart?', autoStart); + var newState; - var newState; + if (state instanceof Phaser.State) + { + newState = state; + } + else if (typeof state === 'object') + { + newState = state; + newState.game = this.game; + } + else if (typeof state === 'function') + { + newState = new state(this.game); + } - if (state instanceof Phaser.State) - { - // console.log('Phaser.StateManager.addState: Phaser.State given'); - newState = state; - } - else if (typeof state === 'object') - { - // console.log('Phaser.StateManager.addState: Object given'); - newState = state; - newState.game = this.game; - } - else if (typeof state === 'function') - { - // console.log('Phaser.StateManager.addState: Function given'); - newState = new state(this.game); - } + this.states[key] = newState; - this.states[key] = newState; + if (autoStart) + { + if (this.game.isBooted) + { + this.start(key); + } + else + { + this._pendingState = key; + } + } - if (autoStart) - { - if (this.game.isBooted) - { - // console.log('Game is booted, so we can start the state now'); - this.start(key); - } - else - { - // console.log('Game is NOT booted, so set the current state as pending'); - this._pendingState = key; - } - } - - return newState; + return newState; }, - /** + /** * Delete the given state. * @method Phaser.StateManager#remove * @param {string} key - A unique key you use to reference this state, i.e. "MainMenu", "Level1". */ remove: function (key) { - if (this.current == key) - { - this.callbackContext = null; + if (this.current == key) + { + this.callbackContext = null; - this.onInitCallback = null; - this.onShutDownCallback = null; + this.onInitCallback = null; + this.onShutDownCallback = null; - this.onPreloadCallback = null; - this.onLoadRenderCallback = null; - this.onLoadUpdateCallback = null; - this.onCreateCallback = null; - this.onUpdateCallback = null; - this.onRenderCallback = null; - this.onPausedCallback = null; - this.onDestroyCallback = null; - } + this.onPreloadCallback = null; + this.onLoadRenderCallback = null; + this.onLoadUpdateCallback = null; + this.onCreateCallback = null; + this.onUpdateCallback = null; + this.onRenderCallback = null; + this.onPausedCallback = null; + this.onDestroyCallback = null; + } - delete this.states[key]; + delete this.states[key]; }, - /** + /** * Start the given state * @method Phaser.StateManager#start * @param {string} key - The key of the state you want to start. @@ -246,84 +208,75 @@ Phaser.StateManager.prototype = { */ start: function (key, clearWorld, clearCache) { - // console.log('Phaser.StateManager.start', key); - // console.log(this); - // console.log(this.callbackContext); - if (typeof clearWorld === "undefined") { clearWorld = true; } if (typeof clearCache === "undefined") { clearCache = false; } - if (this.game.isBooted == false) + if (this.game.isBooted === false) { - // console.log('Game is NOT booted, so set the requested state as pending'); - this._pendingState = key; - return; + this._pendingState = key; + return; } - if (this.checkState(key) == false) - { - return; - } - else - { - // Already got a state running? - if (this.current) - { - this.onShutDownCallback.call(this.callbackContext, this.game); - } + if (this.checkState(key) === false) + { + return; + } + else + { + // Already got a state running? + if (this.current) + { + this.onShutDownCallback.call(this.callbackContext, this.game); + } - if (clearWorld) - { - this.game.tweens.removeAll(); + if (clearWorld) + { + this.game.tweens.removeAll(); - this.game.world.destroy(); + this.game.world.destroy(); - if (clearCache == true) - { - this.game.cache.destroy(); - } - } + if (clearCache === true) + { + this.game.cache.destroy(); + } + } - this.setCurrentState(key); - } + this.setCurrentState(key); + } if (this.onPreloadCallback) { - // console.log('Preload Callback found'); this.game.load.reset(); this.onPreloadCallback.call(this.callbackContext, this.game); // Is the loader empty? - if (this.game.load.queueSize == 0) + if (this.game.load.queueSize === 0) { - // console.log('Loader queue empty'); this.game.loadComplete(); } else { - // console.log('Loader started'); // Start the loader going as we have something in the queue this.game.load.start(); } } else { - // console.log('Preload callback not found'); // No init? Then there was nothing to load either this.game.loadComplete(); } }, - - /** - * Used by onInit and onShutdown when those functions don't exist on the state + + /** + * Used by onInit and onShutdown when those functions don't exist on the state * @method Phaser.StateManager#dummy * @private */ dummy: function () { }, - /** + /** * Description. * @method Phaser.StateManager#checkState * @param {string} key - The key of the state you want to check. @@ -331,37 +284,37 @@ Phaser.StateManager.prototype = { */ checkState: function (key) { - if (this.states[key]) - { - var valid = false; + if (this.states[key]) + { + var valid = false; - if (this.states[key]['preload']) { valid = true; } + if (this.states[key]['preload']) { valid = true; } - if (valid == false && this.states[key]['loadRender']) { valid = true; } - if (valid == false && this.states[key]['loadUpdate']) { valid = true; } - if (valid == false && this.states[key]['create']) { valid = true; } - if (valid == false && this.states[key]['update']) { valid = true; } - if (valid == false && this.states[key]['preRender']) { valid = true; } - if (valid == false && this.states[key]['render']) { valid = true; } - if (valid == false && this.states[key]['paused']) { valid = true; } + if (valid === false && this.states[key]['loadRender']) { valid = true; } + if (valid === false && this.states[key]['loadUpdate']) { valid = true; } + if (valid === false && this.states[key]['create']) { valid = true; } + if (valid === false && this.states[key]['update']) { valid = true; } + if (valid === false && this.states[key]['preRender']) { valid = true; } + if (valid === false && this.states[key]['render']) { valid = true; } + if (valid === false && this.states[key]['paused']) { valid = true; } - if (valid == false) - { - console.warn("Invalid Phaser State object given. Must contain at least a one of the required functions."); - return false; - } + if (valid === false) + { + console.warn("Invalid Phaser State object given. Must contain at least a one of the required functions."); + return false; + } - return true; - } - else - { - console.warn("Phaser.StateManager - No state found with the key: " + key); - return false; - } + return true; + } + else + { + console.warn("Phaser.StateManager - No state found with the key: " + key); + return false; + } }, - /** + /** * Links game properties to the State given by the key. * @method Phaser.StateManager#link * @param {string} key - State key. @@ -369,7 +322,6 @@ Phaser.StateManager.prototype = { */ link: function (key) { - // console.log('linked'); this.states[key].game = this.game; this.states[key].add = this.game.add; this.states[key].camera = this.game.camera; @@ -388,19 +340,19 @@ Phaser.StateManager.prototype = { }, - /** + /** * Sets the current State. Should not be called directly (use StateManager.start) * @method Phaser.StateManager#setCurrentState * @param {string} key - State key. * @protected */ - setCurrentState: function (key) { + setCurrentState: function (key) { this.callbackContext = this.states[key]; this.link(key); - // Used when the state is set as being the current active state + // Used when the state is set as being the current active state this.onInitCallback = this.states[key]['init'] || this.dummy; this.onPreloadCallback = this.states[key]['preload'] || null; @@ -412,102 +364,99 @@ Phaser.StateManager.prototype = { this.onRenderCallback = this.states[key]['render'] || null; this.onPausedCallback = this.states[key]['paused'] || null; - // Used when the state is no longer the current active state + // Used when the state is no longer the current active state this.onShutDownCallback = this.states[key]['shutdown'] || this.dummy; - this.current = key; - this._created = false; + this.current = key; + this._created = false; - this.onInitCallback.call(this.callbackContext, this.game); + this.onInitCallback.call(this.callbackContext, this.game); - }, + }, - /** - * @method Phaser.StateManager#loadComplete + /** + * @method Phaser.StateManager#loadComplete * @protected - */ + */ loadComplete: function () { - // console.log('Phaser.StateManager.loadComplete'); - - if (this._created == false && this.onCreateCallback) + if (this._created === false && this.onCreateCallback) { - // console.log('Create callback found'); - this._created = true; + this._created = true; this.onCreateCallback.call(this.callbackContext, this.game); } else { - this._created = true; + this._created = true; } }, - /** - * @method Phaser.StateManager#update + /** + * @method Phaser.StateManager#update * @protected - */ + */ update: function () { - if (this._created && this.onUpdateCallback) - { - this.onUpdateCallback.call(this.callbackContext, this.game); - } - else - { - if (this.onLoadUpdateCallback) - { - this.onLoadUpdateCallback.call(this.callbackContext, this.game); - } - } + if (this._created && this.onUpdateCallback) + { + this.onUpdateCallback.call(this.callbackContext, this.game); + } + else + { + if (this.onLoadUpdateCallback) + { + this.onLoadUpdateCallback.call(this.callbackContext, this.game); + } + } }, - /** - * @method Phaser.StateManager#preRender + /** + * @method Phaser.StateManager#preRender * @protected - */ + */ preRender: function () { - if (this.onPreRenderCallback) - { - this.onPreRenderCallback.call(this.callbackContext, this.game); - } + if (this.onPreRenderCallback) + { + this.onPreRenderCallback.call(this.callbackContext, this.game); + } }, - /** - * @method Phaser.StateManager#render + /** + * @method Phaser.StateManager#render * @protected - */ + */ render: function () { - if (this._created && this.onRenderCallback) - { - if (this.game.renderType === Phaser.CANVAS) - { - this.game.context.save(); - this.game.context.setTransform(1, 0, 0, 1, 0, 0); - } + if (this._created && this.onRenderCallback) + { + if (this.game.renderType === Phaser.CANVAS) + { + this.game.context.save(); + this.game.context.setTransform(1, 0, 0, 1, 0, 0); + } - this.onRenderCallback.call(this.callbackContext, this.game); + this.onRenderCallback.call(this.callbackContext, this.game); - if (this.game.renderType === Phaser.CANVAS) - { - this.game.context.restore(); - } - } - else - { - if (this.onLoadRenderCallback) - { - this.onLoadRenderCallback.call(this.callbackContext, this.game); - } - } + if (this.game.renderType === Phaser.CANVAS) + { + this.game.context.restore(); + } + } + else + { + if (this.onLoadRenderCallback) + { + this.onLoadRenderCallback.call(this.callbackContext, this.game); + } + } }, - /** + /** * Nuke the entire game from orbit * @method Phaser.StateManager#destroy */ diff --git a/src/core/World.js b/src/core/World.js index 12464e5b..46f33dd6 100644 --- a/src/core/World.js +++ b/src/core/World.js @@ -21,7 +21,7 @@ Phaser.World = function (game) { /** * @property {Phaser.Point} scale - Replaces the PIXI.Point with a slightly more flexible one. - */ + */ this.scale = new Phaser.Point(1, 1); /** @@ -29,20 +29,20 @@ Phaser.World = function (game) { * By default we set the Bounds to be from 0,0 to Game.width,Game.height. I.e. it will match the size given to the game constructor with 0,0 representing the top-left of the display. * However 0,0 is actually the center of the world, and if you rotate or scale the world all of that will happen from 0,0. * So if you want to make a game in which the world itself will rotate you should adjust the bounds so that 0,0 is the center point, i.e. set them to -1000,-1000,2000,2000 for a 2000x2000 sized world centered around 0,0. - * @property {Phaser.Rectangle} bounds - Bound of this world that objects can not escape from. - */ - this.bounds = new Phaser.Rectangle(0, 0, game.width, game.height); + * @property {Phaser.Rectangle} bounds - Bound of this world that objects can not escape from. + */ + this.bounds = new Phaser.Rectangle(0, 0, game.width, game.height); /** - * @property {Phaser.Camera} camera - Camera instance. - */ - this.camera = null; + * @property {Phaser.Camera} camera - Camera instance. + */ + this.camera = null; /** - * @property {number} currentRenderOrderID - Reset each frame, keeps a count of the total number of objects updated. - */ - this.currentRenderOrderID = 0; - + * @property {number} currentRenderOrderID - Reset each frame, keeps a count of the total number of objects updated. + */ + this.currentRenderOrderID = 0; + }; Phaser.World.prototype = Object.create(Phaser.Group.prototype); @@ -71,27 +71,27 @@ Phaser.World.prototype.boot = function () { */ Phaser.World.prototype.update = function () { - this.currentRenderOrderID = 0; + this.currentRenderOrderID = 0; - if (this.game.stage._stage.first._iNext) - { - var currentNode = this.game.stage._stage.first._iNext; + if (this.game.stage._stage.first._iNext) + { + var currentNode = this.game.stage._stage.first._iNext; var skipChildren; - - do - { + + do + { skipChildren = false; - if (currentNode['preUpdate']) - { - skipChildren = (currentNode.preUpdate() === false); - } + if (currentNode['preUpdate']) + { + skipChildren = (currentNode.preUpdate() === false); + } - if (currentNode['update']) - { - skipChildren = (currentNode.update() === false) || skipChildren; - } - + if (currentNode['update']) + { + skipChildren = (currentNode.update() === false) || skipChildren; + } + if (skipChildren) { currentNode = currentNode.last._iNext; @@ -100,10 +100,10 @@ Phaser.World.prototype.update = function () { { currentNode = currentNode._iNext; } - - } - while (currentNode != this.game.stage._stage.last._iNext) - } + + } + while (currentNode != this.game.stage._stage.last._iNext) + } } @@ -119,7 +119,7 @@ Phaser.World.prototype.postUpdate = function () { { var currentNode = this.game.stage._stage.first._iNext; - do + do { if (currentNode['postUpdate']) { diff --git a/src/gameobjects/BitmapData.js b/src/gameobjects/BitmapData.js index 177a6c16..d5227b90 100644 --- a/src/gameobjects/BitmapData.js +++ b/src/gameobjects/BitmapData.js @@ -15,215 +15,216 @@ */ Phaser.BitmapData = function (game, width, height) { - if (typeof width === 'undefined') { width = 256; } - if (typeof height === 'undefined') { height = 256; } + if (typeof width === 'undefined') { width = 256; } + if (typeof height === 'undefined') { height = 256; } - /** - * @property {Phaser.Game} game - A reference to the currently running game. - */ - this.game = game; + /** + * @property {Phaser.Game} game - A reference to the currently running game. + */ + this.game = game; - /** + /** * @property {string} name - The name of the BitmapData. - */ + */ this.name = ''; - /** - * @property {number} width - The width of the BitmapData in pixels. + /** + * @property {number} width - The width of the BitmapData in pixels. */ - this.width = width; - - /** - * @property {number} height - The height of the BitmapData in pixels. + this.width = width; + + /** + * @property {number} height - The height of the BitmapData in pixels. */ - this.height = height; + this.height = height; - /** - * @property {HTMLCanvasElement} canvas - The canvas to which this BitmapData draws. - * @default - */ + /** + * @property {HTMLCanvasElement} canvas - The canvas to which this BitmapData draws. + * @default + */ this.canvas = Phaser.Canvas.create(width, height); - /** - * @property {CanvasRenderingContext2D} context - The 2d context of the canvas. - * @default - */ + /** + * @property {CanvasRenderingContext2D} context - The 2d context of the canvas. + * @default + */ this.context = this.canvas.getContext('2d'); - /** - * @property {array} imageData - The canvas image data. - */ - this.imageData = this.context.getImageData(0, 0, width, height); + /** + * @property {array} imageData - The canvas image data. + */ + this.imageData = this.context.getImageData(0, 0, width, height); - /** - * @property {UInt8Clamped} pixels - A reference to the context imageData buffer. - */ - if (this.imageData.data.buffer) - { - this.pixels = this.imageData.data.buffer; - } - else - { - this.pixels = this.imageData.data; - } + /** + * @property {UInt8Clamped} pixels - A reference to the context imageData buffer. + */ + if (this.imageData.data.buffer) + { + this.pixels = this.imageData.data.buffer; + } + else + { + this.pixels = this.imageData.data; + } - /** - * @property {PIXI.BaseTexture} baseTexture - The PIXI.BaseTexture. - * @default - */ + /** + * @property {PIXI.BaseTexture} baseTexture - The PIXI.BaseTexture. + * @default + */ this.baseTexture = new PIXI.BaseTexture(this.canvas); - /** - * @property {PIXI.Texture} texture - The PIXI.Texture. - * @default - */ + /** + * @property {PIXI.Texture} texture - The PIXI.Texture. + * @default + */ this.texture = new PIXI.Texture(this.baseTexture); - /** - * @property {Phaser.Frame} textureFrame - The Frame this BitmapData uses for rendering. - * @default - */ + /** + * @property {Phaser.Frame} textureFrame - The Frame this BitmapData uses for rendering. + * @default + */ this.textureFrame = new Phaser.Frame(0, 0, 0, width, height, 'bitmapData', game.rnd.uuid()); /** - * @property {number} type - The const type of this object. + * @property {number} type - The const type of this object. * @default - */ + */ this.type = Phaser.BITMAPDATA; - this._dirty = false; + this._dirty = false; } Phaser.BitmapData.prototype = { - /** - * Updates the given Sprite so that it uses this BitmapData as its texture. - * @method Phaser.BitmapData.add - * @param {Phaser.Sprite} sprite - The sprite to apply this texture to. - */ - add: function (sprite) { + /** + * Updates the given Sprite so that it uses this BitmapData as its texture. + * @method Phaser.BitmapData.add + * @param {Phaser.Sprite} sprite - The sprite to apply this texture to. + */ + add: function (sprite) { - sprite.loadTexture(this); + sprite.loadTexture(this); - }, + }, - /** - * Given an array of Sprites it will update each of them so that their Textures reference this BitmapData. - * @method Phaser.BitmapData.addTo - * @param {Phaser.Sprite[]} sprites - An array of Sprites to apply this texture to. - */ - addTo: function (sprites) { + /** + * Given an array of Sprites it will update each of them so that their Textures reference this BitmapData. + * @method Phaser.BitmapData.addTo + * @param {Phaser.Sprite[]} sprites - An array of Sprites to apply this texture to. + */ + addTo: function (sprites) { - for (var i = 0; i < objects.length; i++) - { - if (objects[i].texture) - { - } - } + for (var i = 0; i < sprites.length; i++) + { + if (sprites[i].texture) + { + sprites[i].loadTexture(this); + } + } - }, + }, - /** - * Clears the BitmapData. - * @method Phaser.BitmapData.clear - */ - clear: function () { + /** + * Clears the BitmapData. + * @method Phaser.BitmapData.clear + */ + clear: function () { - this.context.clearRect(0, 0, this.width, this.height); - - this._dirty = true; + this.context.clearRect(0, 0, this.width, this.height); + + this._dirty = true; - }, + }, - refreshBuffer: function () { + refreshBuffer: function () { - this.imageData = this.context.getImageData(0, 0, this.width, this.height); - this.pixels = new Int32Array(this.imageData.data.buffer); + this.imageData = this.context.getImageData(0, 0, this.width, this.height); + this.pixels = new Int32Array(this.imageData.data.buffer); - // this.data8 = new Uint8ClampedArray(this.imageData.buffer); - // this.data32 = new Uint32Array(this.imageData.buffer); + // this.data8 = new Uint8ClampedArray(this.imageData.buffer); + // this.data32 = new Uint32Array(this.imageData.buffer); - }, + }, - /** - * Sets the color of the given pixel to the specified red, green, blue and alpha values. - * @method Phaser.BitmapData.setPixel32 - * @param {number} x - The X coordinate of the pixel to be set. - * @param {number} y - The Y coordinate of the pixel to be set. - * @param {number} red - The red color value, between 0 and 0xFF (255). - * @param {number} green - The green color value, between 0 and 0xFF (255). - * @param {number} blue - The blue color value, between 0 and 0xFF (255). - * @param {number} alpha - The alpha color value, between 0 and 0xFF (255). - */ + /** + * Sets the color of the given pixel to the specified red, green, blue and alpha values. + * @method Phaser.BitmapData.setPixel32 + * @param {number} x - The X coordinate of the pixel to be set. + * @param {number} y - The Y coordinate of the pixel to be set. + * @param {number} red - The red color value, between 0 and 0xFF (255). + * @param {number} green - The green color value, between 0 and 0xFF (255). + * @param {number} blue - The blue color value, between 0 and 0xFF (255). + * @param {number} alpha - The alpha color value, between 0 and 0xFF (255). + */ setPixel32: function (x, y, red, green, blue, alpha) { - if (x >= 0 && x <= this.width && y >= 0 && y <= this.height) - { - this.pixels[y * this.width + x] = (alpha << 24) | (blue << 16) | (green << 8) | red; + if (x >= 0 && x <= this.width && y >= 0 && y <= this.height) + { + this.pixels[y * this.width + x] = (alpha << 24) | (blue << 16) | (green << 8) | red; - /* - if (this.isLittleEndian) - { - this.data32[y * this.width + x] = (alpha << 24) | (blue << 16) | (green << 8) | red; - } - else - { - this.data32[y * this.width + x] = (red << 24) | (green << 16) | (blue << 8) | alpha; - } - */ + /* + if (this.isLittleEndian) + { + this.data32[y * this.width + x] = (alpha << 24) | (blue << 16) | (green << 8) | red; + } + else + { + this.data32[y * this.width + x] = (red << 24) | (green << 16) | (blue << 8) | alpha; + } + */ - // this.imageData.data.set(this.data8); + // this.imageData.data.set(this.data8); - this.context.putImageData(this.imageData, 0, 0); + this.context.putImageData(this.imageData, 0, 0); - this._dirty = true; - } + this._dirty = true; + } }, - /** - * Sets the color of the given pixel to the specified red, green and blue values. - * @method Phaser.BitmapData.setPixel - * @param {number} x - The X coordinate of the pixel to be set. - * @param {number} y - The Y coordinate of the pixel to be set. - * @param {number} red - The red color value (between 0 and 255) - * @param {number} green - The green color value (between 0 and 255) - * @param {number} blue - The blue color value (between 0 and 255) - */ + /** + * Sets the color of the given pixel to the specified red, green and blue values. + * @method Phaser.BitmapData.setPixel + * @param {number} x - The X coordinate of the pixel to be set. + * @param {number} y - The Y coordinate of the pixel to be set. + * @param {number} red - The red color value (between 0 and 255) + * @param {number} green - The green color value (between 0 and 255) + * @param {number} blue - The blue color value (between 0 and 255) + */ setPixel: function (x, y, red, green, blue) { - this.setPixel32(x, y, red, green, blue, 255); + this.setPixel32(x, y, red, green, blue, 255); }, - /** - * Get a color of a specific pixel. - * @param {number} x - The X coordinate of the pixel to get. - * @param {number} y - The Y coordinate of the pixel to get. - * @return {number} A native color value integer (format: 0xRRGGBB) - */ + /** + * Get a color of a specific pixel. + * @param {number} x - The X coordinate of the pixel to get. + * @param {number} y - The Y coordinate of the pixel to get. + * @return {number} A native color value integer (format: 0xRRGGBB) + */ getPixel: function (x, y) { - if (x >= 0 && x <= this.width && y >= 0 && y <= this.height) - { - return this.data32[y * this.width + x]; - } + if (x >= 0 && x <= this.width && y >= 0 && y <= this.height) + { + return this.data32[y * this.width + x]; + } }, - /** - * Get a color of a specific pixel (including alpha value). - * @param {number} x - The X coordinate of the pixel to get. - * @param {number} y - The Y coordinate of the pixel to get. - * @return {number} A native color value integer (format: 0xAARRGGBB) - */ + /** + * Get a color of a specific pixel (including alpha value). + * @param {number} x - The X coordinate of the pixel to get. + * @param {number} y - The Y coordinate of the pixel to get. + * @return {number} A native color value integer (format: 0xAARRGGBB) + */ getPixel32: function (x, y) { - if (x >= 0 && x <= this.width && y >= 0 && y <= this.height) - { - return this.data32[y * this.width + x]; - } + if (x >= 0 && x <= this.width && y >= 0 && y <= this.height) + { + return this.data32[y * this.width + x]; + } }, @@ -234,721 +235,724 @@ Phaser.BitmapData.prototype = { */ getPixels: function (rect) { - // return this.context.getImageData(rect.x, rect.y, rect.width, rect.height); + return this.context.getImageData(rect.x, rect.y, rect.width, rect.height); }, - /** - * Adds an arc to the path which is centered at (x, y) position with radius r starting at startAngle and ending at endAngle - * going in the given direction by anticlockwise (defaulting to clockwise). - * @method Phaser.BitmapData.arc - * @param {number} x - The x axis of the coordinate for the arc's center - * @param {number} y - The y axis of the coordinate for the arc's center - * @param {number} radius - The arc's radius - * @param {number} startAngle - The starting point, measured from the x axis, from which it will be drawn, expressed in radians. - * @param {number} endAngle - The end arc's angle to which it will be drawn, expressed in radians. - * @param {boolean} [anticlockwise=true] - true draws the arc anticlockwise, otherwise in a clockwise direction. - * @return {Phaser.BitmapData} The BitmapData instance this method was called on. - */ - arc: function (x, y, radius, startAngle, endAngle, anticlockwise) { - - if (typeof anticlockwise === 'undefined') { anticlockwise = false; } - - this._dirty = true; - this.context.arc(x, y, radius, startAngle, endAngle, anticlockwise); - return this; - - }, - - /** - * Adds an arc with the given control points and radius, connected to the previous point by a straight line. - * @method Phaser.BitmapData.arcTo - * @param {number} x1 - * @param {number} y1 - * @param {number} x2 - * @param {number} y2 - * @param {number} radius - * @return {Phaser.BitmapData} The BitmapData instance this method was called on. - */ - arcTo: function (x1, y1, x2, y2, radius) { - - this._dirty = true; - this.context.arcTo(x1, y1, x2, y2, radius); - return this; - - }, - - /** - * Begins a fill with the specified color. This ends the current sub-path. - * @method Phaser.BitmapData.beginFill - * @param {string} color - A CSS compatible color value (ex. "red", "#FF0000", or "rgba(255,0,0,0.5)"). Setting to null will result in no fill. - * @return {Phaser.BitmapData} The BitmapData instance this method was called on. - */ - beginFill: function (color) { - - this.fillStyle(color); - - return this; - - }, - - /** - * Begins a linear gradient fill defined by the line (x0, y0) to (x1, y1). This ends the current sub-path. For - * example, the following code defines a black to white vertical gradient ranging from 20px to 120px, and draws a square to display it: - * - * ```myGraphics.beginLinearGradientFill(["#000","#FFF"], [0, 1], 0, 20, 0, 120).rect(20, 20, 120, 120);``` - * - * @method Phaser.BitmapData.beginLinearGradientFill - * @param {Array} colors - An array of CSS compatible color values. For example, ["#F00","#00F"] would define a gradient drawing from red to blue. - * @param {Array} ratios - An array of gradient positions which correspond to the colors. For example, [0.1, 0.9] would draw the first color to 10% then interpolating to the second color at 90%. - * @param {number} x0 - The position of the first point defining the line that defines the gradient direction and size. - * @param {number} y0 - The position of the first point defining the line that defines the gradient direction and size. - * @param {number} x1 - The position of the second point defining the line that defines the gradient direction and size. - * @param {number} y1 - The position of the second point defining the line that defines the gradient direction and size. - * @return {Phaser.BitmapData} The BitmapData instance this method was called on. - */ - beginLinearGradientFill: function (colors, ratios, x0, y0, x1, y1) { - - var gradient = this.createLinearGradient(x0, y0, x1, y1); - - for (var i = 0, len = colors.length; i < len; i++) - { - gradient.addColorStop(ratios[i], colors[i]); - } - - this.fillStyle(gradient); - - return this; - - }, - - /** - * Begins a linear gradient stroke defined by the line (x0, y0) to (x1, y1). This ends the current sub-path. For - * example, the following code defines a black to white vertical gradient ranging from 20px to 120px, and draws a - * square to display it: - * - * ```myGraphics.setStrokeStyle(10).beginLinearGradientStroke(["#000","#FFF"], [0, 1], 0, 20, 0, 120).drawRect(20, 20, 120, 120);``` - * - * @method Phaser.BitmapData.beginLinearGradientStroke - * @param {Array} colors - An array of CSS compatible color values. For example, ["#F00","#00F"] would define a gradient drawing from red to blue. - * @param {Array} ratios - An array of gradient positions which correspond to the colors. For example, [0.1, 0.9] would draw the first color to 10% then interpolating to the second color at 90%. - * @param {number} x0 - The position of the first point defining the line that defines the gradient direction and size. - * @param {number} y0 - The position of the first point defining the line that defines the gradient direction and size. - * @param {number} x1 - The position of the second point defining the line that defines the gradient direction and size. - * @param {number} y1 - The position of the second point defining the line that defines the gradient direction and size. - * @return {Phaser.BitmapData} The BitmapData instance this method was called on. - */ - beginLinearGradientStroke: function (colors, ratios, x0, y0, x1, y1) { - - var gradient = this.createLinearGradient(x0, y0, x1, y1); - - for (var i = 0, len = colors.length; i < len; i++) - { - gradient.addColorStop(ratios[i], colors[i]); - } - - this.strokeStyle(gradient); - - return this; - - }, - - /** - * Begins a radial gradient stroke. This ends the current sub-path. For example, the following code defines a red to - * blue radial gradient centered at (100, 100), with a radius of 50, and draws a rectangle to display it: - * - * myGraphics.setStrokeStyle(10) - * .beginRadialGradientStroke(["#F00","#00F"], [0, 1], 100, 100, 0, 100, 100, 50) - * .drawRect(50, 90, 150, 110); - * - * @method Phaser.BitmapData.beginRadialGradientStroke - * @param {Array} colors - An array of CSS compatible color values. For example, ["#F00","#00F"] would define a gradient drawing from red to blue. - * @param {Array} ratios - An array of gradient positions which correspond to the colors. For example, [0.1, 0.9] would draw the first color to 10% then interpolating to the second color at 90%. - * @param {number} x0 - Center position of the inner circle that defines the gradient. - * @param {number} y0 - Center position of the inner circle that defines the gradient. - * @param {number} r0 - Radius of the inner circle that defines the gradient. - * @param {number} x1 - Center position of the outer circle that defines the gradient. - * @param {number} y1 - Center position of the outer circle that defines the gradient. - * @param {number} r1 - Radius of the outer circle that defines the gradient. - * @return {Phaser.BitmapData} The BitmapData instance this method was called on. - */ - beginRadialGradientStroke: function (colors, ratios, x0, y0, r0, x1, y1, r1) { - - var gradient = this.createRadialGradient(x0, y0, r0, x1, y1, r1); - - for (var i = 0, len = colors.length; i < len; i++) - { - gradient.addColorStop(ratios[i], colors[i]); - } - - this.strokeStyle(gradient); - - return this; - - }, - - /** - * Starts a new path by resetting the list of sub-paths. Call this method when you want to create a new path. - * @method Phaser.BitmapData.beginPath - * @return {Phaser.BitmapData} The BitmapData instance this method was called on. - */ - beginPath: function () { - - this.context.beginPath(); - return this; - - }, - - /** - * Begins a stroke with the specified color. This ends the current sub-path. - * @method Phaser.BitmapData.beginStroke - * @param {String} color A CSS compatible color value (ex. "#FF0000", "red", or "rgba(255,0,0,0.5)"). Setting to null will result in no stroke. - * @return {Phaser.BitmapData} The BitmapData instance this method was called on. - */ - beginStroke: function (color) { - - this.strokeStyle(color); - return this; - - }, - - /** - * Adds a bezier curve from the current context point to (x, y) using the control points (cp1x, cp1y) and (cp2x, cp2y). - * @method Phaser.BitmapData.bezierCurveTo - * @param {number} cp1x - The x axis of control point 1. - * @param {number} cp1y - The y axis of control point 1. - * @param {number} cp2x - The x axis of control point 2. - * @param {number} cp2y - The y axis of control point 2. - * @param {number} x - The x axis of the ending point. - * @param {number} y - The y axis of the ending point. - * @return {Phaser.BitmapData} The BitmapData instance this method was called on. - */ - bezierCurveTo: function (cp1x, cp1y, cp2x, cp2y, x, y) { - - this._dirty = true; - this.context.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y); - return this; - - }, - - /** - * Draws a circle with the specified radius at (x, y). - * @method Phaser.BitmapData.circle - * @param {number} x - x coordinate center point of circle. - * @param {number} y - y coordinate center point of circle. - * @param {number} radius - Radius of circle in radians. - * @return {Phaser.BitmapData} The BitmapData instance this method was called on. - */ - circle: function (x, y, radius) { - - this.arc(x, y, radius, 0, Math.PI*2); - return this; - - }, - - /** - * Sets all pixels in the rectangle defined by starting point (x, y) and size (width, height) to transparent black. - * @method Phaser.BitmapData.clearRect - * @param {number} x - The x axis of the coordinate for the rectangle starting point. - * @param {number} y - The y axis of the coordinate for the rectangle starting point. - * @param {number} width - The rectangles width. - * @param {number} height - The rectangles height. - * @return {Phaser.BitmapData} The BitmapData instance this method was called on. - */ - clearRect: function (x, y, width, height) { - - this._dirty = true; - this.context.clearRect(x, y, width, height); - return this; - - }, - - /** - * Creates a clipping path from the current sub-paths. Everything drawn after clip() is called appears inside the clipping path only. - * @method Phaser.BitmapData.clip - * @return {Phaser.BitmapData} The BitmapData instance this method was called on. - */ - clip: function (x, y, width, height) { - - this._dirty = true; - this.context.clip(); - return this; - - }, - - /** - * Tries to draw a straight line from the current point to the start. If the shape has already been closed or has only one point, this function does nothing. - * @method Phaser.BitmapData.closePath - * @return {Phaser.BitmapData} The BitmapData instance this method was called on. - */ - closePath: function () { - - this._dirty = true; - this.context.closePath(); - return this; - - }, - - /** - * Creates a linear gradient with defined by an imaginary line which implies the direction of the gradient. - * Once the gradient is created colors can be inserted using the addColorStop method. - * @method Phaser.BitmapData.createLinearGradient - * @param {number} x - The x axis of the coordinate for the gradients starting point. - * @param {number} y - The y axis of the coordinate for the gradients starting point. - * @param {number} width - The width of the gradient. - * @param {number} height - The height of the gradient. - * @return {CanvasGradient} The Linear Gradient. - */ - createLinearGradient: function (x, y, width, height) { - - return this.context.createLinearGradient(x, y, width, height); - - }, - - // createPattern - - /** - * Creates a radial gradient. - * @method Phaser.BitmapData.createRadialGradient - * @param {number} x0 - * @param {number} y0 - * @param {number} r0 - * @param {number} x1 - * @param {number} y1 - * @param {number} r1 - * @return {CanvasGradient} The Radial Gradient. - */ - createRadialGradient: function (x, y, width, height) { - - return this.context.createRadialGradient(x0, y0, r0, x1, y1, r1); - - }, - - // drawImage - // drawSystemFocusRing (?) - - /** - * Draws an ellipse (oval) with a specified width (w) and height (h). - * @method Phaser.BitmapData.ellipse - * @param {number} x - x coordinate center point of ellipse. - * @param {number} y - y coordinate center point of ellipse. - * @param {number} w - height (horizontal diameter) of ellipse. The horizontal radius will be half of this number. - * @param {number} h - width (vertical diameter) of ellipse. The vertical radius will be half of this number. - * @return {Phaser.BitmapData} The BitmapData instance this method was called on. - */ - ellipse: function (x, y, w, h) { - - var k = 0.5522848; - var ox = (w / 2) * k; - var oy = (h / 2) * k; - var xe = x + w; - var ye = y + h; - var xm = x + w / 2; - var ym = y + h / 2; - - this.moveTo(x, ym); - this.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y); - this.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym); - this.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye); - this.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym); - - return this; - - }, - - /** - * Fills the subpaths with the current fill style. - * @method Phaser.BitmapData.fill - * @return {Phaser.BitmapData} The BitmapData instance this method was called on. - */ - fill: function () { - - this._dirty = true; - this.context.fill(); - return this; - - }, - - /** - * Draws a filled rectangle at (x, y) position whose size is determined by width and height. - * @method Phaser.BitmapData.fillRect - * @param {number} x - The x axis of the coordinate for the rectangle starting point. - * @param {number} y - The y axis of the coordinate for the rectangle starting point. - * @param {number} width - The rectangles width. - * @param {number} height - The rectangles height. - * @return {Phaser.BitmapData} The BitmapData instance this method was called on. - */ - fillRect: function (x, y, width, height) { - - this._dirty = true; - this.context.fillRect(x, y, width, height); - return this; - - }, - - /** - * Sets the fill style. - * @method Phaser.BitmapData.fillStyle - * @param {string} color - The fill color value in CSS format: #RRGGBB or rgba(r,g,b,a) - * @return {Phaser.BitmapData} The BitmapData instance this method was called on. - */ - fillStyle: function (color) { - - this.context.fillStyle = color; - return this; - - }, - - // fillText - - /** - * Sets the font. - * @method Phaser.BitmapData.font - * @param {DOMString} font - The font to be used for any text rendering. Default value 10px sans-serif. - * @return {Phaser.BitmapData} The BitmapData instance this method was called on. - */ - font: function (font) { - - this.context.font = font; - return this; - - }, - - /** - * Alpha value that is applied to shapes and images before they are composited onto the canvas. Default 1.0 (opaque). - * @method Phaser.BitmapData.globalAlpha - * @param {number} alpha - Alpha value that is applied to shapes and images before they are composited onto the canvas. Default 1.0 (opaque). - * @return {Phaser.BitmapData} The BitmapData instance this method was called on. - */ - globalAlpha: function (alpha) { - - this.context.globalAlpha = alpha; - return this; - - }, - - /** - * With globalAlpha applied this sets how shapes and images are drawn onto the existing bitmap. Possible values: source-atop, source-in, source-out, - * source-over (default), destination-atop, destination-in, destination-out, destination-over, lighter, darker, copy and xor. - * @method Phaser.BitmapData.globalCompositeOperation - * @param {DOMString} operation - The composite operation to apply. - * @return {Phaser.BitmapData} The BitmapData instance this method was called on. - */ - globalCompositeOperation: function (operation) { - - this.context.globalCompositeOperation = operation; - return this; - - }, - - /** - * Type of endings on the end of lines. Possible values: butt (default), round, square. - * @method Phaser.BitmapData.lineCap - * @param {DOMString} style - Possible values: butt (default), round, square - * @return {Phaser.BitmapData} The BitmapData instance this method was called on. - */ - lineCap: function (style) { - - this.context.lineCap = style; - return this; - - }, - - /** - * Specifies where to start a dasharray on a line. - * @method Phaser.BitmapData.lineDashOffset - * @param {number} offset - Specifies where to start a dasharray on a line. - * @return {Phaser.BitmapData} The BitmapData instance this method was called on. - */ - lineDashOffset: function (offset) { - - this.context.lineDashOffset = offset; - return this; - - }, - - /** - * Defines the type of corners where two lines meet. Possible values: round, bevel, miter (default) - * @method Phaser.BitmapData.lineJoin - * @param {DOMString} join - Possible values: round, bevel, miter (default) - * @return {Phaser.BitmapData} The BitmapData instance this method was called on. - */ - lineJoin: function (join) { - - this.context.lineJoin = join; - return this; - - }, - - /** - * Width of lines. Default 1.0 - * @method Phaser.BitmapData.lineWidth - * @param {number} width - Width of lines. Default 1.0 - * @return {Phaser.BitmapData} The BitmapData instance this method was called on. - */ - lineWidth: function (width) { - - this.context.lineWidth = width; - return this; - - }, - - /** - * Default 10. - * @method Phaser.BitmapData.miterLimit - * @param {number} limit - Default 10. - * @return {Phaser.BitmapData} The BitmapData instance this method was called on. - */ - miterLimit: function (limit) { - - this.context.miterLimit = limit; - return this; - - }, - - // getImageData - // getLineDash - // isPointInPath - // isPointInStroke - - /** - * Connects the last point in the subpath to the x, y coordinates with a straight line. - * @method Phaser.BitmapData.lineTo - * @param {number} x - The x axis of the coordinate for the end of the line. - * @param {number} y - The y axis of the coordinate for the end of the line. - * @return {Phaser.BitmapData} The BitmapData instance this method was called on. - */ - lineTo: function (x, y) { - - this._dirty = true; - this.context.lineTo(x, y); - return this; - - }, - - // measureText - - /** - * Moves the starting point of a new subpath to the (x, y) coordinates. - * @method Phaser.BitmapData.moveTo - * @param {number} x - The x axis of the point. - * @param {number} y - The y axis of the point. - * @return {Phaser.BitmapData} The BitmapData instance this method was called on. - */ - moveTo: function (x, y) { - - this.context.moveTo(x, y); - return this; - - }, - - // putImageData - - /** - * Draws a quadratic curve from the current drawing point to (x, y) using the control point (cpx, cpy). - * @method Phaser.BitmapData.quadraticCurveTo - * @param {Number} cpx - The x axis of the control point. - * @param {Number} cpy - The y axis of the control point. - * @param {Number} x - The x axis of the ending point. - * @param {Number} y - The y axis of the ending point. - * @return {Phaser.BitmapData} The BitmapData instance this method was called on. - */ - quadraticCurveTo: function(cpx, cpy, x, y) { - - this._dirty = true; - this.context.quadraticCurveTo(cpx, cpy, x, y); - return this; - - }, - - /** - * Draws a rectangle at (x, y) position whose size is determined by width and height. - * @method Phaser.BitmapData.rect - * @param {number} x - The x axis of the coordinate for the rectangle starting point. - * @param {number} y - The y axis of the coordinate for the rectangle starting point. - * @param {number} width - The rectangles width. - * @param {number} height - The rectangles height. - * @return {Phaser.BitmapData} The BitmapData instance this method was called on. - */ - rect: function (x, y, width, height) { - - this._dirty = true; - this.context.rect(x, y, width, height); - return this; - - }, - - /** - * Restores the drawing style state to the last element on the 'state stack' saved by save(). - * @method Phaser.BitmapData.restore - * @return {Phaser.BitmapData} The BitmapData instance this method was called on. - */ - restore: function () { - - this._dirty = true; - this.context.restore(); - return this; - - }, - - /** - * Rotates the drawing context values by r radians. - * @method Phaser.BitmapData.rotate - * @param {number} angle - The angle of rotation given in radians. - * @return {Phaser.BitmapData} The BitmapData instance this method was called on. - */ - rotate: function (angle) { - - this._dirty = true; - this.context.rotate(angle); - return this; - - }, - - /** - * Sets the stroke style for the current sub-path. Like all drawing methods, this can be chained, so you can define - * the stroke style and color in a single line of code like so: - * - * ```myGraphics.setStrokeStyle(8,"round").beginStroke("#F00");``` - * - * @method Phaser.BitmapData.setStrokeStyle - * @param {number} thickness - The width of the stroke. - * @param {string|number} [caps=0] - Indicates the type of caps to use at the end of lines. One of butt, round, or square. Defaults to "butt". Also accepts the values 0 (butt), 1 (round), and 2 (square) for use with he tiny API. - * @param {string|number} [joints=0] Specifies the type of joints that should be used where two lines meet. One of bevel, round, or miter. Defaults to "miter". Also accepts the values 0 (miter), 1 (round), and 2 (bevel) for use with the tiny API. - * @param {number} [miterLimit=10] - If joints is set to "miter", then you can specify a miter limit ratio which controls at what point a mitered joint will be clipped. - * @param {boolean} [ignoreScale=false] - If true, the stroke will be drawn at the specified thickness regardless of active transformations. - * @return {Phaser.BitmapData} The BitmapData instance this method was called on. - */ - setStrokeStyle: function (thickness, caps, joints, miterLimit, ignoreScale) { - - if (typeof thickness === 'undefined') { thickness = 1; } - if (typeof caps === 'undefined') { caps = 'butt'; } - if (typeof joints === 'undefined') { joints = 'miter'; } - if (typeof miterLimit === 'undefined') { miterLimit = 10; } - - this.lineWidth(thickness); - this.lineCap(caps); - this.lineJoin(joints); - this.miterLimit(miterLimit); - - return this; - - }, - - /** - * Saves the current drawing style state using a stack so you can revert any change you make to it using restore(). - * @method Phaser.BitmapData.save - * @return {Phaser.BitmapData} The BitmapData instance this method was called on. - */ - save: function () { - - this._dirty = true; - this.context.save(); - return this; - - }, - - /** - * Scales the current drawing context. - * @method Phaser.BitmapData.scale - * @param {number} x - * @param {number} y - * @return {Phaser.BitmapData} The BitmapData instance this method was called on. - */ - scale: function (x, y) { - - this._dirty = true; - this.context.scale(x, y); - return this; - - }, - - /** - * - * @method Phaser.BitmapData.scrollPathIntoView - * @return {Phaser.BitmapData} The BitmapData instance this method was called on. - */ - scrollPathIntoView: function () { - - this._dirty = true; - this.context.scrollPathIntoView(); - return this; - - }, - - // setLineDash - // setTransform - - /** - * Strokes the subpaths with the current stroke style. - * @method Phaser.BitmapData.stroke - * @return {Phaser.BitmapData} The BitmapData instance this method was called on. - */ - stroke: function () { - - this._dirty = true; - this.context.stroke(); - return this; - - }, - - /** - * Paints a rectangle which has a starting point at (x, y) and has a w width and an h height onto the canvas, using the current stroke style. - * @method Phaser.BitmapData.strokeRect - * @param {number} x - The x axis for the starting point of the rectangle. - * @param {number} y - The y axis for the starting point of the rectangle. - * @param {number} width - The rectangles width. - * @param {number} height - The rectangles height. - * @return {Phaser.BitmapData} The BitmapData instance this method was called on. - */ - strokeRect: function () { - - this._dirty = true; - this.context.strokeRect(x, y, width, height); - return this; - - }, - - /** - * Color or style to use for the lines around shapes. Default #000 (black). - * @method Phaser.BitmapData.strokeStyle - * @param {string} style - Color or style to use for the lines around shapes. Default #000 (black). - * @return {Phaser.BitmapData} The BitmapData instance this method was called on. - */ - strokeStyle: function (style) { - - this.context.strokeStyle = style; - return this; - - }, - - // strokeText - // transform - // translate - - /** - * If the game is running in WebGL this will push the texture up to the GPU if it's dirty. - * This is called automatically if the BitmapData is being used by a Sprite, otherwise you need to remember to call it in your render function. - * @method Phaser.BitmapData.render - */ - render: function () { - - if (this._dirty) - { - // Only needed if running in WebGL, otherwise this array will never get cleared down - if (this.game.renderType == Phaser.WEBGL) - { - PIXI.texturesToUpdate.push(this.baseTexture); - } - - this._dirty = false; - } - - } + /** + * Adds an arc to the path which is centered at (x, y) position with radius r starting at startAngle and ending at endAngle + * going in the given direction by anticlockwise (defaulting to clockwise). + * @method Phaser.BitmapData.arc + * @param {number} x - The x axis of the coordinate for the arc's center + * @param {number} y - The y axis of the coordinate for the arc's center + * @param {number} radius - The arc's radius + * @param {number} startAngle - The starting point, measured from the x axis, from which it will be drawn, expressed in radians. + * @param {number} endAngle - The end arc's angle to which it will be drawn, expressed in radians. + * @param {boolean} [anticlockwise=true] - true draws the arc anticlockwise, otherwise in a clockwise direction. + * @return {Phaser.BitmapData} The BitmapData instance this method was called on. + */ + arc: function (x, y, radius, startAngle, endAngle, anticlockwise) { + + if (typeof anticlockwise === 'undefined') { anticlockwise = false; } + + this._dirty = true; + this.context.arc(x, y, radius, startAngle, endAngle, anticlockwise); + return this; + + }, + + /** + * Adds an arc with the given control points and radius, connected to the previous point by a straight line. + * @method Phaser.BitmapData.arcTo + * @param {number} x1 + * @param {number} y1 + * @param {number} x2 + * @param {number} y2 + * @param {number} radius + * @return {Phaser.BitmapData} The BitmapData instance this method was called on. + */ + arcTo: function (x1, y1, x2, y2, radius) { + + this._dirty = true; + this.context.arcTo(x1, y1, x2, y2, radius); + return this; + + }, + + /** + * Begins a fill with the specified color. This ends the current sub-path. + * @method Phaser.BitmapData.beginFill + * @param {string} color - A CSS compatible color value (ex. "red", "#FF0000", or "rgba(255,0,0,0.5)"). Setting to null will result in no fill. + * @return {Phaser.BitmapData} The BitmapData instance this method was called on. + */ + beginFill: function (color) { + + this.fillStyle(color); + + return this; + + }, + + /** + * Begins a linear gradient fill defined by the line (x0, y0) to (x1, y1). This ends the current sub-path. For + * example, the following code defines a black to white vertical gradient ranging from 20px to 120px, and draws a square to display it: + * + * ```myGraphics.beginLinearGradientFill(["#000","#FFF"], [0, 1], 0, 20, 0, 120).rect(20, 20, 120, 120);``` + * + * @method Phaser.BitmapData.beginLinearGradientFill + * @param {Array} colors - An array of CSS compatible color values. For example, ["#F00","#00F"] would define a gradient drawing from red to blue. + * @param {Array} ratios - An array of gradient positions which correspond to the colors. For example, [0.1, 0.9] would draw the first color to 10% then interpolating to the second color at 90%. + * @param {number} x0 - The position of the first point defining the line that defines the gradient direction and size. + * @param {number} y0 - The position of the first point defining the line that defines the gradient direction and size. + * @param {number} x1 - The position of the second point defining the line that defines the gradient direction and size. + * @param {number} y1 - The position of the second point defining the line that defines the gradient direction and size. + * @return {Phaser.BitmapData} The BitmapData instance this method was called on. + */ + beginLinearGradientFill: function (colors, ratios, x0, y0, x1, y1) { + + var gradient = this.createLinearGradient(x0, y0, x1, y1); + + for (var i = 0, len = colors.length; i < len; i++) + { + gradient.addColorStop(ratios[i], colors[i]); + } + + this.fillStyle(gradient); + + return this; + + }, + + /** + * Begins a linear gradient stroke defined by the line (x0, y0) to (x1, y1). This ends the current sub-path. For + * example, the following code defines a black to white vertical gradient ranging from 20px to 120px, and draws a + * square to display it: + * + * ```myGraphics.setStrokeStyle(10).beginLinearGradientStroke(["#000","#FFF"], [0, 1], 0, 20, 0, 120).drawRect(20, 20, 120, 120);``` + * + * @method Phaser.BitmapData.beginLinearGradientStroke + * @param {Array} colors - An array of CSS compatible color values. For example, ["#F00","#00F"] would define a gradient drawing from red to blue. + * @param {Array} ratios - An array of gradient positions which correspond to the colors. For example, [0.1, 0.9] would draw the first color to 10% then interpolating to the second color at 90%. + * @param {number} x0 - The position of the first point defining the line that defines the gradient direction and size. + * @param {number} y0 - The position of the first point defining the line that defines the gradient direction and size. + * @param {number} x1 - The position of the second point defining the line that defines the gradient direction and size. + * @param {number} y1 - The position of the second point defining the line that defines the gradient direction and size. + * @return {Phaser.BitmapData} The BitmapData instance this method was called on. + */ + beginLinearGradientStroke: function (colors, ratios, x0, y0, x1, y1) { + + var gradient = this.createLinearGradient(x0, y0, x1, y1); + + for (var i = 0, len = colors.length; i < len; i++) + { + gradient.addColorStop(ratios[i], colors[i]); + } + + this.strokeStyle(gradient); + + return this; + + }, + + /** + * Begins a radial gradient stroke. This ends the current sub-path. For example, the following code defines a red to + * blue radial gradient centered at (100, 100), with a radius of 50, and draws a rectangle to display it: + * + * myGraphics.setStrokeStyle(10) + * .beginRadialGradientStroke(["#F00","#00F"], [0, 1], 100, 100, 0, 100, 100, 50) + * .drawRect(50, 90, 150, 110); + * + * @method Phaser.BitmapData.beginRadialGradientStroke + * @param {Array} colors - An array of CSS compatible color values. For example, ["#F00","#00F"] would define a gradient drawing from red to blue. + * @param {Array} ratios - An array of gradient positions which correspond to the colors. For example, [0.1, 0.9] would draw the first color to 10% then interpolating to the second color at 90%. + * @param {number} x0 - Center position of the inner circle that defines the gradient. + * @param {number} y0 - Center position of the inner circle that defines the gradient. + * @param {number} r0 - Radius of the inner circle that defines the gradient. + * @param {number} x1 - Center position of the outer circle that defines the gradient. + * @param {number} y1 - Center position of the outer circle that defines the gradient. + * @param {number} r1 - Radius of the outer circle that defines the gradient. + * @return {Phaser.BitmapData} The BitmapData instance this method was called on. + */ + beginRadialGradientStroke: function (colors, ratios, x0, y0, r0, x1, y1, r1) { + + var gradient = this.createRadialGradient(x0, y0, r0, x1, y1, r1); + + for (var i = 0, len = colors.length; i < len; i++) + { + gradient.addColorStop(ratios[i], colors[i]); + } + + this.strokeStyle(gradient); + + return this; + + }, + + /** + * Starts a new path by resetting the list of sub-paths. Call this method when you want to create a new path. + * @method Phaser.BitmapData.beginPath + * @return {Phaser.BitmapData} The BitmapData instance this method was called on. + */ + beginPath: function () { + + this.context.beginPath(); + return this; + + }, + + /** + * Begins a stroke with the specified color. This ends the current sub-path. + * @method Phaser.BitmapData.beginStroke + * @param {String} color A CSS compatible color value (ex. "#FF0000", "red", or "rgba(255,0,0,0.5)"). Setting to null will result in no stroke. + * @return {Phaser.BitmapData} The BitmapData instance this method was called on. + */ + beginStroke: function (color) { + + this.strokeStyle(color); + return this; + + }, + + /** + * Adds a bezier curve from the current context point to (x, y) using the control points (cp1x, cp1y) and (cp2x, cp2y). + * @method Phaser.BitmapData.bezierCurveTo + * @param {number} cp1x - The x axis of control point 1. + * @param {number} cp1y - The y axis of control point 1. + * @param {number} cp2x - The x axis of control point 2. + * @param {number} cp2y - The y axis of control point 2. + * @param {number} x - The x axis of the ending point. + * @param {number} y - The y axis of the ending point. + * @return {Phaser.BitmapData} The BitmapData instance this method was called on. + */ + bezierCurveTo: function (cp1x, cp1y, cp2x, cp2y, x, y) { + + this._dirty = true; + this.context.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y); + return this; + + }, + + /** + * Draws a circle with the specified radius at (x, y). + * @method Phaser.BitmapData.circle + * @param {number} x - x coordinate center point of circle. + * @param {number} y - y coordinate center point of circle. + * @param {number} radius - Radius of circle in radians. + * @return {Phaser.BitmapData} The BitmapData instance this method was called on. + */ + circle: function (x, y, radius) { + + this.arc(x, y, radius, 0, Math.PI*2); + return this; + + }, + + /** + * Sets all pixels in the rectangle defined by starting point (x, y) and size (width, height) to transparent black. + * @method Phaser.BitmapData.clearRect + * @param {number} x - The x axis of the coordinate for the rectangle starting point. + * @param {number} y - The y axis of the coordinate for the rectangle starting point. + * @param {number} width - The rectangles width. + * @param {number} height - The rectangles height. + * @return {Phaser.BitmapData} The BitmapData instance this method was called on. + */ + clearRect: function (x, y, width, height) { + + this._dirty = true; + this.context.clearRect(x, y, width, height); + return this; + + }, + + /** + * Creates a clipping path from the current sub-paths. Everything drawn after clip() is called appears inside the clipping path only. + * @method Phaser.BitmapData.clip + * @return {Phaser.BitmapData} The BitmapData instance this method was called on. + */ + clip: function () { + + this._dirty = true; + this.context.clip(); + return this; + + }, + + /** + * Tries to draw a straight line from the current point to the start. If the shape has already been closed or has only one point, this function does nothing. + * @method Phaser.BitmapData.closePath + * @return {Phaser.BitmapData} The BitmapData instance this method was called on. + */ + closePath: function () { + + this._dirty = true; + this.context.closePath(); + return this; + + }, + + /** + * Creates a linear gradient with defined by an imaginary line which implies the direction of the gradient. + * Once the gradient is created colors can be inserted using the addColorStop method. + * @method Phaser.BitmapData.createLinearGradient + * @param {number} x - The x axis of the coordinate for the gradients starting point. + * @param {number} y - The y axis of the coordinate for the gradients starting point. + * @param {number} width - The width of the gradient. + * @param {number} height - The height of the gradient. + * @return {CanvasGradient} The Linear Gradient. + */ + createLinearGradient: function (x, y, width, height) { + + return this.context.createLinearGradient(x, y, width, height); + + }, + + // createPattern + + /** + * Creates a radial gradient. + * @method Phaser.BitmapData.createRadialGradient + * @param {number} x0 + * @param {number} y0 + * @param {number} r0 + * @param {number} x1 + * @param {number} y1 + * @param {number} r1 + * @return {CanvasGradient} The Radial Gradient. + */ + createRadialGradient: function (x0, y0, r0, x1, y1, r1) { + + return this.context.createRadialGradient(x0, y0, r0, x1, y1, r1); + + }, + + // drawImage + // drawSystemFocusRing (?) + + /** + * Draws an ellipse (oval) with a specified width (w) and height (h). + * @method Phaser.BitmapData.ellipse + * @param {number} x - x coordinate center point of ellipse. + * @param {number} y - y coordinate center point of ellipse. + * @param {number} w - height (horizontal diameter) of ellipse. The horizontal radius will be half of this number. + * @param {number} h - width (vertical diameter) of ellipse. The vertical radius will be half of this number. + * @return {Phaser.BitmapData} The BitmapData instance this method was called on. + */ + ellipse: function (x, y, w, h) { + + var k = 0.5522848; + var ox = (w / 2) * k; + var oy = (h / 2) * k; + var xe = x + w; + var ye = y + h; + var xm = x + w / 2; + var ym = y + h / 2; + + this.moveTo(x, ym); + this.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y); + this.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym); + this.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye); + this.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym); + + return this; + + }, + + /** + * Fills the subpaths with the current fill style. + * @method Phaser.BitmapData.fill + * @return {Phaser.BitmapData} The BitmapData instance this method was called on. + */ + fill: function () { + + this._dirty = true; + this.context.fill(); + return this; + + }, + + /** + * Draws a filled rectangle at (x, y) position whose size is determined by width and height. + * @method Phaser.BitmapData.fillRect + * @param {number} x - The x axis of the coordinate for the rectangle starting point. + * @param {number} y - The y axis of the coordinate for the rectangle starting point. + * @param {number} width - The rectangles width. + * @param {number} height - The rectangles height. + * @return {Phaser.BitmapData} The BitmapData instance this method was called on. + */ + fillRect: function (x, y, width, height) { + + this._dirty = true; + this.context.fillRect(x, y, width, height); + return this; + + }, + + /** + * Sets the fill style. + * @method Phaser.BitmapData.fillStyle + * @param {string} color - The fill color value in CSS format: #RRGGBB or rgba(r,g,b,a) + * @return {Phaser.BitmapData} The BitmapData instance this method was called on. + */ + fillStyle: function (color) { + + this.context.fillStyle = color; + return this; + + }, + + // fillText + + /** + * Sets the font. + * @method Phaser.BitmapData.font + * @param {DOMString} font - The font to be used for any text rendering. Default value 10px sans-serif. + * @return {Phaser.BitmapData} The BitmapData instance this method was called on. + */ + font: function (font) { + + this.context.font = font; + return this; + + }, + + /** + * Alpha value that is applied to shapes and images before they are composited onto the canvas. Default 1.0 (opaque). + * @method Phaser.BitmapData.globalAlpha + * @param {number} alpha - Alpha value that is applied to shapes and images before they are composited onto the canvas. Default 1.0 (opaque). + * @return {Phaser.BitmapData} The BitmapData instance this method was called on. + */ + globalAlpha: function (alpha) { + + this.context.globalAlpha = alpha; + return this; + + }, + + /** + * With globalAlpha applied this sets how shapes and images are drawn onto the existing bitmap. Possible values: source-atop, source-in, source-out, + * source-over (default), destination-atop, destination-in, destination-out, destination-over, lighter, darker, copy and xor. + * @method Phaser.BitmapData.globalCompositeOperation + * @param {DOMString} operation - The composite operation to apply. + * @return {Phaser.BitmapData} The BitmapData instance this method was called on. + */ + globalCompositeOperation: function (operation) { + + this.context.globalCompositeOperation = operation; + return this; + + }, + + /** + * Type of endings on the end of lines. Possible values: butt (default), round, square. + * @method Phaser.BitmapData.lineCap + * @param {DOMString} style - Possible values: butt (default), round, square + * @return {Phaser.BitmapData} The BitmapData instance this method was called on. + */ + lineCap: function (style) { + + this.context.lineCap = style; + return this; + + }, + + /** + * Specifies where to start a dasharray on a line. + * @method Phaser.BitmapData.lineDashOffset + * @param {number} offset - Specifies where to start a dasharray on a line. + * @return {Phaser.BitmapData} The BitmapData instance this method was called on. + */ + lineDashOffset: function (offset) { + + this.context.lineDashOffset = offset; + return this; + + }, + + /** + * Defines the type of corners where two lines meet. Possible values: round, bevel, miter (default) + * @method Phaser.BitmapData.lineJoin + * @param {DOMString} join - Possible values: round, bevel, miter (default) + * @return {Phaser.BitmapData} The BitmapData instance this method was called on. + */ + lineJoin: function (join) { + + this.context.lineJoin = join; + return this; + + }, + + /** + * Width of lines. Default 1.0 + * @method Phaser.BitmapData.lineWidth + * @param {number} width - Width of lines. Default 1.0 + * @return {Phaser.BitmapData} The BitmapData instance this method was called on. + */ + lineWidth: function (width) { + + this.context.lineWidth = width; + return this; + + }, + + /** + * Default 10. + * @method Phaser.BitmapData.miterLimit + * @param {number} limit - Default 10. + * @return {Phaser.BitmapData} The BitmapData instance this method was called on. + */ + miterLimit: function (limit) { + + this.context.miterLimit = limit; + return this; + + }, + + // getImageData + // getLineDash + // isPointInPath + // isPointInStroke + + /** + * Connects the last point in the subpath to the x, y coordinates with a straight line. + * @method Phaser.BitmapData.lineTo + * @param {number} x - The x axis of the coordinate for the end of the line. + * @param {number} y - The y axis of the coordinate for the end of the line. + * @return {Phaser.BitmapData} The BitmapData instance this method was called on. + */ + lineTo: function (x, y) { + + this._dirty = true; + this.context.lineTo(x, y); + return this; + + }, + + // measureText + + /** + * Moves the starting point of a new subpath to the (x, y) coordinates. + * @method Phaser.BitmapData.moveTo + * @param {number} x - The x axis of the point. + * @param {number} y - The y axis of the point. + * @return {Phaser.BitmapData} The BitmapData instance this method was called on. + */ + moveTo: function (x, y) { + + this.context.moveTo(x, y); + return this; + + }, + + // putImageData + + /** + * Draws a quadratic curve from the current drawing point to (x, y) using the control point (cpx, cpy). + * @method Phaser.BitmapData.quadraticCurveTo + * @param {Number} cpx - The x axis of the control point. + * @param {Number} cpy - The y axis of the control point. + * @param {Number} x - The x axis of the ending point. + * @param {Number} y - The y axis of the ending point. + * @return {Phaser.BitmapData} The BitmapData instance this method was called on. + */ + quadraticCurveTo: function(cpx, cpy, x, y) { + + this._dirty = true; + this.context.quadraticCurveTo(cpx, cpy, x, y); + return this; + + }, + + /** + * Draws a rectangle at (x, y) position whose size is determined by width and height. + * @method Phaser.BitmapData.rect + * @param {number} x - The x axis of the coordinate for the rectangle starting point. + * @param {number} y - The y axis of the coordinate for the rectangle starting point. + * @param {number} width - The rectangles width. + * @param {number} height - The rectangles height. + * @return {Phaser.BitmapData} The BitmapData instance this method was called on. + */ + rect: function (x, y, width, height) { + + this._dirty = true; + this.context.rect(x, y, width, height); + return this; + + }, + + /** + * Restores the drawing style state to the last element on the 'state stack' saved by save(). + * @method Phaser.BitmapData.restore + * @return {Phaser.BitmapData} The BitmapData instance this method was called on. + */ + restore: function () { + + this._dirty = true; + this.context.restore(); + return this; + + }, + + /** + * Rotates the drawing context values by r radians. + * @method Phaser.BitmapData.rotate + * @param {number} angle - The angle of rotation given in radians. + * @return {Phaser.BitmapData} The BitmapData instance this method was called on. + */ + rotate: function (angle) { + + this._dirty = true; + this.context.rotate(angle); + return this; + + }, + + /** + * Sets the stroke style for the current sub-path. Like all drawing methods, this can be chained, so you can define + * the stroke style and color in a single line of code like so: + * + * ```myGraphics.setStrokeStyle(8,"round").beginStroke("#F00");``` + * + * @method Phaser.BitmapData.setStrokeStyle + * @param {number} thickness - The width of the stroke. + * @param {string|number} [caps=0] - Indicates the type of caps to use at the end of lines. One of butt, round, or square. Defaults to "butt". Also accepts the values 0 (butt), 1 (round), and 2 (square) for use with he tiny API. + * @param {string|number} [joints=0] Specifies the type of joints that should be used where two lines meet. One of bevel, round, or miter. Defaults to "miter". Also accepts the values 0 (miter), 1 (round), and 2 (bevel) for use with the tiny API. + * @param {number} [miterLimit=10] - If joints is set to "miter", then you can specify a miter limit ratio which controls at what point a mitered joint will be clipped. + * @param {boolean} [ignoreScale=false] - If true, the stroke will be drawn at the specified thickness regardless of active transformations. + * @return {Phaser.BitmapData} The BitmapData instance this method was called on. + */ + setStrokeStyle: function (thickness, caps, joints, miterLimit, ignoreScale) { + + if (typeof thickness === 'undefined') { thickness = 1; } + if (typeof caps === 'undefined') { caps = 'butt'; } + if (typeof joints === 'undefined') { joints = 'miter'; } + if (typeof miterLimit === 'undefined') { miterLimit = 10; } + + // TODO + ignoreScale = false; + + this.lineWidth(thickness); + this.lineCap(caps); + this.lineJoin(joints); + this.miterLimit(miterLimit); + + return this; + + }, + + /** + * Saves the current drawing style state using a stack so you can revert any change you make to it using restore(). + * @method Phaser.BitmapData.save + * @return {Phaser.BitmapData} The BitmapData instance this method was called on. + */ + save: function () { + + this._dirty = true; + this.context.save(); + return this; + + }, + + /** + * Scales the current drawing context. + * @method Phaser.BitmapData.scale + * @param {number} x + * @param {number} y + * @return {Phaser.BitmapData} The BitmapData instance this method was called on. + */ + scale: function (x, y) { + + this._dirty = true; + this.context.scale(x, y); + return this; + + }, + + /** + * + * @method Phaser.BitmapData.scrollPathIntoView + * @return {Phaser.BitmapData} The BitmapData instance this method was called on. + */ + scrollPathIntoView: function () { + + this._dirty = true; + this.context.scrollPathIntoView(); + return this; + + }, + + // setLineDash + // setTransform + + /** + * Strokes the subpaths with the current stroke style. + * @method Phaser.BitmapData.stroke + * @return {Phaser.BitmapData} The BitmapData instance this method was called on. + */ + stroke: function () { + + this._dirty = true; + this.context.stroke(); + return this; + + }, + + /** + * Paints a rectangle which has a starting point at (x, y) and has a w width and an h height onto the canvas, using the current stroke style. + * @method Phaser.BitmapData.strokeRect + * @param {number} x - The x axis for the starting point of the rectangle. + * @param {number} y - The y axis for the starting point of the rectangle. + * @param {number} width - The rectangles width. + * @param {number} height - The rectangles height. + * @return {Phaser.BitmapData} The BitmapData instance this method was called on. + */ + strokeRect: function (x, y, width, height) { + + this._dirty = true; + this.context.strokeRect(x, y, width, height); + return this; + + }, + + /** + * Color or style to use for the lines around shapes. Default #000 (black). + * @method Phaser.BitmapData.strokeStyle + * @param {string} style - Color or style to use for the lines around shapes. Default #000 (black). + * @return {Phaser.BitmapData} The BitmapData instance this method was called on. + */ + strokeStyle: function (style) { + + this.context.strokeStyle = style; + return this; + + }, + + // strokeText + // transform + // translate + + /** + * If the game is running in WebGL this will push the texture up to the GPU if it's dirty. + * This is called automatically if the BitmapData is being used by a Sprite, otherwise you need to remember to call it in your render function. + * @method Phaser.BitmapData.render + */ + render: function () { + + if (this._dirty) + { + // Only needed if running in WebGL, otherwise this array will never get cleared down + if (this.game.renderType == Phaser.WEBGL) + { + PIXI.texturesToUpdate.push(this.baseTexture); + } + + this._dirty = false; + } + + } } -// EaselJS Tiny API emulation +// EaselJS Tiny API emulation /** * Shortcut to moveTo. @@ -973,13 +977,13 @@ Phaser.BitmapData.prototype.at = Phaser.BitmapData.prototype.arcTo; * @method Phaser.BitmapData.prototype.bt */ Phaser.BitmapData.prototype.bt = Phaser.BitmapData.prototype.bezierCurveTo; - + /** * Shortcut to quadraticCurveTo. * @method Phaser.BitmapData.prototype.qt */ Phaser.BitmapData.prototype.qt = Phaser.BitmapData.prototype.quadraticCurveTo; - + /** * Shortcut to arc. * @method Phaser.BitmapData.prototype.a @@ -991,7 +995,7 @@ Phaser.BitmapData.prototype.a = Phaser.BitmapData.prototype.arc; * @method Phaser.BitmapData.prototype.r */ Phaser.BitmapData.prototype.r = Phaser.BitmapData.prototype.rect; - + /** * Shortcut to closePath. * @method Phaser.BitmapData.prototype.cp @@ -1003,7 +1007,7 @@ Phaser.BitmapData.prototype.cp = Phaser.BitmapData.prototype.closePath; * @method Phaser.BitmapData.prototype.c */ Phaser.BitmapData.prototype.c = Phaser.BitmapData.prototype.clear; - + /** * Shortcut to beginFill. * @method Phaser.BitmapData.prototype.f @@ -1015,19 +1019,19 @@ Phaser.BitmapData.prototype.f = Phaser.BitmapData.prototype.beginFill; * @method Phaser.BitmapData.prototype.lf */ Phaser.BitmapData.prototype.lf = Phaser.BitmapData.prototype.beginLinearGradientFill; - + /** * Shortcut to beginRadialGradientFill. * @method Phaser.BitmapData.prototype.rf */ Phaser.BitmapData.prototype.rf = Phaser.BitmapData.prototype.beginRadialGradientFill; - + /** * Shortcut to beginBitmapFill. * @method Phaser.BitmapData.prototype.bf */ //Phaser.BitmapData.prototype.bf = Phaser.BitmapData.prototype.beginBitmapFill; - + /** * Shortcut to endFill. * @method Phaser.BitmapData.prototype.ef @@ -1039,13 +1043,13 @@ Phaser.BitmapData.prototype.ef = Phaser.BitmapData.prototype.endFill; * @method Phaser.BitmapData.prototype.ss */ Phaser.BitmapData.prototype.ss = Phaser.BitmapData.prototype.setStrokeStyle; - + /** * Shortcut to beginStroke. * @method Phaser.BitmapData.prototype.s */ Phaser.BitmapData.prototype.s = Phaser.BitmapData.prototype.beginStroke; - + /** * Shortcut to beginLinearGradientStroke. * @method Phaser.BitmapData.prototype.ls @@ -1057,31 +1061,31 @@ Phaser.BitmapData.prototype.ls = Phaser.BitmapData.prototype.beginLinearGradient * @method Phaser.BitmapData.prototype.rs */ Phaser.BitmapData.prototype.rs = Phaser.BitmapData.prototype.beginRadialGradientStroke; - + /** * Shortcut to beginBitmapStroke. * @method Phaser.BitmapData.prototype.bs */ // Phaser.BitmapData.prototype.bs = Phaser.BitmapData.prototype.beginBitmapStroke; - + /** * Shortcut to endStroke. * @method Phaser.BitmapData.prototype.es */ // Phaser.BitmapData.prototype.es = Phaser.BitmapData.prototype.endStroke; - + /** * Shortcut to rect. * @method Phaser.BitmapData.prototype.dr */ Phaser.BitmapData.prototype.dr = Phaser.BitmapData.prototype.rect; - + /** * Shortcut to drawRoundRect. * @method Phaser.BitmapData.prototype.rr */ // Phaser.BitmapData.prototype.rr = Phaser.BitmapData.prototype.drawRoundRect; - + /** * Shortcut to drawRoundRectComplex. * @method Phaser.BitmapData.prototype.rc @@ -1093,13 +1097,13 @@ Phaser.BitmapData.prototype.dr = Phaser.BitmapData.prototype.rect; * @method Phaser.BitmapData.prototype.dc */ Phaser.BitmapData.prototype.dc = Phaser.BitmapData.prototype.circle; - + /** * Shortcut to drawEllipse. * @method Phaser.BitmapData.prototype.de */ Phaser.BitmapData.prototype.de = Phaser.BitmapData.prototype.ellipse; - + /** * Shortcut to drawPolyStar. * @method Phaser.BitmapData.prototype.dp diff --git a/src/gameobjects/BitmapText.js b/src/gameobjects/BitmapText.js index a6bcc596..831e1aa3 100644 --- a/src/gameobjects/BitmapText.js +++ b/src/gameobjects/BitmapText.js @@ -25,28 +25,28 @@ Phaser.BitmapText = function (game, x, y, text, style) { text = text || ''; style = style || ''; - /** - * @property {boolean} exists - If exists = false then the Sprite isn't updated by the core game loop or physics subsystem at all. - * @default - */ + /** + * @property {boolean} exists - If exists = false then the Sprite isn't updated by the core game loop or physics subsystem at all. + * @default + */ this.exists = true; - /** + /** * @property {boolean} 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 - */ + * @default + */ this.alive = true; - /** + /** * @property {Description} group - Description. - * @default - */ + * @default + */ this.group = null; - /** + /** * @property {string} name - Description. - * @default - */ + * @default + */ this.name = ''; /** @@ -61,54 +61,62 @@ Phaser.BitmapText = function (game, x, y, text, style) { */ this.type = Phaser.BITMAPTEXT; - /** - * @property {number} position.x - Description. - */ + /** + * @property {number} position.x - Description. + */ this.position.x = x; - /** - * @property {number} position.y - Description. - */ + /** + * @property {number} position.y - Description. + */ this.position.y = y; // Replaces the PIXI.Point with a slightly more flexible one - /** - * @property {Phaser.Point} anchor - Description. - */ + /** + * @property {Phaser.Point} anchor - Description. + */ this.anchor = new Phaser.Point(); - /** - * @property {Phaser.Point} scale - Description. - */ + /** + * @property {Phaser.Point} scale - Description. + */ this.scale = new Phaser.Point(1, 1); // A mini cache for storing all of the calculated values - /** - * @property {function} _cache - Description. - * @private - */ - this._cache = { + /** + * @property {function} _cache - Description. + * @private + */ + this._cache = { dirty: false, // Transform cache - a00: 1, a01: 0, a02: x, a10: 0, a11: 1, a12: y, id: 1, + a00: 1, + a01: 0, + a02: x, + a10: 0, + a11: 1, + a12: y, + id: 1, // The previous calculated position - x: -1, y: -1, + x: -1, + y: -1, // The actual scale values based on the worldTransform - scaleX: 1, scaleY: 1 + scaleX: 1, + scaleY: 1 }; this._cache.x = this.x; this._cache.y = this.y; - /** - * @property {boolean} renderable - Description. - * @private - */ + /** + * @property {boolean} renderable - Description. + * @private + */ this.renderable = true; }; diff --git a/src/gameobjects/Button.js b/src/gameobjects/Button.js index 77ad8b1d..7abff94d 100644 --- a/src/gameobjects/Button.js +++ b/src/gameobjects/Button.js @@ -33,67 +33,67 @@ Phaser.Button = function (game, x, y, key, callback, callbackContext, overFrame, callback = callback || null; callbackContext = callbackContext || this; - Phaser.Sprite.call(this, game, x, y, key, outFrame); + Phaser.Sprite.call(this, game, x, y, key, outFrame); - /** - * @property {number} type - The Phaser Object Type. - */ + /** + * @property {number} type - The Phaser Object Type. + */ this.type = Phaser.BUTTON; - /** - * @property {string} _onOverFrameName - Internal variable. - * @private - * @default - */ + /** + * @property {string} _onOverFrameName - Internal variable. + * @private + * @default + */ this._onOverFrameName = null; - /** - * @property {string} _onOutFrameName - Internal variable. - * @private - * @default - */ + /** + * @property {string} _onOutFrameName - Internal variable. + * @private + * @default + */ this._onOutFrameName = null; - /** - * @property {string} _onDownFrameName - Internal variable. - * @private - * @default - */ + /** + * @property {string} _onDownFrameName - Internal variable. + * @private + * @default + */ this._onDownFrameName = null; - /** - * @property {string} _onUpFrameName - Internal variable. - * @private - * @default - */ + /** + * @property {string} _onUpFrameName - Internal variable. + * @private + * @default + */ this._onUpFrameName = null; - /** - * @property {number} _onOverFrameID - Internal variable. - * @private - * @default - */ + /** + * @property {number} _onOverFrameID - Internal variable. + * @private + * @default + */ this._onOverFrameID = null; - /** - * @property {number} _onOutFrameID - Internal variable. - * @private - * @default - */ + /** + * @property {number} _onOutFrameID - Internal variable. + * @private + * @default + */ this._onOutFrameID = null; - /** - * @property {number} _onDownFrameID - Internal variable. - * @private - * @default - */ + /** + * @property {number} _onDownFrameID - Internal variable. + * @private + * @default + */ this._onDownFrameID = null; - /** - * @property {number} _onUpFrameID - Internal variable. - * @private - * @default - */ + /** + * @property {number} _onUpFrameID - Internal variable. + * @private + * @default + */ this._onUpFrameID = null; /** @@ -144,25 +144,25 @@ Phaser.Button = function (game, x, y, key, callback, callbackContext, overFrame, */ this.onUpSoundMarker = ''; - /** - * @property {Phaser.Signal} onInputOver - The Signal (or event) dispatched when this Button is in an Over state. - */ - this.onInputOver = new Phaser.Signal; + /** + * @property {Phaser.Signal} onInputOver - The Signal (or event) dispatched when this Button is in an Over state. + */ + this.onInputOver = new Phaser.Signal(); - /** - * @property {Phaser.Signal} onInputOut - The Signal (or event) dispatched when this Button is in an Out state. - */ - this.onInputOut = new Phaser.Signal; + /** + * @property {Phaser.Signal} onInputOut - The Signal (or event) dispatched when this Button is in an Out state. + */ + this.onInputOut = new Phaser.Signal(); - /** - * @property {Phaser.Signal} onInputDown - The Signal (or event) dispatched when this Button is in an Down state. - */ - this.onInputDown = new Phaser.Signal; + /** + * @property {Phaser.Signal} onInputDown - The Signal (or event) dispatched when this Button is in an Down state. + */ + this.onInputDown = new Phaser.Signal(); - /** - * @property {Phaser.Signal} onInputUp - The Signal (or event) dispatched when this Button is in an Up state. - */ - this.onInputUp = new Phaser.Signal; + /** + * @property {Phaser.Signal} onInputUp - The Signal (or event) dispatched when this Button is in an Up state. + */ + this.onInputUp = new Phaser.Signal(); /** * @property {boolean} freezeFrames - When true the Button will cease to change texture frame on all events (over, out, up, down). @@ -237,7 +237,7 @@ Phaser.Button.prototype.setFrames = function (overFrame, outFrame, downFrame) { this._onOutFrameName = outFrame; this._onUpFrameName = outFrame; - if (this.input.pointerOver() == false) + if (this.input.pointerOver() === false) { this.frameName = outFrame; } @@ -247,7 +247,7 @@ Phaser.Button.prototype.setFrames = function (overFrame, outFrame, downFrame) { this._onOutFrameID = outFrame; this._onUpFrameID = outFrame; - if (this.input.pointerOver() == false) + if (this.input.pointerOver() === false) { this.frame = outFrame; } @@ -407,7 +407,7 @@ Phaser.Button.prototype.setDownSound = function (sound, marker) { */ Phaser.Button.prototype.onInputOverHandler = function (pointer) { - if (this.freezeFrames == false) + if (this.freezeFrames === false) { if (this._onOverFrameName != null) { @@ -439,7 +439,7 @@ Phaser.Button.prototype.onInputOverHandler = function (pointer) { */ Phaser.Button.prototype.onInputOutHandler = function (pointer) { - if (this.freezeFrames == false) + if (this.freezeFrames === false) { if (this._onOutFrameName != null) { @@ -471,7 +471,7 @@ Phaser.Button.prototype.onInputOutHandler = function (pointer) { */ Phaser.Button.prototype.onInputDownHandler = function (pointer) { - if (this.freezeFrames == false) + if (this.freezeFrames === false) { if (this._onDownFrameName != null) { @@ -503,7 +503,7 @@ Phaser.Button.prototype.onInputDownHandler = function (pointer) { */ Phaser.Button.prototype.onInputUpHandler = function (pointer) { - if (this.freezeFrames == false) + if (this.freezeFrames === false) { if (this._onUpFrameName != null) { @@ -520,7 +520,7 @@ Phaser.Button.prototype.onInputUpHandler = function (pointer) { this.onUpSound.play(this.onUpSoundMarker); } - if (this.forceOut && this.freezeFrames == false) + if (this.forceOut && this.freezeFrames === false) { if (this._onOutFrameName != null) { diff --git a/src/gameobjects/Events.js b/src/gameobjects/Events.js index 73fe1abd..fb5cc1f8 100644 --- a/src/gameobjects/Events.js +++ b/src/gameobjects/Events.js @@ -4,7 +4,6 @@ * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */ - /** * The Events component is a collection of events fired by the parent game object and its components. * @@ -14,13 +13,13 @@ * @param {Phaser.Sprite} sprite - A reference to Description. */ Phaser.Events = function (sprite) { - - this.parent = sprite; - this.onAddedToGroup = new Phaser.Signal; - this.onRemovedFromGroup = new Phaser.Signal; - this.onKilled = new Phaser.Signal; - this.onRevived = new Phaser.Signal; - this.onOutOfBounds = new Phaser.Signal; + + this.parent = sprite; + this.onAddedToGroup = new Phaser.Signal(); + this.onRemovedFromGroup = new Phaser.Signal(); + this.onKilled = new Phaser.Signal(); + this.onRevived = new Phaser.Signal(); + this.onOutOfBounds = new Phaser.Signal(); this.onInputOver = null; this.onInputOut = null; @@ -29,40 +28,40 @@ Phaser.Events = function (sprite) { this.onDragStart = null; this.onDragStop = null; - this.onAnimationStart = null; - this.onAnimationComplete = null; - this.onAnimationLoop = null; + this.onAnimationStart = null; + this.onAnimationComplete = null; + this.onAnimationLoop = null; }; Phaser.Events.prototype = { - destroy: function () { + destroy: function () { - this.parent = null; - this.onAddedToGroup.dispose(); - this.onRemovedFromGroup.dispose(); - this.onKilled.dispose(); - this.onRevived.dispose(); - this.onOutOfBounds.dispose(); + this.parent = null; + this.onAddedToGroup.dispose(); + this.onRemovedFromGroup.dispose(); + this.onKilled.dispose(); + this.onRevived.dispose(); + this.onOutOfBounds.dispose(); - if (this.onInputOver) - { - this.onInputOver.dispose(); - this.onInputOut.dispose(); - this.onInputDown.dispose(); - this.onInputUp.dispose(); - this.onDragStart.dispose(); - this.onDragStop.dispose(); - } + if (this.onInputOver) + { + this.onInputOver.dispose(); + this.onInputOut.dispose(); + this.onInputDown.dispose(); + this.onInputUp.dispose(); + this.onDragStart.dispose(); + this.onDragStop.dispose(); + } - if (this.onAnimationStart) - { - this.onAnimationStart.dispose(); - this.onAnimationComplete.dispose(); - this.onAnimationLoop.dispose(); - } + if (this.onAnimationStart) + { + this.onAnimationStart.dispose(); + this.onAnimationComplete.dispose(); + this.onAnimationLoop.dispose(); + } - } + } }; \ No newline at end of file diff --git a/src/gameobjects/GameObjectFactory.js b/src/gameobjects/GameObjectFactory.js index baabe344..85ea5289 100644 --- a/src/gameobjects/GameObjectFactory.js +++ b/src/gameobjects/GameObjectFactory.js @@ -14,14 +14,14 @@ Phaser.GameObjectFactory = function (game) { /** - * @property {Phaser.Game} game - A reference to the currently running Game. - */ - this.game = game; - + * @property {Phaser.Game} game - A reference to the currently running Game. + */ + this.game = game; + /** - * @property {Phaser.World} world - A reference to the game world. - */ - this.world = this.game.world; + * @property {Phaser.World} world - A reference to the game world. + */ + this.world = this.game.world; }; @@ -39,7 +39,7 @@ Phaser.GameObjectFactory.prototype = { }, - /** + /** * Create a new Sprite with specific position and sprite sheet key. * * @method Phaser.GameObjectFactory#sprite diff --git a/src/gameobjects/Graphics.js b/src/gameobjects/Graphics.js index 98bb2b9a..fc8932fb 100644 --- a/src/gameobjects/Graphics.js +++ b/src/gameobjects/Graphics.js @@ -5,7 +5,7 @@ */ /** -* Creates a new Graphics object. +* Creates a new `Graphics` object. * * @class Phaser.Graphics * @constructor @@ -21,22 +21,20 @@ Phaser.Graphics = function (game, x, y) { PIXI.Graphics.call(this); /** - * @property {Description} type - Description. + * @property {number} type - The Phaser Object Type. */ this.type = Phaser.GRAPHICS; this.position.x = x; - this.position.y = y; + this.position.y = y; }; Phaser.Graphics.prototype = Object.create(PIXI.Graphics.prototype); Phaser.Graphics.prototype.constructor = Phaser.Graphics; -// Add our own custom methods - /** -* Description. +* Destroy this Graphics instance. * * @method Phaser.Sprite.prototype.destroy */ @@ -58,14 +56,14 @@ Phaser.Graphics.prototype.destroy = function() { */ Phaser.Graphics.prototype.drawPolygon = function (poly) { - graphics.moveTo(poly.points[0].x, poly.points[0].y); + this.moveTo(poly.points[0].x, poly.points[0].y); for (var i = 1; i < poly.points.length; i += 1) { - graphics.lineTo(poly.points[i].x, poly.points[i].y); + this.lineTo(poly.points[i].x, poly.points[i].y); } - graphics.lineTo(poly.points[0].x, poly.points[0].y); + this.lineTo(poly.points[0].x, poly.points[0].y); } diff --git a/src/gameobjects/RenderTexture.js b/src/gameobjects/RenderTexture.js index 7b7aa34c..4ab01752 100644 --- a/src/gameobjects/RenderTexture.js +++ b/src/gameobjects/RenderTexture.js @@ -15,54 +15,54 @@ */ Phaser.RenderTexture = function (game, key, width, height) { - /** - * @property {Phaser.Game} game - A reference to the currently running game. - */ - this.game = game; + /** + * @property {Phaser.Game} game - A reference to the currently running game. + */ + this.game = game; - /** + /** * @property {string} name - the name of the object. - */ + */ this.name = key; - PIXI.EventTarget.call(this); + PIXI.EventTarget.call(this); - /** - * @property {number} width - the width. + /** + * @property {number} width - the width. */ - this.width = width || 100; - - /** - * @property {number} height - the height. + this.width = width || 100; + + /** + * @property {number} height - the height. */ - this.height = height || 100; + this.height = height || 100; - /** + /** * @property {PIXI.mat3} indetityMatrix - Matrix object. - */ - this.indetityMatrix = PIXI.mat3.create(); - - /** - * @property {PIXI.Rectangle} frame - The frame for this texture. */ - this.frame = new PIXI.Rectangle(0, 0, this.width, this.height); + this.indetityMatrix = PIXI.mat3.create(); - /** - * @property {number} type - Base Phaser object type. + /** + * @property {PIXI.Rectangle} frame - The frame for this texture. */ - this.type = Phaser.RENDERTEXTURE; + this.frame = new PIXI.Rectangle(0, 0, this.width, this.height); - this._tempPoint = { x: 0, y: 0 }; + /** + * @property {number} type - Base Phaser object type. + */ + this.type = Phaser.RENDERTEXTURE; - if (PIXI.gl) - { - this.initWebGL(); - } - else - { - this.initCanvas(); - } - + this._tempPoint = { x: 0, y: 0 }; + + if (PIXI.gl) + { + this.initWebGL(); + } + else + { + this.initCanvas(); + } + }; Phaser.RenderTexture.prototype = Object.create(PIXI.Texture.prototype); @@ -79,22 +79,22 @@ Phaser.RenderTexture.prototype.constructor = PIXI.RenderTexture; */ Phaser.RenderTexture.prototype.render = function(displayObject, position, clear) { - if (typeof position === 'undefined') { position = false; } - if (typeof clear === 'undefined') { clear = false; } + if (typeof position === 'undefined') { position = false; } + if (typeof clear === 'undefined') { clear = false; } - if (displayObject instanceof Phaser.Group) - { - displayObject = displayObject._container; - } + if (displayObject instanceof Phaser.Group) + { + displayObject = displayObject._container; + } - if (PIXI.gl) - { - this.renderWebGL(displayObject, position, clear); - } - else - { - this.renderCanvas(displayObject, position, clear); - } + if (PIXI.gl) + { + this.renderWebGL(displayObject, position, clear); + } + else + { + this.renderCanvas(displayObject, position, clear); + } } @@ -110,10 +110,10 @@ Phaser.RenderTexture.prototype.render = function(displayObject, position, clear) */ Phaser.RenderTexture.prototype.renderXY = function(displayObject, x, y, clear) { - this._tempPoint.x = x; - this._tempPoint.y = y; + this._tempPoint.x = x; + this._tempPoint.y = y; - this.render(displayObject, this._tempPoint, clear); + this.render(displayObject, this._tempPoint, clear); } @@ -125,64 +125,64 @@ Phaser.RenderTexture.prototype.renderXY = function(displayObject, x, y, clear) { */ Phaser.RenderTexture.prototype.initWebGL = function() { - var gl = PIXI.gl; - this.glFramebuffer = gl.createFramebuffer(); + var gl = PIXI.gl; + this.glFramebuffer = gl.createFramebuffer(); - gl.bindFramebuffer(gl.FRAMEBUFFER, this.glFramebuffer ); + gl.bindFramebuffer(gl.FRAMEBUFFER, this.glFramebuffer ); this.glFramebuffer.width = this.width; - this.glFramebuffer.height = this.height; + this.glFramebuffer.height = this.height; - this.baseTexture = new PIXI.BaseTexture(); + this.baseTexture = new PIXI.BaseTexture(); - this.baseTexture.width = this.width; - this.baseTexture.height = this.height; + this.baseTexture.width = this.width; + this.baseTexture.height = this.height; this.baseTexture._glTexture = gl.createTexture(); gl.bindTexture(gl.TEXTURE_2D, this.baseTexture._glTexture); - gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, this.width, this.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); + gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, this.width, this.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); - gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); - this.baseTexture.isRender = true; + this.baseTexture.isRender = true; - gl.bindFramebuffer(gl.FRAMEBUFFER, this.glFramebuffer ); - gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this.baseTexture._glTexture, 0); + gl.bindFramebuffer(gl.FRAMEBUFFER, this.glFramebuffer ); + gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this.baseTexture._glTexture, 0); - // create a projection matrix.. - this.projection = new PIXI.Point(this.width/2 , -this.height/2); + // create a projection matrix.. + this.projection = new PIXI.Point(this.width/2 , -this.height/2); - // set the correct render function.. - // this.render = this.renderWebGL; + // set the correct render function.. + // this.render = this.renderWebGL; } Phaser.RenderTexture.prototype.resize = function(width, height) { - this.width = width; - this.height = height; - - if(PIXI.gl) - { - this.projection.x = this.width/2 - this.projection.y = -this.height/2; - - var gl = PIXI.gl; - gl.bindTexture(gl.TEXTURE_2D, this.baseTexture._glTexture); - gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, this.width, this.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); - } - else - { - - this.frame.width = this.width - this.frame.height = this.height; - this.renderer.resize(this.width, this.height); - } + this.width = width; + this.height = height; + + if(PIXI.gl) + { + this.projection.x = this.width/2 + this.projection.y = -this.height/2; + + var gl = PIXI.gl; + gl.bindTexture(gl.TEXTURE_2D, this.baseTexture._glTexture); + gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, this.width, this.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); + } + else + { + + this.frame.width = this.width + this.frame.height = this.height; + this.renderer.resize(this.width, this.height); + } } /** @@ -193,12 +193,12 @@ Phaser.RenderTexture.prototype.resize = function(width, height) */ Phaser.RenderTexture.prototype.initCanvas = function() { - this.renderer = new PIXI.CanvasRenderer(this.width, this.height, null, 0); + this.renderer = new PIXI.CanvasRenderer(this.width, this.height, null, 0); - this.baseTexture = new PIXI.BaseTexture(this.renderer.view); - this.frame = new PIXI.Rectangle(0, 0, this.width, this.height); + this.baseTexture = new PIXI.BaseTexture(this.renderer.view); + this.frame = new PIXI.Rectangle(0, 0, this.width, this.height); - // this.render = this.renderCanvas; + // this.render = this.renderCanvas; } /** @@ -211,69 +211,72 @@ Phaser.RenderTexture.prototype.initCanvas = function() */ Phaser.RenderTexture.prototype.renderWebGL = function(displayObject, position, clear) { - var gl = PIXI.gl; + var gl = PIXI.gl; - // enable the alpha color mask.. - gl.colorMask(true, true, true, true); + // enable the alpha color mask.. + gl.colorMask(true, true, true, true); - gl.viewport(0, 0, this.width, this.height); + gl.viewport(0, 0, this.width, this.height); - gl.bindFramebuffer(gl.FRAMEBUFFER, this.glFramebuffer ); + gl.bindFramebuffer(gl.FRAMEBUFFER, this.glFramebuffer ); - if(clear) - { - gl.clearColor(0,0,0, 0); - gl.clear(gl.COLOR_BUFFER_BIT); - } + if (clear) + { + gl.clearColor(0,0,0, 0); + gl.clear(gl.COLOR_BUFFER_BIT); + } - // THIS WILL MESS WITH HIT TESTING! - var children = displayObject.children; + // THIS WILL MESS WITH HIT TESTING! + var children = displayObject.children; - //TODO -? create a new one??? dont think so! - var originalWorldTransform = displayObject.worldTransform; - displayObject.worldTransform = PIXI.mat3.create();//sthis.indetityMatrix; - // modify to flip... - displayObject.worldTransform[4] = -1; - displayObject.worldTransform[5] = this.projection.y * -2; + //TODO -? create a new one??? dont think so! + var originalWorldTransform = displayObject.worldTransform; + displayObject.worldTransform = PIXI.mat3.create();//sthis.indetityMatrix; + // modify to flip... + displayObject.worldTransform[4] = -1; + displayObject.worldTransform[5] = this.projection.y * -2; - if(position) - { - displayObject.worldTransform[2] = position.x; - displayObject.worldTransform[5] -= position.y; - } - - PIXI.visibleCount++; - displayObject.vcount = PIXI.visibleCount; - - for(var i=0,j=children.length; iTileSprite. +* A TileSprite is a Sprite whos texture is set to repeat and can be scrolled. As it scrolls the texture repeats (wraps) on the edges. * @class Phaser.Tilemap +* @extends Phaser.Sprite * @constructor * @param {Phaser.Game} game - Current game instance. * @param {number} x - X position of the new tileSprite. @@ -25,33 +26,33 @@ Phaser.TileSprite = function (game, x, y, width, height, key, frame) { key = key || null; frame = frame || null; - Phaser.Sprite.call(this, game, x, y, key, frame); + Phaser.Sprite.call(this, game, x, y, key, frame); - /** - * @property {Description} texture - Description. + /** + * @property {PIXI.Texture} texture - The texture that the sprite renders with. */ this.texture = PIXI.TextureCache[key]; - PIXI.TilingSprite.call(this, this.texture, width, height); + PIXI.TilingSprite.call(this, this.texture, width, height); - /** - * @property {Description} type - Description. + /** + * @property {number} type - The const type of this object. + * @readonly */ - this.type = Phaser.TILESPRITE; + this.type = Phaser.TILESPRITE; - /** - * @property {Point} tileScale - The scaling of the image that is being tiled. - */ - this.tileScale = new Phaser.Point(1, 1); + /** + * @property {Phaser.Point} tileScale - The scaling of the image that is being tiled. + */ + this.tileScale = new Phaser.Point(1, 1); - /** - * @property {Point} tilePosition - The offset position of the image that is being tiled. - */ - this.tilePosition = new Phaser.Point(0, 0); + /** + * @property {Phaser.Point} tilePosition - The offset position of the image that is being tiled. + */ + this.tilePosition = new Phaser.Point(0, 0); }; Phaser.TileSprite.prototype = Phaser.Utils.extend(true, PIXI.TilingSprite.prototype, Phaser.Sprite.prototype); Phaser.TileSprite.prototype.constructor = Phaser.TileSprite; -// Add our own custom methods diff --git a/src/geom/Circle.js b/src/geom/Circle.js index cbb736f1..a1529cd4 100644 --- a/src/geom/Circle.js +++ b/src/geom/Circle.js @@ -13,7 +13,7 @@ * @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) { x = x || 0; @@ -22,26 +22,26 @@ Phaser.Circle = function (x, y, diameter) { /** * @property {number} x - The x coordinate of the center of the circle. - **/ + */ this.x = x; /** * @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 - **/ + /** + * @property {number} _radius - The radius of the circle. + * @private + */ this._radius = diameter * 0.5; } else @@ -57,7 +57,7 @@ Phaser.Circle.prototype = { * The circumference of the circle. * @method Phaser.Circle#circumference * @return {number} - **/ + */ circumference: function () { return 2 * (Math.PI * this._radius); }, @@ -69,7 +69,7 @@ Phaser.Circle.prototype = { * @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; this.y = y; @@ -83,7 +83,7 @@ Phaser.Circle.prototype = { * @method Phaser.Circle#copyFrom * @param {any} source - The object to copy from. * @return {Circle} This Circle object. - **/ + */ copyFrom: function (source) { return this.setTo(source.x, source.y, source.diameter); }, @@ -93,11 +93,11 @@ Phaser.Circle.prototype = { * @method Phaser.Circle#copyTo * @param {any} dest - The object to copy to. * @return {Object} This dest object. - **/ + */ copyTo: function(dest) { - dest[x] = this.x; - dest[y] = this.y; - dest[diameter] = this._diameter; + dest.x = this.x; + dest.y = this.y; + dest.diameter = this._diameter; return dest; }, @@ -134,7 +134,7 @@ Phaser.Circle.prototype = { if (typeof out === "undefined") { out = new Phaser.Circle(); } - return out.setTo(a.x, a.y, a.diameter); + return out.setTo(this.x, this.y, this.diameter); }, @@ -167,7 +167,7 @@ Phaser.Circle.prototype = { * @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) { this.x += dx; this.y += dy; @@ -179,7 +179,7 @@ Phaser.Circle.prototype = { * @method Phaser.Circle#offsetPoint * @param {Point} point A Point object to use to offset this Circle object (or any valid object with exposed x and y properties). * @return {Circle} This Circle object. - **/ + */ offsetPoint: function (point) { return this.offset(point.x, point.y); }, @@ -188,7 +188,7 @@ Phaser.Circle.prototype = { * Returns a string representation of this object. * @method Phaser.Circle#toString * @return {string} a string representation of the instance. - **/ + */ toString: function () { return "[{Phaser.Circle (x=" + this.x + " y=" + this.y + " diameter=" + this.diameter + " radius=" + this.radius + ")}]"; } @@ -351,11 +351,16 @@ Object.defineProperty(Phaser.Circle.prototype, "area", { Object.defineProperty(Phaser.Circle.prototype, "empty", { get: function () { - return (this._diameter == 0); + return (this._diameter === 0); }, set: function (value) { - this.setTo(0, 0, 0); + + if (value === true) + { + this.setTo(0, 0, 0); + } + } }); diff --git a/src/geom/Point.js b/src/geom/Point.js index 4e645e42..b03ca287 100644 --- a/src/geom/Point.js +++ b/src/geom/Point.js @@ -11,20 +11,20 @@ * @constructor * @param {number} x The horizontal position of this Point (default 0) * @param {number} y The vertical position of this Point (default 0) -**/ +*/ Phaser.Point = function (x, y) { x = x || 0; y = y || 0; /** - * @property {number} x - The x coordinate of the point. - **/ + * @property {number} x - The x coordinate of the point. + */ this.x = x; /** - * @property {number} y - The y coordinate of the point. - **/ + * @property {number} y - The y coordinate of the point. + */ this.y = y; }; @@ -36,7 +36,7 @@ Phaser.Point.prototype = { * @method Phaser.Point#copyFrom * @param {any} source - The object to copy from. * @return {Point} This Point object. - **/ + */ copyFrom: function (source) { return this.setTo(source.x, source.y); }, @@ -45,7 +45,7 @@ Phaser.Point.prototype = { * Inverts the x and y values of this Point * @method Phaser.Point#invert * @return {Point} This Point object. - **/ + */ invert: function () { return this.setTo(this.y, this.x); }, @@ -56,7 +56,7 @@ Phaser.Point.prototype = { * @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) { this.x = x; @@ -71,7 +71,7 @@ Phaser.Point.prototype = { * @param {number} x - The value to add to Point.x. * @param {number} y - The value to add to Point.y. * @return {Phaser.Point} This Point object. Useful for chaining method calls. - **/ + */ add: function (x, y) { this.x += x; @@ -86,7 +86,7 @@ Phaser.Point.prototype = { * @param {number} x - The value to subtract from Point.x. * @param {number} y - The value to subtract from Point.y. * @return {Phaser.Point} This Point object. Useful for chaining method calls. - **/ + */ subtract: function (x, y) { this.x -= x; @@ -101,7 +101,7 @@ Phaser.Point.prototype = { * @param {number} x - The value to multiply Point.x by. * @param {number} y - The value to multiply Point.x by. * @return {Phaser.Point} This Point object. Useful for chaining method calls. - **/ + */ multiply: function (x, y) { this.x *= x; @@ -116,7 +116,7 @@ Phaser.Point.prototype = { * @param {number} x - The value to divide Point.x by. * @param {number} y - The value to divide Point.x by. * @return {Phaser.Point} This Point object. Useful for chaining method calls. - **/ + */ divide: function (x, y) { this.x /= x; @@ -176,32 +176,22 @@ Phaser.Point.prototype = { */ clone: function (output) { - if (typeof output === "undefined") { output = new Phaser.Point; } + if (typeof output === "undefined") { output = new Phaser.Point(); } return output.setTo(this.x, this.y); }, - /** - * Copies the x and y properties from any given object to this Point. - * @method Phaser.Point#copyFrom - * @param {any} source - The object to copy from. - * @return {Point} This Point object. - **/ - copyFrom: function (source) { - return this.setTo(source.x, source.y); - }, - /** * Copies the x and y properties from this Point to any given object. * @method Phaser.Point#copyTo * @param {any} dest - The object to copy to. * @return {Object} The dest object. - **/ + */ copyTo: function(dest) { - dest[x] = this.x; - dest[y] = this.y; + dest.x = this.x; + dest.y = this.y; return dest; @@ -291,7 +281,7 @@ Phaser.Point.prototype = { * Returns a string representation of this object. * @method Phaser.Point#toString * @return {string} A string representation of the instance. - **/ + */ toString: function () { return '[{Point (x=' + this.x + ' y=' + this.y + ')}]'; } @@ -406,7 +396,7 @@ Phaser.Point.distance = function (a, b, round) { return Phaser.Math.distance(a.x, a.y, b.x, b.y); } -}, +}; /** * Rotates a Point around the x/y coordinates given to the desired angle. diff --git a/src/geom/Polygon.js b/src/geom/Polygon.js index 671c44e5..8bb0b875 100644 --- a/src/geom/Polygon.js +++ b/src/geom/Polygon.js @@ -20,8 +20,8 @@ Phaser.Polygon = function (points) { PIXI.Polygon.call(this, points); /** - * @property {number} type - The base object type. - */ + * @property {number} type - The base object type. + */ this.type = Phaser.POLYGON; }; diff --git a/src/geom/Rectangle.js b/src/geom/Rectangle.js index f851fa03..c27aca20 100644 --- a/src/geom/Rectangle.js +++ b/src/geom/Rectangle.js @@ -11,10 +11,10 @@ * @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. +* @param {number} width - The width of the Rectangle. +* @param {number} height - The height of the Rectangle. * @return {Rectangle} This Rectangle object. -**/ +*/ Phaser.Rectangle = function (x, y, width, height) { x = x || 0; @@ -23,22 +23,22 @@ Phaser.Rectangle = function (x, y, width, height) { height = height || 0; /** - * @property {number} x - Description. + * @property {number} x - The x coordinate of the top-left corner of the Rectangle. */ this.x = x; /** - * @property {number} y - Description. + * @property {number} y - The y coordinate of the top-left corner of the Rectangle. */ this.y = y; /** - * @property {number} width - Description. + * @property {number} width - The width of the Rectangle. */ this.width = width; /** - * @property {number} height - Description. + * @property {number} height - The height of the Rectangle. */ this.height = height; @@ -52,7 +52,7 @@ Phaser.Rectangle.prototype = { * @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) { this.x += dx; @@ -67,7 +67,7 @@ Phaser.Rectangle.prototype = { * @method Phaser.Rectangle#offsetPoint * @param {Point} point - A Point object to use to offset this Rectangle object. * @return {Rectangle} This Rectangle object. - **/ + */ offsetPoint: function (point) { return this.offset(point.x, point.y); }, @@ -80,7 +80,7 @@ Phaser.Rectangle.prototype = { * @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) { this.x = x; @@ -95,7 +95,7 @@ Phaser.Rectangle.prototype = { /** * Runs Math.floor() on both the x and y values of this Rectangle. * @method Phaser.Rectangle#floor - **/ + */ floor: function () { this.x = Math.floor(this.x); @@ -106,7 +106,7 @@ Phaser.Rectangle.prototype = { /** * Runs Math.floor() on the x, y, width and height values of this Rectangle. * @method Phaser.Rectangle#floorAll - **/ + */ floorAll: function () { this.x = Math.floor(this.x); @@ -121,7 +121,7 @@ Phaser.Rectangle.prototype = { * @method Phaser.Rectangle#copyFrom * @param {any} source - The object to copy from. * @return {Rectangle} This Rectangle object. - **/ + */ copyFrom: function (source) { return this.setTo(source.x, source.y, source.width, source.height); }, @@ -131,7 +131,7 @@ Phaser.Rectangle.prototype = { * @method Phaser.Rectangle#copyTo * @param {any} source - The object to copy to. * @return {object} This object. - **/ + */ copyTo: function (dest) { dest.x = this.x; @@ -215,7 +215,7 @@ Phaser.Rectangle.prototype = { * @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) { - return Phaser.Rectangle.intersection(this, b, output); + return Phaser.Rectangle.intersection(this, b, out); }, /** @@ -259,7 +259,7 @@ Phaser.Rectangle.prototype = { * Returns a string representation of this object. * @method Phaser.Rectangle#toString * @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 + ")}]"; } @@ -490,7 +490,12 @@ Object.defineProperty(Phaser.Rectangle.prototype, "empty", { }, set: function (value) { - this.setTo(0, 0, 0, 0); + + if (value === true) + { + this.setTo(0, 0, 0, 0); + } + } }); @@ -615,7 +620,7 @@ Phaser.Rectangle.equals = function (a, b) { */ Phaser.Rectangle.intersection = function (a, b, out) { - out = out || new Phaser.Rectangle; + out = out || new Phaser.Rectangle(); if (Phaser.Rectangle.intersects(a, b)) { diff --git a/src/input/Input.js b/src/input/Input.js index acc9cda9..29f3a283 100644 --- a/src/input/Input.js +++ b/src/input/Input.js @@ -5,32 +5,32 @@ */ /** -* Constructor for Phaser Input. +* Phaser.Input is the Input Manager for all types of Input across Phaser, including mouse, keyboard, touch and MSPointer. +* The Input manager is updated automatically by the core game loop. +* * @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 {Phaser.Game} game - A reference to the currently running game. + */ + this.game = game; - /** - * @property {Description} hitCanvas - Description. + /** + * @property {HTMLCanvasElement} hitCanvas - The canvas to which single pixels are drawn in order to perform pixel-perfect hit detection. * @default - */ + */ this.hitCanvas = null; - /** - * @property {Description} hitContext - Description. - * @default - */ + /** + * @property {CanvasRenderingContext2D} hitContext - The context of the pixel perfect hit canvas. + * @default + */ this.hitContext = null; - + }; /** @@ -53,11 +53,6 @@ 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. @@ -67,31 +62,28 @@ Phaser.Input.prototype = { pollRate: 0, /** - * @property {number} _pollCounter - Description. + * @property {number} _pollCounter - Internal var holding the current poll counter. * @private * @default */ _pollCounter: 0, /** - * A vector object representing the previous position of the Pointer. - * @property {Vec2} vector + * @property {Phaser.Point} _oldPosition - A point object representing the previous position of the Pointer. * @private * @default */ _oldPosition: null, /** - * X coordinate of the most recent Pointer event - * @property {number} _x + * @property {number} _x - x coordinate of the most recent Pointer event * @private * @default */ _x: 0, /** - * Y coordinate of the most recent Pointer event - * @property {number} _y + * @property {number} _y - Y coordinate of the most recent Pointer event * @private * @default */ @@ -112,17 +104,14 @@ Phaser.Input.prototype = { multiInputOverride: Phaser.Input.MOUSE_TOUCH_COMBINE, /** - * A vector object representing the current position of the Pointer. - * @property {Phaser.Point} position + * @property {Phaser.Point} position - A point object representing the current position of the Pointer. * @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. + * A point object representing the speed of the Pointer. Only really useful in single Pointer games, otherwise see the Pointer objects directly. * @property {Phaser.Point} speed - * @default */ speed: null, @@ -130,7 +119,6 @@ Phaser.Input.prototype = { * 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 {Phaser.Circle} circle - * @default */ circle: null, @@ -138,7 +126,6 @@ Phaser.Input.prototype = { * 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. * @property {Phaser.Point} scale - * @default */ scale: null, @@ -267,7 +254,7 @@ Phaser.Input.prototype = { /** * A Pointer object * @property {Phaser.Pointer} pointer9 - */ + */ pointer9: null, /** @@ -353,40 +340,40 @@ Phaser.Input.prototype = { */ interactiveItems: new Phaser.LinkedList(), - /** + /** * Starts the Input Manager running. * @method Phaser.Input#boot * @protected */ boot: function () { - this.mousePointer = new Phaser.Pointer(this.game, 0); - this.pointer1 = new Phaser.Pointer(this.game, 1); - this.pointer2 = new Phaser.Pointer(this.game, 2); + this.mousePointer = new Phaser.Pointer(this.game, 0); + this.pointer1 = new Phaser.Pointer(this.game, 1); + this.pointer2 = new Phaser.Pointer(this.game, 2); - this.mouse = new Phaser.Mouse(this.game); - this.keyboard = new Phaser.Keyboard(this.game); - this.touch = new Phaser.Touch(this.game); - this.mspointer = new Phaser.MSPointer(this.game); + this.mouse = new Phaser.Mouse(this.game); + this.keyboard = new Phaser.Keyboard(this.game); + this.touch = new Phaser.Touch(this.game); + this.mspointer = new Phaser.MSPointer(this.game); - this.onDown = new Phaser.Signal(); - this.onUp = new Phaser.Signal(); - this.onTap = new Phaser.Signal(); - this.onHold = new Phaser.Signal(); + this.onDown = new Phaser.Signal(); + this.onUp = new Phaser.Signal(); + this.onTap = new Phaser.Signal(); + this.onHold = new Phaser.Signal(); - this.scale = new Phaser.Point(1, 1); - this.speed = new Phaser.Point(); - this.position = new Phaser.Point(); - this._oldPosition = new Phaser.Point(); + this.scale = new Phaser.Point(1, 1); + this.speed = new Phaser.Point(); + this.position = new Phaser.Point(); + this._oldPosition = new Phaser.Point(); - this.circle = new Phaser.Circle(0, 0, 44); + this.circle = new Phaser.Circle(0, 0, 44); - this.activePointer = this.mousePointer; - this.currentPointers = 0; + this.activePointer = this.mousePointer; + this.currentPointers = 0; - this.hitCanvas = document.createElement('canvas'); - this.hitCanvas.width = 1; - this.hitCanvas.height = 1; + this.hitCanvas = document.createElement('canvas'); + this.hitCanvas.width = 1; + this.hitCanvas.height = 1; this.hitContext = this.hitCanvas.getContext('2d'); this.mouse.start(); @@ -410,7 +397,7 @@ Phaser.Input.prototype = { }, - /** + /** * Add a new Pointer object to the Input Manager. By default Input creates 3 pointer objects: mousePointer, pointer1 and pointer2. * If you need more then use this to create a new one, up to a maximum of 10. * @method Phaser.Input#addPointer @@ -428,7 +415,7 @@ Phaser.Input.prototype = { } } - if (next == 0) + if (next === 0) { console.warn("You can only have 10 Pointer objects"); return null; @@ -441,7 +428,7 @@ Phaser.Input.prototype = { }, - /** + /** * Updates the Input Manager. Called by the core Game loop. * @method Phaser.Input#update * @protected @@ -475,14 +462,14 @@ Phaser.Input.prototype = { this._pollCounter = 0; }, - /** + /** * Reset all of the Pointers and Input states * @method Phaser.Input#reset * @param {boolean} hard - A soft reset (hard = false) won't reset any Signals that might be bound. A hard reset will. */ reset: function (hard) { - if (this.game.isBooted == false) + if (this.game.isBooted === false) { return; } @@ -503,7 +490,7 @@ Phaser.Input.prototype = { this.currentPointers = 0; this.game.stage.canvas.style.cursor = "default"; - if (hard == true) + if (hard === true) { this.onDown.dispose(); this.onUp.dispose(); @@ -534,7 +521,7 @@ Phaser.Input.prototype = { }, - /** + /** * Find the first free Pointer object and start it, passing in the event data. This is called automatically by Phaser.Touch and Phaser.MSPointer. * @method Phaser.Input#startPointer * @param {Any} event - The event data from the Touch event. @@ -547,11 +534,11 @@ Phaser.Input.prototype = { return null; } - if (this.pointer1.active == false) + if (this.pointer1.active === false) { return this.pointer1.start(event); } - else if (this.pointer2.active == false) + else if (this.pointer2.active === false) { return this.pointer2.start(event); } @@ -559,7 +546,7 @@ Phaser.Input.prototype = { { for (var i = 3; i <= 10; i++) { - if (this['pointer' + i] && this['pointer' + i].active == false) + if (this['pointer' + i] && this['pointer' + i].active === false) { return this['pointer' + i].start(event); } @@ -570,7 +557,7 @@ Phaser.Input.prototype = { }, - /** + /** * Updates the matching Pointer object, passing in the event data. This is called automatically and should not normally need to be invoked. * @method Phaser.Input#updatePointer * @param {Any} event - The event data from the Touch event. @@ -601,7 +588,7 @@ Phaser.Input.prototype = { }, - /** + /** * Stops the matching Pointer object, passing in the event data. * @method Phaser.Input#stopPointer * @param {Any} event - The event data from the Touch event. @@ -632,7 +619,7 @@ Phaser.Input.prototype = { }, - /** + /** * Get the next Pointer object whos active property matches the given state * @method Phaser.Input#getPointer * @param {boolean} state - The state the Pointer should be in (false for inactive, true for active). @@ -665,7 +652,7 @@ Phaser.Input.prototype = { }, - /** + /** * Get the Pointer object whos identified property matches the given identifier value. * @method Phaser.Input#getPointerFromIdentifier * @param {number} identifier - The Pointer.identifier value to search for. @@ -793,7 +780,7 @@ Object.defineProperty(Phaser.Input.prototype, "totalActivePointers", { Object.defineProperty(Phaser.Input.prototype, "worldX", { get: function () { - return this.game.camera.view.x + this.x; + return this.game.camera.view.x + this.x; } }); @@ -806,7 +793,7 @@ Object.defineProperty(Phaser.Input.prototype, "worldX", { Object.defineProperty(Phaser.Input.prototype, "worldY", { get: function () { - return this.game.camera.view.y + this.y; + return this.game.camera.view.y + this.y; } }); diff --git a/src/input/InputHandler.js b/src/input/InputHandler.js index 7b4f89d2..85e411c9 100644 --- a/src/input/InputHandler.js +++ b/src/input/InputHandler.js @@ -5,131 +5,129 @@ */ /** -* Constructor for Phaser InputHandler. +* The Input Handler is bound to a specific Sprite and is responsible for managing all Input events on that Sprite. * @class Phaser.InputHandler -* @classdesc Description. * @constructor -* @param {Phaser.Sprite} game - Description. +* @param {Phaser.Sprite} sprite - The Sprite object to which this Input Handler belongs. */ Phaser.InputHandler = function (sprite) { - /** - * @property {Phaser.Sprite} sprite - Description. - */ - this.sprite = sprite; + /** + * @property {Phaser.Sprite} sprite - The Sprite object to which this Input Handler belongs. + */ + this.sprite = sprite; /** * @property {Phaser.Game} game - A reference to the currently running game. */ this.game = sprite.game; - /** - * @property {boolean} enabled - Description. - * @default - */ + /** + * @property {boolean} enabled - If enabled the Input Handler will process input requests and monitor pointer activity. + * @default + */ this.enabled = false; - // Linked list references - /** - * @property {Description} parent - Description. - * @default - */ - this.parent = null; + /** + * @property {Description} parent - Description. + * @default + */ + // this.parent = null; - /** - * @property {Description} next - Description. - * @default - */ - this.next = null; + /** + * @property {Description} next - Linked List + * @default + */ + // this.next = null; - /** - * @property {Description} prev - Description. - * @default - */ - this.prev = 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; + /** + * @property {Description} last - Description. + * @default + */ + // this.last = this; + + /** + * @property {Description} first - Description. + * @default + */ + // this.first = this; - /** - * @property {number} priorityID - The PriorityID controls which Sprite receives an Input event first if they should overlap. - * @default - */ + /** + * @property {number} priorityID - The PriorityID controls which Sprite receives an Input event first if they should overlap. + * @default + */ this.priorityID = 0; - /** - * @property {boolean} useHandCursor - Description. - * @default - */ + /** + * @property {boolean} useHandCursor - On a desktop browser you can set the 'hand' cursor to appear when moving over the Sprite. + * @default + */ this.useHandCursor = false; - - /** - * @property {boolean} isDragged - Description. - * @default - */ + + /** + * @property {boolean} isDragged - true if the Sprite is being currently dragged. + * @default + */ this.isDragged = false; - /** - * @property {boolean} allowHorizontalDrag - Description. - * @default - */ + /** + * @property {boolean} allowHorizontalDrag - Controls if the Sprite is allowed to be dragged horizontally. + * @default + */ this.allowHorizontalDrag = true; - /** - * @property {boolean} allowVerticalDrag - Description. - * @default - */ + /** + * @property {boolean} allowVerticalDrag - Controls if the Sprite is allowed to be dragged vertically. + * @default + */ this.allowVerticalDrag = true; - /** - * @property {boolean} bringToTop - Description. - * @default - */ + /** + * @property {boolean} bringToTop - If true when this Sprite is clicked or dragged it will automatically be bought to the top of the Group it is within. + * @default + */ this.bringToTop = false; - /** - * @property {Description} snapOffset - Description. - * @default - */ + /** + * @property {Phaser.Point} snapOffset - A Point object that contains by how far the Sprite snap is offset. + * @default + */ this.snapOffset = null; - /** - * @property {boolean} snapOnDrag - Description. - * @default - */ + /** + * @property {boolean} snapOnDrag - When the Sprite is dragged this controls if the center of the Sprite will snap to the pointer on drag or not. + * @default + */ this.snapOnDrag = false; - /** - * @property {boolean} snapOnRelease - Description. - * @default - */ + /** + * @property {boolean} snapOnRelease - When the Sprite is dragged this controls if the Sprite will be snapped on release. + * @default + */ this.snapOnRelease = false; - /** - * @property {number} snapX - Description. - * @default - */ + /** + * @property {number} snapX - When a Sprite has snapping enabled this holds the width of the snap grid. + * @default + */ this.snapX = 0; - /** - * @property {number} snapY - Description. - * @default - */ + /** + * @property {number} snapY - When a Sprite has snapping enabled this holds the height of the snap grid. + * @default + */ this.snapY = 0; - /** - * @property {number} pixelPerfect - Should we use pixel perfect hit detection? Warning: expensive. Only enable if you really need it! - * @default - */ + /** + * @property {number} pixelPerfect - Should we use pixel perfect hit detection? Warning: expensive. Only enable if you really need it! + * @default + */ this.pixelPerfect = false; /** @@ -145,13 +143,13 @@ Phaser.InputHandler = function (sprite) { this.draggable = false; /** - * @property {Description} boundsRect - A region of the game world within which the sprite is restricted during drag. + * @property {Phaser.Rectangle} boundsRect - A region of the game world within which the sprite is restricted during drag. * @default */ this.boundsRect = null; /** - * @property {Description} boundsSprite - A Sprite the bounds of which this sprite is restricted during drag. + * @property {Phaser.Sprite} boundsSprite - A Sprite the bounds of which this sprite is restricted during drag. * @default */ this.boundsSprite = null; @@ -168,7 +166,7 @@ Phaser.InputHandler = function (sprite) { * @property {Phaser.Point} _tempPoint - Description. * @private */ - this._tempPoint = new Phaser.Point; + this._tempPoint = new Phaser.Point(); this._pointerData = []; @@ -192,23 +190,23 @@ Phaser.InputHandler = function (sprite) { Phaser.InputHandler.prototype = { - /** - * Description. - * @method Phaser.InputHandler#start - * @param {number} priority - Description. - * @param {boolean} useHandCursor - Description. - * @return {Phaser.Sprite} Description. - */ - start: function (priority, useHandCursor) { + /** + * Starts the Input Handler running. This is called automatically when you enable input on a Sprite, or can be called directly if you need to set a specific priority. + * @method Phaser.InputHandler#start + * @param {number} priority - Higher priority sprites take click priority over low-priority sprites when they are stacked on-top of each other. + * @param {boolean} useHandCursor - If true the Sprite will show the hand cursor on mouse-over (doesn't apply to mobile browsers) + * @return {Phaser.Sprite} The Sprite object to which the Input Handler is bound. + */ + start: function (priority, useHandCursor) { - priority = priority || 0; - if (typeof useHandCursor == 'undefined') { useHandCursor = false; } + priority = priority || 0; + if (typeof useHandCursor == 'undefined') { useHandCursor = false; } // Turning on - if (this.enabled == false) + if (this.enabled === false) { // Register, etc - this.game.input.interactiveItems.add(this); + this.game.input.interactiveItems.add(this); this.useHandCursor = useHandCursor; this.priorityID = priority; @@ -231,29 +229,29 @@ Phaser.InputHandler.prototype = { }; } - this.snapOffset = new Phaser.Point; + this.snapOffset = new Phaser.Point(); this.enabled = true; // Create the signals the Input component will emit if (this.sprite.events && this.sprite.events.onInputOver == null) { - this.sprite.events.onInputOver = new Phaser.Signal; - this.sprite.events.onInputOut = new Phaser.Signal; - this.sprite.events.onInputDown = new Phaser.Signal; - this.sprite.events.onInputUp = new Phaser.Signal; - this.sprite.events.onDragStart = new Phaser.Signal; - this.sprite.events.onDragStop = new Phaser.Signal; + this.sprite.events.onInputOver = new Phaser.Signal(); + this.sprite.events.onInputOut = new Phaser.Signal(); + this.sprite.events.onInputDown = new Phaser.Signal(); + this.sprite.events.onInputUp = new Phaser.Signal(); + this.sprite.events.onDragStart = new Phaser.Signal(); + this.sprite.events.onDragStop = new Phaser.Signal(); } } return this.sprite; - }, + }, - /** - * Description. - * @method Phaser.InputHandler#reset - */ + /** + * Resets the Input Handler and disables it. + * @method Phaser.InputHandler#reset + */ reset: function () { this.enabled = false; @@ -278,14 +276,14 @@ Phaser.InputHandler.prototype = { } }, - /** - * Description. - * @method Phaser.InputHandler#stop - */ - stop: function () { + /** + * Stops the Input Handler from running. + * @method Phaser.InputHandler#stop + */ + stop: function () { // Turning off - if (this.enabled == false) + if (this.enabled === false) { return; } @@ -293,15 +291,15 @@ Phaser.InputHandler.prototype = { { // De-register, etc this.enabled = false; - this.game.input.interactiveItems.remove(this); + this.game.input.interactiveItems.remove(this); } - }, + }, - /** - * Clean up memory. - * @method Phaser.InputHandler#destroy - */ + /** + * Clean up memory. + * @method Phaser.InputHandler#destroy + */ destroy: function () { if (this.enabled) @@ -310,99 +308,99 @@ Phaser.InputHandler.prototype = { this.game.input.interactiveItems.remove(this); - this.stop(); + this.stop(); - this.sprite = null; + this.sprite = null; } }, - /** + /** * 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. * @method Phaser.InputHandler#pointerX - * @param {Pointer} pointer + * @param {Phaser.Pointer} pointer * @return {number} The x coordinate of the Input pointer. - */ + */ pointerX: function (pointer) { - pointer = pointer || 0; + pointer = pointer || 0; return this._pointerData[pointer].x; }, - /** + /** * 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. * @method Phaser.InputHandler#pointerY - * @param {Pointer} pointer + * @param {Phaser.Pointer} pointer * @return {number} The y coordinate of the Input pointer. */ pointerY: function (pointer) { - pointer = pointer || 0; + pointer = pointer || 0; return this._pointerData[pointer].y; }, - /** + /** * If the Pointer is touching the touchscreen, or the mouse button is held down, isDown is set to true. * @method Phaser.InputHandler#pointerDown - * @param {Pointer} pointer + * @param {Phaser.Pointer} pointer * @return {boolean} */ pointerDown: function (pointer) { - pointer = pointer || 0; + pointer = pointer || 0; return this._pointerData[pointer].isDown; }, - /** + /** * If the Pointer is not touching the touchscreen, or the mouse button is up, isUp is set to true * @method Phaser.InputHandler#pointerUp - * @param {Pointer} pointer + * @param {Phaser.Pointer} pointer * @return {boolean} */ pointerUp: function (pointer) { - pointer = pointer || 0; + pointer = pointer || 0; return this._pointerData[pointer].isUp; }, - /** + /** * A timestamp representing when the Pointer first touched the touchscreen. * @method Phaser.InputHandler#pointerTimeDown - * @param {Pointer} pointer + * @param {Phaser.Pointer} pointer * @return {number} */ pointerTimeDown: function (pointer) { - pointer = pointer || 0; + pointer = pointer || 0; return this._pointerData[pointer].timeDown; }, - /** + /** * A timestamp representing when the Pointer left the touchscreen. * @method Phaser.InputHandler#pointerTimeUp - * @param {Pointer} pointer + * @param {Phaser.Pointer} pointer * @return {number} */ pointerTimeUp: function (pointer) { - pointer = pointer || 0; + pointer = pointer || 0; return this._pointerData[pointer].timeUp; }, - /** + /** * Is the Pointer over this Sprite? * @method Phaser.InputHandler#pointerOver * @param {number} [index] - The ID number of a Pointer to check. If you don't provide a number it will check all Pointers. @@ -432,13 +430,13 @@ Phaser.InputHandler.prototype = { }, - /** + /** * Is the Pointer outside of this Sprite? * @method Phaser.InputHandler#pointerOut * @param {number} [index] - The ID number of a Pointer to check. If you don't provide a number it will check all Pointers. * @return {boolean} True if the given pointer (if a index was given, or any pointer if not) is out of this object. */ - pointerOut: function (pointer) { + pointerOut: function (index) { if (this.enabled) { @@ -462,52 +460,52 @@ Phaser.InputHandler.prototype = { }, - /** + /** * A timestamp representing when the Pointer first touched the touchscreen. * @method Phaser.InputHandler#pointerTimeOver - * @param {Pointer} pointer + * @param {Phaser.Pointer} pointer * @return {number} */ pointerTimeOver: function (pointer) { - pointer = pointer || 0; + pointer = pointer || 0; return this._pointerData[pointer].timeOver; }, - /** + /** * A timestamp representing when the Pointer left the touchscreen. * @method Phaser.InputHandler#pointerTimeOut - * @param {Pointer} pointer + * @param {Phaser.Pointer} pointer * @return {number} */ pointerTimeOut: function (pointer) { - pointer = pointer || 0; + pointer = pointer || 0; return this._pointerData[pointer].timeOut; }, - /** + /** * Is this sprite being dragged by the mouse or not? * @method Phaser.InputHandler#pointerTimeOut - * @param {Pointer} pointer + * @param {Phaser.Pointer} pointer * @return {number} */ pointerDragged: function (pointer) { - pointer = pointer || 0; + pointer = pointer || 0; return this._pointerData[pointer].isDragged; }, - /** + /** * Checks if the given pointer is over this Sprite. * @method Phaser.InputHandler#checkPointerOver - * @param {Pointer} pointer + * @param {Phaser.Pointer} pointer * @return {boolean} */ checkPointerOver: function (pointer) { @@ -533,7 +531,7 @@ Phaser.InputHandler.prototype = { }, - /** + /** * Runs a pixel perfect check against the given x/y coordinates of the Sprite this InputHandler is bound to. * It compares the alpha value of the pixel and if >= InputHandler.pixelPerfectAlpha it returns true. * @method Phaser.InputHandler#checkPixel @@ -565,14 +563,14 @@ Phaser.InputHandler.prototype = { }, - /** + /** * Update. * @method Phaser.InputHandler#update - * @param {Pointer} pointer + * @param {Phaser.Pointer} pointer */ update: function (pointer) { - if (this.enabled == false || this.sprite.visible == false || (this.sprite.group && this.sprite.group.visible == false)) + if (this.enabled === false || this.sprite.visible === false || (this.sprite.group && this.sprite.group.visible === false)) { this._pointerOutHandler(pointer); return false; @@ -582,7 +580,7 @@ Phaser.InputHandler.prototype = { { return this.updateDrag(pointer); } - else if (this._pointerData[pointer.id].isOver == true) + else if (this._pointerData[pointer.id].isOver === true) { if (this.checkPointerOver(pointer)) { @@ -598,15 +596,15 @@ Phaser.InputHandler.prototype = { } }, - /** - * Description. - * @method Phaser.InputHandler#_pointerOverHandler - * @private - * @param {Pointer} pointer - */ + /** + * Internal method handling the pointer over event. + * @method Phaser.InputHandler#_pointerOverHandler + * @private + * @param {Phaser.Pointer} pointer + */ _pointerOverHandler: function (pointer) { - if (this._pointerData[pointer.id].isOver == false) + if (this._pointerData[pointer.id].isOver === false) { this._pointerData[pointer.id].isOver = true; this._pointerData[pointer.id].isOut = false; @@ -614,7 +612,7 @@ Phaser.InputHandler.prototype = { this._pointerData[pointer.id].x = pointer.x - this.sprite.x; this._pointerData[pointer.id].y = pointer.y - this.sprite.y; - if (this.useHandCursor && this._pointerData[pointer.id].isDragged == false) + if (this.useHandCursor && this._pointerData[pointer.id].isDragged === false) { this.game.stage.canvas.style.cursor = "pointer"; } @@ -623,19 +621,19 @@ Phaser.InputHandler.prototype = { } }, - /** - * Description. - * @method Phaser.InputHandler#_pointerOutHandler - * @private - * @param {Pointer} pointer - */ + /** + * Internal method handling the pointer out event. + * @method Phaser.InputHandler#_pointerOutHandler + * @private + * @param {Phaser.Pointer} pointer + */ _pointerOutHandler: function (pointer) { this._pointerData[pointer.id].isOver = false; this._pointerData[pointer.id].isOut = true; this._pointerData[pointer.id].timeOut = this.game.time.now; - if (this.useHandCursor && this._pointerData[pointer.id].isDragged == false) + if (this.useHandCursor && this._pointerData[pointer.id].isDragged === false) { this.game.stage.canvas.style.cursor = "default"; } @@ -647,15 +645,15 @@ Phaser.InputHandler.prototype = { }, - /** - * Description. - * @method Phaser.InputHandler#_touchedHandler - * @private - * @param {Pointer} pointer - */ + /** + * Internal method handling the touched event. + * @method Phaser.InputHandler#_touchedHandler + * @private + * @param {Phaser.Pointer} pointer + */ _touchedHandler: function (pointer) { - if (this._pointerData[pointer.id].isDown == false && this._pointerData[pointer.id].isOver == true) + if (this._pointerData[pointer.id].isDown === false && this._pointerData[pointer.id].isOver === true) { this._pointerData[pointer.id].isDown = true; this._pointerData[pointer.id].isUp = false; @@ -663,7 +661,7 @@ Phaser.InputHandler.prototype = { this.sprite.events.onInputDown.dispatch(this.sprite, pointer); // Start drag - if (this.draggable && this.isDragged == false) + if (this.draggable && this.isDragged === false) { this.startDrag(pointer); } @@ -671,7 +669,7 @@ Phaser.InputHandler.prototype = { if (this.bringToTop) { this.sprite.bringToTop(); - } + } } // Consume the event? @@ -679,12 +677,12 @@ Phaser.InputHandler.prototype = { }, - /** - * Description. - * @method Phaser.InputHandler#_releasedHandler - * @private - * @param {Pointer} pointer - */ + /** + * Internal method handling the pointer released event. + * @method Phaser.InputHandler#_releasedHandler + * @private + * @param {Phaser.Pointer} pointer + */ _releasedHandler: function (pointer) { // If was previously touched by this Pointer, check if still is AND still over this item @@ -719,10 +717,10 @@ Phaser.InputHandler.prototype = { }, - /** + /** * Updates the Pointer drag on this Sprite. * @method Phaser.InputHandler#updateDrag - * @param {Pointer} pointer + * @param {Phaser.Pointer} pointer * @return {boolean} */ updateDrag: function (pointer) { @@ -763,79 +761,79 @@ Phaser.InputHandler.prototype = { }, - /** + /** * Returns true if the pointer has entered the Sprite within the specified delay time (defaults to 500ms, half a second) * @method Phaser.InputHandler#justOver - * @param {Pointer} pointer + * @param {Phaser.Pointer} pointer * @param {number} delay - The time below which the pointer is considered as just over. * @return {boolean} */ justOver: function (pointer, delay) { - pointer = pointer || 0; - delay = delay || 500; + pointer = pointer || 0; + delay = delay || 500; return (this._pointerData[pointer].isOver && this.overDuration(pointer) < delay); }, - /** + /** * Returns true if the pointer has left the Sprite within the specified delay time (defaults to 500ms, half a second) * @method Phaser.InputHandler#justOut - * @param {Pointer} pointer + * @param {Phaser.Pointer} pointer * @param {number} delay - The time below which the pointer is considered as just out. * @return {boolean} */ justOut: function (pointer, delay) { - pointer = pointer || 0; - delay = delay || 500; + pointer = pointer || 0; + delay = delay || 500; return (this._pointerData[pointer].isOut && (this.game.time.now - this._pointerData[pointer].timeOut < delay)); }, - /** + /** * Returns true if the pointer has entered the Sprite within the specified delay time (defaults to 500ms, half a second) * @method Phaser.InputHandler#justPressed - * @param {Pointer} pointer + * @param {Phaser.Pointer} pointer * @param {number} delay - The time below which the pointer is considered as just over. * @return {boolean} */ justPressed: function (pointer, delay) { - pointer = pointer || 0; - delay = delay || 500; + pointer = pointer || 0; + delay = delay || 500; return (this._pointerData[pointer].isDown && this.downDuration(pointer) < delay); }, - /** + /** * Returns true if the pointer has left the Sprite within the specified delay time (defaults to 500ms, half a second) * @method Phaser.InputHandler#justReleased - * @param {Pointer} pointer + * @param {Phaser.Pointer} pointer * @param {number} delay - The time below which the pointer is considered as just out. * @return {boolean} */ justReleased: function (pointer, delay) { - pointer = pointer || 0; - delay = delay || 500; + pointer = pointer || 0; + delay = delay || 500; return (this._pointerData[pointer].isUp && (this.game.time.now - this._pointerData[pointer].timeUp < delay)); }, - /** + /** * If the pointer is currently over this Sprite this returns how long it has been there for in milliseconds. * @method Phaser.InputHandler#overDuration - * @param {Pointer} pointer + * @param {Phaser.Pointer} pointer * @return {number} The number of milliseconds the pointer has been over the Sprite, or -1 if not over. */ overDuration: function (pointer) { - pointer = pointer || 0; + pointer = pointer || 0; if (this._pointerData[pointer].isOver) { @@ -846,15 +844,15 @@ Phaser.InputHandler.prototype = { }, - /** + /** * If the pointer is currently over this Sprite this returns how long it has been there for in milliseconds. * @method Phaser.InputHandler#downDuration - * @param {Pointer} pointer + * @param {Phaser.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) { - pointer = pointer || 0; + pointer = pointer || 0; if (this._pointerData[pointer].isDown) { @@ -865,25 +863,24 @@ Phaser.InputHandler.prototype = { }, - /** + /** * Make this Sprite draggable by the mouse. You can also optionally set mouseStartDragCallback and mouseStopDragCallback * @method Phaser.InputHandler#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. - * @param alphaThreshold If using pixel perfect collision this specifies the alpha level from 0 to 255 above which a collision is processed (default 255) - * @param boundsRect If you want to restrict the drag of this sprite to a specific FlxRect, pass the FlxRect here, otherwise it's free to drag anywhere - * @param boundsSprite If you want to restrict the drag of this sprite to within the bounding box of another sprite, pass it here + * @param {boolean} [lockCenter=false] - 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 {boolean} [bringToTop=false] - If true the Sprite will be bought to the top of the rendering list in its current Group. + * @param {boolean} [pixelPerfect=false] - If true it will use a pixel perfect test to see if you clicked the Sprite. False uses the bounding box. + * @param {boolean} [alphaThreshold=255] - If using pixel perfect collision this specifies the alpha level from 0 to 255 above which a collision is processed. + * @param {Phaser.Rectangle} [boundsRect=null] - If you want to restrict the drag of this sprite to a specific Rectangle, pass the Phaser.Rectangle here, otherwise it's free to drag anywhere. + * @param {Phaser.Sprite} [boundsSprite=null] - If you want to restrict the drag of this sprite to within the bounding box of another sprite, pass it here. */ enableDrag: function (lockCenter, bringToTop, pixelPerfect, alphaThreshold, boundsRect, boundsSprite) { if (typeof lockCenter == 'undefined') { lockCenter = false; } if (typeof bringToTop == 'undefined') { bringToTop = false; } if (typeof pixelPerfect == 'undefined') { pixelPerfect = false; } - - alphaThreshold = alphaThreshold || 255; - boundsRect = boundsRect || null; - boundsSprite = boundsSprite || null; + if (typeof alphaThreshold == 'undefined') { alphaThreshold = 255; } + if (typeof boundsRect == 'undefined') { boundsRect = null; } + if (typeof boundsSprite == 'undefined') { boundsSprite = null; } this._dragPoint = new Phaser.Point(); this.draggable = true; @@ -906,7 +903,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 Phaser.InputHandler#disableDrag */ @@ -926,9 +923,10 @@ Phaser.InputHandler.prototype = { }, - /** + /** * Called by Pointer when drag starts on this Sprite. Should not usually be called directly. * @method Phaser.InputHandler#startDrag + * @param {Phaser.Pointer} pointer */ startDrag: function (pointer) { @@ -957,9 +955,10 @@ Phaser.InputHandler.prototype = { }, - /** + /** * Called by Pointer when drag is stopped on this Sprite. Should not usually be called directly. * @method Phaser.InputHandler#stopDrag + * @param {Phaser.Pointer} pointer */ stopDrag: function (pointer) { @@ -976,37 +975,37 @@ Phaser.InputHandler.prototype = { this.sprite.events.onDragStop.dispatch(this.sprite, pointer); this.sprite.events.onInputUp.dispatch(this.sprite, pointer); - if (this.checkPointerOver(pointer) == false) + if (this.checkPointerOver(pointer) === false) { this._pointerOutHandler(pointer); } }, - /** + /** * Restricts this sprite to drag movement only on the given axis. Note: If both are set to false the sprite will never move! * @method Phaser.InputHandler#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 + * @param {boolean} [allowHorizontal=true] - To enable the sprite to be dragged horizontally set to true, otherwise false. + * @param {boolean} [allowVertical=true] - To enable the sprite to be dragged vertically set to true, otherwise false. */ setDragLock: function (allowHorizontal, allowVertical) { if (typeof allowHorizontal == 'undefined') { allowHorizontal = true; } - if (typeof allowVertical == 'undefined') { allowVertical = true; } + if (typeof allowVertical == 'undefined') { allowVertical = true; } this.allowHorizontalDrag = allowHorizontal; this.allowVerticalDrag = allowVertical; }, - /** + /** * 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 Phaser.InputHandler#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 - * @param onRelease If true the sprite will snap to the grid when released + * @param {number} snapX - The width of the grid cell to snap to. + * @param {number} snapY - The height of the grid cell to snap to. + * @param {boolean} [onDrag=true] - If true the sprite will snap to the grid while being dragged. + * @param {boolean} [onRelease=false] - If true the sprite will snap to the grid when released. */ enableSnap: function (snapX, snapY, onDrag, onRelease) { @@ -1020,7 +1019,7 @@ Phaser.InputHandler.prototype = { }, - /** + /** * Stops the sprite from snapping to a grid during drag or release. * @method Phaser.InputHandler#disableSnap */ @@ -1031,7 +1030,7 @@ Phaser.InputHandler.prototype = { }, - /** + /** * Bounds Rect check for the sprite drag * @method Phaser.InputHandler#checkBoundsRect */ @@ -1057,7 +1056,7 @@ Phaser.InputHandler.prototype = { }, - /** + /** * Parent Sprite Bounds check for the sprite drag. * @method Phaser.InputHandler#checkBoundsSprite */ diff --git a/src/input/Key.js b/src/input/Key.js index b8ad2ab4..161829d9 100644 --- a/src/input/Key.js +++ b/src/input/Key.js @@ -13,87 +13,87 @@ */ Phaser.Key = function (game, keycode) { - /** - * @property {Phaser.Game} game - A reference to the currently running game. - */ - this.game = game; + /** + * @property {Phaser.Game} game - A reference to the currently running game. + */ + this.game = game; - /** - * @property {boolean} isDown - The "down" state of the key. - * @default - */ - this.isDown = false; + /** + * @property {boolean} isDown - The "down" state of the key. + * @default + */ + this.isDown = false; - /** - * @property {boolean} isUp - The "up" state of the key. - * @default - */ - this.isUp = false; + /** + * @property {boolean} isUp - The "up" state of the key. + * @default + */ + this.isUp = false; - /** - * @property {boolean} altKey - The down state of the ALT key, if pressed at the same time as this key. - * @default - */ - this.altKey = false; + /** + * @property {boolean} altKey - The down state of the ALT key, if pressed at the same time as this key. + * @default + */ + this.altKey = false; - /** - * @property {boolean} ctrlKey - The down state of the CTRL key, if pressed at the same time as this key. - * @default - */ - this.ctrlKey = false; + /** + * @property {boolean} ctrlKey - The down state of the CTRL key, if pressed at the same time as this key. + * @default + */ + this.ctrlKey = false; - /** - * @property {boolean} shiftKey - The down state of the SHIFT key, if pressed at the same time as this key. - * @default - */ - this.shiftKey = false; + /** + * @property {boolean} shiftKey - The down state of the SHIFT key, if pressed at the same time as this key. + * @default + */ + this.shiftKey = false; - /** - * @property {number} timeDown - The timestamp when the key was last pressed down. - * @default - */ - this.timeDown = 0; + /** + * @property {number} timeDown - The timestamp when the key was last pressed down. + * @default + */ + this.timeDown = 0; - /** - * If the key is down this value holds the duration of that key press and is constantly updated. - * If the key is up it holds the duration of the previous down session. - * @property {number} duration - The number of milliseconds this key has been held down for. - * @default - */ - this.duration = 0; + /** + * If the key is down this value holds the duration of that key press and is constantly updated. + * If the key is up it holds the duration of the previous down session. + * @property {number} duration - The number of milliseconds this key has been held down for. + * @default + */ + this.duration = 0; - /** - * @property {number} timeUp - The timestamp when the key was last released. - * @default - */ - this.timeUp = 0; + /** + * @property {number} timeUp - The timestamp when the key was last released. + * @default + */ + this.timeUp = 0; - /** - * @property {number} repeats - If a key is held down this holds down the number of times the key has 'repeated'. - * @default - */ - this.repeats = 0; + /** + * @property {number} repeats - If a key is held down this holds down the number of times the key has 'repeated'. + * @default + */ + this.repeats = 0; - /** - * @property {number} keyCode - The keycode of this key. - */ - this.keyCode = keycode; + /** + * @property {number} keyCode - The keycode of this key. + */ + this.keyCode = keycode; - /** - * @property {Phaser.Signal} onDown - This Signal is dispatched every time this Key is pressed down. It is only dispatched once (until the key is released again). - */ + /** + * @property {Phaser.Signal} onDown - This Signal is dispatched every time this Key is pressed down. It is only dispatched once (until the key is released again). + */ this.onDown = new Phaser.Signal(); - /** - * @property {Phaser.Signal} onUp - This Signal is dispatched every time this Key is pressed down. It is only dispatched once (until the key is released again). - */ + /** + * @property {Phaser.Signal} onUp - This Signal is dispatched every time this Key is pressed down. It is only dispatched once (until the key is released again). + */ this.onUp = new Phaser.Signal(); - + }; Phaser.Key.prototype = { - /** + /** * Called automatically by Phaser.Keyboard. * @method Phaser.Key#processKeyDown * @param {KeyboardEvent} event. @@ -124,7 +124,7 @@ Phaser.Key.prototype = { }, - /** + /** * Called automatically by Phaser.Keyboard. * @method Phaser.Key#processKeyUp * @param {KeyboardEvent} event. @@ -140,8 +140,8 @@ Phaser.Key.prototype = { }, - /** - * Returns the "just pressed" state of the Key. Just pressed is considered true if the key was pressed down within the duration given (default 250ms) + /** + * Returns the "just pressed" state of the Key. Just pressed is considered true if the key was pressed down within the duration given (default 250ms) * @method Phaser.Key#justPressed * @param {number} [duration=250] - The duration below which the key is considered as being just pressed. * @return {boolean} True if the key is just pressed otherwise false. @@ -154,8 +154,8 @@ Phaser.Key.prototype = { }, - /** - * Returns the "just released" state of the Key. Just released is considered as being true if the key was released within the duration given (default 250ms) + /** + * Returns the "just released" state of the Key. Just released is considered as being true if the key was released within the duration given (default 250ms) * @method Phaser.Key#justPressed * @param {number} [duration=250] - The duration below which the key is considered as being just released. * @return {boolean} True if the key is just released otherwise false. @@ -164,7 +164,7 @@ Phaser.Key.prototype = { if (typeof duration === "undefined") { duration = 250; } - return (this.isDown == false && (this.game.time.now - this.timeUp < duration)); + return (this.isDown === false && (this.game.time.now - this.timeUp < duration)); } diff --git a/src/input/Keyboard.js b/src/input/Keyboard.js index c3bf108b..2c66712f 100644 --- a/src/input/Keyboard.js +++ b/src/input/Keyboard.js @@ -5,36 +5,35 @@ */ /** -* Phaser - Keyboard constructor. +* The Keyboard class handles looking after keyboard input for your game. It will recognise and respond to key presses and dispatch the required events. * * @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 - */ + /** + * @property {Phaser.Game} game - Local reference to game. + */ + this.game = game; + + /** + * @property {object} _keys - The object the key values are stored in. + * @private + */ this._keys = {}; /** - * @property {Description} _hotkeys - Description. + * @property {object} _hotkeys - The object the hot keys are stored in. * @private */ this._hotkeys = {}; - /** - * @property {Description} _capture - Description. - * @private - */ + /** + * @property {object} _capture - The object the key capture values are stored in. + * @private + */ this._capture = {}; /** @@ -72,7 +71,7 @@ Phaser.Keyboard = function (game) { * @property {function} onUpCallback - This callback is invoked every time a key is released. */ this.onUpCallback = null; - + }; Phaser.Keyboard.prototype = { @@ -134,10 +133,10 @@ Phaser.Keyboard.prototype = { */ createCursorKeys: function () { - return { - up: this.addKey(Phaser.Keyboard.UP), - down: this.addKey(Phaser.Keyboard.DOWN), - left: this.addKey(Phaser.Keyboard.LEFT), + return { + up: this.addKey(Phaser.Keyboard.UP), + down: this.addKey(Phaser.Keyboard.DOWN), + left: this.addKey(Phaser.Keyboard.LEFT), right: this.addKey(Phaser.Keyboard.RIGHT) } @@ -178,7 +177,7 @@ Phaser.Keyboard.prototype = { }, - /** + /** * By default when a key is pressed Phaser will not stop the event from propagating up to the browser. * 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. @@ -201,9 +200,9 @@ Phaser.Keyboard.prototype = { } }, - /** - * Removes an existing key capture. - * @method Phaser.Keyboard#removeKeyCapture + /** + * Removes an existing key capture. + * @method Phaser.Keyboard#removeKeyCapture * @param {number} keycode */ removeKeyCapture: function (keycode) { @@ -212,9 +211,9 @@ Phaser.Keyboard.prototype = { }, - /** - * Clear all set key captures. - * @method Phaser.Keyboard#clearCaptures + /** + * Clear all set key captures. + * @method Phaser.Keyboard#clearCaptures */ clearCaptures: function () { @@ -222,12 +221,12 @@ Phaser.Keyboard.prototype = { }, - /** - * Process the keydown event. - * @method Phaser.Keyboard#processKeyDown + /** + * Process the keydown event. + * @method Phaser.Keyboard#processKeyDown * @param {KeyboardEvent} event * @protected - */ + */ processKeyDown: function (event) { if (this.game.input.disabled || this.disabled) @@ -278,9 +277,9 @@ Phaser.Keyboard.prototype = { }, - /** - * Process the keyup event. - * @method Phaser.Keyboard#processKeyUp + /** + * Process the keyup event. + * @method Phaser.Keyboard#processKeyUp * @param {KeyboardEvent} event * @protected */ @@ -324,9 +323,9 @@ Phaser.Keyboard.prototype = { }, - /** - * Reset the "isDown" state of all keys. - * @method Phaser.Keyboard#reset + /** + * Reset the "isDown" state of all keys. + * @method Phaser.Keyboard#reset */ reset: function () { @@ -390,7 +389,7 @@ Phaser.Keyboard.prototype = { return this._keys[keycode].isDown; } - return false; + return false; } diff --git a/src/input/MSPointer.js b/src/input/MSPointer.js index e24399f9..80c0f058 100644 --- a/src/input/MSPointer.js +++ b/src/input/MSPointer.js @@ -16,33 +16,15 @@ */ 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; + /** + * @property {Phaser.Game} game - A reference to the currently running game. + */ + this.game = game; + + /** + * @property {Object} callbackContext - The context under which callbacks are called (defaults to game). + */ + this.callbackContext = this.game; /** * You can disable all Input by setting disabled = true. While set all new input related events will be ignored. @@ -51,26 +33,20 @@ Phaser.MSPointer = function (game) { this.disabled = false; /** - * Description. - * @property {Description} _onMSPointerDown + * @property {function} _onMSPointerDown - Internal function to handle MSPointer events. * @private - * @default */ this._onMSPointerDown = null; /** - * Description. - * @property {Description} _onMSPointerMove + * @property {function} _onMSPointerMove - Internal function to handle MSPointer events. * @private - * @default */ this._onMSPointerMove = null; /** - * Description. - * @property {Description} _onMSPointerUp + * @property {function} _onMSPointerUp - Internal function to handle MSPointer events. * @private - * @default */ this._onMSPointerUp = null; @@ -78,7 +54,7 @@ Phaser.MSPointer = function (game) { Phaser.MSPointer.prototype = { - /** + /** * Starts the event listeners running. * @method Phaser.MSPointer#start */ @@ -86,7 +62,7 @@ Phaser.MSPointer.prototype = { var _this = this; - if (this.game.device.mspointer == true) + if (this.game.device.mspointer === true) { this._onMSPointerDown = function (event) { return _this.onPointerDown(event); @@ -104,6 +80,11 @@ Phaser.MSPointer.prototype = { this.game.renderer.view.addEventListener('MSPointerMove', this._onMSPointerMove, false); this.game.renderer.view.addEventListener('MSPointerUp', this._onMSPointerUp, false); + // IE11+ uses non-prefix events + this.game.renderer.view.addEventListener('pointerDown', this._onMSPointerDown, false); + this.game.renderer.view.addEventListener('pointerMove', this._onMSPointerMove, false); + this.game.renderer.view.addEventListener('pointerUp', this._onMSPointerUp, false); + this.game.renderer.view.style['-ms-content-zooming'] = 'none'; this.game.renderer.view.style['-ms-touch-action'] = 'none'; @@ -112,10 +93,10 @@ Phaser.MSPointer.prototype = { }, /** - * Description. + * The function that handles the PointerDown event. * @method Phaser.MSPointer#onPointerDown - * @param {Any} event - **/ + * @param {PointerEvent} event + */ onPointerDown: function (event) { if (this.game.input.disabled || this.disabled) @@ -131,10 +112,10 @@ Phaser.MSPointer.prototype = { }, /** - * Description. + * The function that handles the PointerMove event. * @method Phaser.MSPointer#onPointerMove - * @param {Any} event - **/ + * @param {PointerEvent } event + */ onPointerMove: function (event) { if (this.game.input.disabled || this.disabled) @@ -150,10 +131,10 @@ Phaser.MSPointer.prototype = { }, /** - * Description. + * The function that handles the PointerUp event. * @method Phaser.MSPointer#onPointerUp - * @param {Any} event - **/ + * @param {PointerEvent} event + */ onPointerUp: function (event) { if (this.game.input.disabled || this.disabled) @@ -168,7 +149,7 @@ Phaser.MSPointer.prototype = { }, - /** + /** * Stop the event listeners. * @method Phaser.MSPointer#stop */ @@ -178,6 +159,10 @@ Phaser.MSPointer.prototype = { this.game.stage.canvas.removeEventListener('MSPointerMove', this._onMSPointerMove); this.game.stage.canvas.removeEventListener('MSPointerUp', this._onMSPointerUp); + this.game.stage.canvas.removeEventListener('pointerDown', this._onMSPointerDown); + this.game.stage.canvas.removeEventListener('pointerMove', this._onMSPointerMove); + this.game.stage.canvas.removeEventListener('pointerUp', this._onMSPointerUp); + } }; \ No newline at end of file diff --git a/src/input/Mouse.js b/src/input/Mouse.js index a9ff3845..75c69983 100644 --- a/src/input/Mouse.js +++ b/src/input/Mouse.js @@ -5,98 +5,90 @@ */ /** -* Phaser - Mouse constructor. +* Phaser.Mouse is responsible for handling all aspects of mouse interaction with the browser. It captures and processes mouse events. * * @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 {Object} callbackContext - Description. - */ - this.callbackContext = this.game; + /** + * @property {Phaser.Game} game - A reference to the currently running game. + */ + this.game = game; + + /** + * @property {Object} callbackContext - The context under which callbacks are called. + */ + this.callbackContext = this.game; - /** - * @property {function} mouseDownCallback - Description. - * @default - */ - this.mouseDownCallback = null; - - /** - * @property {function} mouseMoveCallback - Description. - * @default - */ - this.mouseMoveCallback = null; - - /** - * @property {function} mouseUpCallback - Description. - * @default - */ - this.mouseUpCallback = null; + /** + * @property {function} mouseDownCallback - A callback that can be fired when the mouse is pressed down. + */ + this.mouseDownCallback = null; + + /** + * @property {function} mouseMoveCallback - A callback that can be fired when the mouse is moved while pressed down. + */ + this.mouseMoveCallback = null; + + /** + * @property {function} mouseUpCallback - A callback that can be fired when the mouse is released from a pressed down state. + */ + this.mouseUpCallback = null; /** * @property {boolean} capture - If true the DOM mouse events will have event.preventDefault applied to them, if false they will propogate fully. */ this.capture = true; - /** - * @property {number} button- The type of click, either: Phaser.Mouse.NO_BUTTON, Phaser.Mouse.LEFT_BUTTON, Phaser.Mouse.MIDDLE_BUTTON or Phaser.Mouse.RIGHT_BUTTON. - * @default - */ - this.button = -1; + /** + * @property {number} button- The type of click, either: Phaser.Mouse.NO_BUTTON, Phaser.Mouse.LEFT_BUTTON, Phaser.Mouse.MIDDLE_BUTTON or Phaser.Mouse.RIGHT_BUTTON. + * @default + */ + this.button = -1; /** - * You can disable all Input by setting disabled = true. While set all new input related events will be ignored. - * @property {boolean} disabled + * @property {boolean} disabled - You can disable all Input by setting disabled = true. While set all new input related events will be ignored. * @default */ this.disabled = false; /** - * If the mouse has been Pointer Locked successfully this will be set to true. - * @property {boolean} locked + * @property {boolean} locked - If the mouse has been Pointer Locked successfully this will be set to true. * @default */ this.locked = false; /** - * This event is dispatched when the browser enters or leaves pointer lock state. - * @property {Phaser.Signal} pointerLock + * @property {Phaser.Signal} pointerLock - This event is dispatched when the browser enters or leaves pointer lock state. * @default */ - this.pointerLock = new Phaser.Signal; + this.pointerLock = new Phaser.Signal(); /** - * The browser mouse event. - * @property {MouseEvent} event + * @property {MouseEvent} event - The browser mouse event. */ - this.event; + this.event = null; /** - * @property {function} _onMouseDown + * @property {function} _onMouseDown - Internal event handler reference. * @private */ - this._onMouseDown; + this._onMouseDown = null; /** - * @property {function} _onMouseMove + * @property {function} _onMouseMove - Internal event handler reference. * @private */ - this._onMouseMove; + this._onMouseMove = null; /** - * @property {function} _onMouseUp + * @property {function} _onMouseUp - Internal event handler reference. * @private */ - this._onMouseUp; + this._onMouseUp = null; }; @@ -105,6 +97,7 @@ Phaser.Mouse = function (game) { * @type {number} */ Phaser.Mouse.NO_BUTTON = -1; + /** * @constant * @type {number} @@ -125,7 +118,7 @@ Phaser.Mouse.RIGHT_BUTTON = 2; Phaser.Mouse.prototype = { - /** + /** * Starts the event listeners running. * @method Phaser.Mouse#start */ @@ -133,7 +126,7 @@ Phaser.Mouse.prototype = { var _this = this; - if (this.game.device.android && this.game.device.chrome == false) + if (this.game.device.android && this.game.device.chrome === false) { // Android stock browser fires mouse events even if you preventDefault on the touchStart, so ... return; @@ -161,10 +154,10 @@ Phaser.Mouse.prototype = { }, - /** - * The internal method that handles the mouse down event from the browser. - * @method Phaser.Mouse#onMouseDown - * @param {MouseEvent} event + /** + * The internal method that handles the mouse down event from the browser. + * @method Phaser.Mouse#onMouseDown + * @param {MouseEvent} event - The native event from the browser. This gets stored in Mouse.event. */ onMouseDown: function (event) { @@ -193,10 +186,10 @@ Phaser.Mouse.prototype = { }, - /** + /** * The internal method that handles the mouse move event from the browser. - * @method Phaser.Mouse#onMouseMove - * @param {MouseEvent} event + * @method Phaser.Mouse#onMouseMove + * @param {MouseEvent} event - The native event from the browser. This gets stored in Mouse.event. */ onMouseMove: function (event) { @@ -223,10 +216,10 @@ Phaser.Mouse.prototype = { }, - /** + /** * The internal method that handles the mouse up event from the browser. - * @method Phaser.Mouse#onMouseUp - * @param {MouseEvent} event + * @method Phaser.Mouse#onMouseUp + * @param {MouseEvent} event - The native event from the browser. This gets stored in Mouse.event. */ onMouseUp: function (event) { @@ -237,7 +230,7 @@ Phaser.Mouse.prototype = { event.preventDefault(); } - this.button = Phaser.Mouse.NO_BUTTON; + this.button = Phaser.Mouse.NO_BUTTON; if (this.mouseUpCallback) { @@ -259,7 +252,7 @@ Phaser.Mouse.prototype = { * If the browser supports it you can request that the pointer be locked to the browser window. * This is classically known as 'FPS controls', where the pointer can't leave the browser until the user presses an exit key. * If the browser successfully enters a locked state the event Phaser.Mouse.pointerLock will be dispatched and the first parameter will be 'true'. - * @method Phaser.Mouse#requestPointerLock + * @method Phaser.Mouse#requestPointerLock */ requestPointerLock: function () { @@ -284,10 +277,10 @@ Phaser.Mouse.prototype = { }, - /** - * Internal pointerLockChange handler. - * @method Phaser.Mouse#pointerLockChange - * @param {MouseEvent} event + /** + * Internal pointerLockChange handler. + * @method Phaser.Mouse#pointerLockChange + * @param {pointerlockchange} event - The native event from the browser. This gets stored in Mouse.event. */ pointerLockChange: function (event) { @@ -297,20 +290,20 @@ Phaser.Mouse.prototype = { { // Pointer was successfully locked this.locked = true; - this.pointerLock.dispatch(true); + this.pointerLock.dispatch(true, event); } else { // Pointer was unlocked this.locked = false; - this.pointerLock.dispatch(false); + this.pointerLock.dispatch(false, event); } }, - /** - * Internal release pointer lock handler. - * @method Phaser.Mouse#releasePointerLock + /** + * Internal release pointer lock handler. + * @method Phaser.Mouse#releasePointerLock */ releasePointerLock: function () { @@ -324,7 +317,7 @@ Phaser.Mouse.prototype = { }, - /** + /** * Stop the event listeners. * @method Phaser.Mouse#stop */ diff --git a/src/input/Pointer.js b/src/input/Pointer.js index b7af095d..376cfbd4 100644 --- a/src/input/Pointer.js +++ b/src/input/Pointer.js @@ -11,192 +11,167 @@ * @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. +* @param {number} id - The ID of the Pointer object within the game. Each game can have up to 10 active pointers. */ Phaser.Pointer = function (game, id) { /** - * @property {Phaser.Game} game - Local reference to game. + * @property {Phaser.Game} game - A reference to the currently running game. */ this.game = game; /** - * @property {Description} id - Description. + * @property {number} id - The ID of the Pointer object within the game. Each game can have up to 10 active pointers. */ this.id = id; /** - * Local private variable to store the status of dispatching a hold event. - * @property {boolean} _holdSent + * @property {boolean} _holdSent - Local private variable to store the status of dispatching a hold event. * @private * @default */ this._holdSent = false; /** - * Local private variable storing the short-term history of pointer movements. - * @property {array} _history + * @property {array} _history - Local private variable storing the short-term history of pointer movements. * @private */ this._history = []; /** - * Local private variable storing the time at which the next history drop should occur - * @property {number} _lastDrop + * @property {number} _lastDrop - Local private variable storing the time at which the next history drop should occur. * @private * @default */ this._nextDrop = 0; /** - * Monitor events outside of a state reset loop. - * @property {boolean} _stateReset - * @private - * @default - */ + * @property {boolean} _stateReset - Monitor events outside of a state reset loop. + * @private + * @default + */ this._stateReset = false; /** - * Description. - * @property {boolean} withinGame + * @property {boolean} withinGame - true if the Pointer is within the game area, otherwise false. */ this.withinGame = false; /** - * The horizontal coordinate of point relative to the viewport in pixels, excluding any scroll offset. - * @property {number} clientX + * @property {number} clientX - The horizontal coordinate of point relative to the viewport in pixels, excluding any scroll offset. * @default */ this.clientX = -1; /** - * The vertical coordinate of point relative to the viewport in pixels, excluding any scroll offset. - * @property {number} clientY + * @property {number} clientY - The vertical coordinate of point relative to the viewport in pixels, excluding any scroll offset. * @default */ this.clientY = -1; /** - * The horizontal coordinate of point relative to the viewport in pixels, including any scroll offset. - * @property {number} pageX + * @property {number} pageX - The horizontal coordinate of point relative to the viewport in pixels, including any scroll offset. * @default */ this.pageX = -1; /** - * The vertical coordinate of point relative to the viewport in pixels, including any scroll offset. - * @property {number} pageY + * @property {number} pageY - The vertical coordinate of point relative to the viewport in pixels, including any scroll offset. * @default */ this.pageY = -1; /** - * The horizontal coordinate of point relative to the screen in pixels. - * @property {number} screenX + * @property {number} screenX - The horizontal coordinate of point relative to the screen in pixels. * @default */ this.screenX = -1; /** - * The vertical coordinate of point relative to the screen in pixels. - * @property {number} screenY + * @property {number} screenY - The vertical coordinate of point relative to the screen in pixels. * @default */ this.screenY = -1; /** - * The horizontal coordinate of point relative to the game element. This value is automatically scaled based on game size. - * @property {number} x + * @property {number} x - The horizontal coordinate of point relative to the game element. This value is automatically scaled based on game size. * @default */ this.x = -1; /** - * The vertical coordinate of point relative to the game element. This value is automatically scaled based on game size. - * @property {number} y + * @property {number} y - The vertical coordinate of point relative to the game element. This value is automatically scaled based on game size. * @default */ this.y = -1; /** - * If the Pointer is a mouse this is true, otherwise false. - * @property {boolean} isMouse - * @type {boolean} + * @property {boolean} isMouse - If the Pointer is a mouse this is true, otherwise false. + * @default */ this.isMouse = false; /** - * If the Pointer is touching the touchscreen, or the mouse button is held down, isDown is set to true. - * @property {boolean} isDown + * @property {boolean} isDown - If the Pointer is touching the touchscreen, or the mouse button is held down, isDown is set to true. * @default */ this.isDown = false; /** - * If the Pointer is not touching the touchscreen, or the mouse button is up, isUp is set to true. - * @property {boolean} isUp + * @property {boolean} isUp - If the Pointer is not touching the touchscreen, or the mouse button is up, isUp is set to true. * @default */ this.isUp = true; /** - * A timestamp representing when the Pointer first touched the touchscreen. - * @property {number} timeDown + * @property {number} timeDown - A timestamp representing when the Pointer first touched the touchscreen. * @default */ this.timeDown = 0; /** - * A timestamp representing when the Pointer left the touchscreen. - * @property {number} timeUp + * @property {number} timeUp - A timestamp representing when the Pointer left the touchscreen. * @default */ this.timeUp = 0; /** - * A timestamp representing when the Pointer was last tapped or clicked. - * @property {number} previousTapTime + * @property {number} previousTapTime - A timestamp representing when the Pointer was last tapped or clicked. * @default */ this.previousTapTime = 0; /** - * The total number of times this Pointer has been touched to the touchscreen. - * @property {number} totalTouches + * @property {number} totalTouches - The total number of times this Pointer has been touched to the touchscreen. * @default */ this.totalTouches = 0; /** - * The number of miliseconds since the last click. - * @property {number} msSinceLastClick + * @property {number} msSinceLastClick - The number of miliseconds since the last click. * @default */ this.msSinceLastClick = Number.MAX_VALUE; /** - * The Game Object this Pointer is currently over / touching / dragging. - * @property {Any} targetObject + * @property {any} targetObject - The Game Object this Pointer is currently over / touching / dragging. * @default */ this.targetObject = null; /** - * An active pointer is one that is currently pressed down on the display. A Mouse is always active. - * @property {boolean} active + * @property {boolean} active - An active pointer is one that is currently pressed down on the display. A Mouse is always active. * @default */ this.active = false; /** - * A Phaser.Point object containing the current x/y values of the pointer on the display. - * @property {Phaser.Point} position + * @property {Phaser.Point} position - A Phaser.Point object containing the current x/y values of the pointer on the display. */ this.position = new Phaser.Point(); /** - * A Phaser.Point object containing the x/y values of the pointer when it was last in a down state on the display. - * @property {Phaser.Point} positionDown + * @property {Phaser.Point} positionDown - A Phaser.Point object containing the x/y values of the pointer when it was last in a down state on the display. */ this.positionDown = new Phaser.Point(); @@ -207,7 +182,7 @@ Phaser.Pointer = function (game, id) { */ this.circle = new Phaser.Circle(0, 0, 44); - if (id == 0) + if (id === 0) { this.isMouse = true; } @@ -216,7 +191,7 @@ Phaser.Pointer = function (game, id) { Phaser.Pointer.prototype = { - /** + /** * Called when the Pointer is pressed onto the touchscreen. * @method Phaser.Pointer#start * @param {Any} event @@ -232,7 +207,7 @@ Phaser.Pointer.prototype = { } // Fix to stop rogue browser plugins from blocking the visibility state event - if (this.game.paused == true && this.game.stage.scale.incorrectOrientation == false) + if (this.game.paused === true && this.game.stage.scale.incorrectOrientation === false) { this.game.paused = false; return this; @@ -255,7 +230,7 @@ Phaser.Pointer.prototype = { // x and y are the old values here? this.positionDown.setTo(this.x, this.y); - if (this.game.input.multiInputOverride == Phaser.Input.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.Input.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.Input.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers == 0)) + if (this.game.input.multiInputOverride == Phaser.Input.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.Input.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.Input.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers === 0)) { this.game.input.x = this.x; this.game.input.y = this.y; @@ -267,7 +242,7 @@ Phaser.Pointer.prototype = { this._stateReset = false; this.totalTouches++; - if (this.isMouse == false) + if (this.isMouse === false) { this.game.input.currentPointers++; } @@ -281,17 +256,17 @@ Phaser.Pointer.prototype = { }, - /** - * Description. + /** + * Called internall by the Input Manager. * @method Phaser.Pointer#update */ update: function () { if (this.active) { - if (this._holdSent == false && this.duration >= this.game.input.holdRate) + if (this._holdSent === false && this.duration >= this.game.input.holdRate) { - if (this.game.input.multiInputOverride == Phaser.Input.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.Input.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.Input.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers == 0)) + if (this.game.input.multiInputOverride == Phaser.Input.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.Input.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.Input.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers === 0)) { this.game.input.onHold.dispatch(this); } @@ -318,10 +293,10 @@ Phaser.Pointer.prototype = { }, - /** - * Called when the Pointer is moved + /** + * Called when the Pointer is moved. * @method Phaser.Pointer#move - * @param {Any} event + * @param {MouseEvent|PointerEvent|TouchEvent} event - The event passed up from the input handler. */ move: function (event) { @@ -351,7 +326,7 @@ Phaser.Pointer.prototype = { this.circle.x = this.x; this.circle.y = this.y; - if (this.game.input.multiInputOverride == Phaser.Input.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.Input.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.Input.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers == 0)) + if (this.game.input.multiInputOverride == Phaser.Input.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.Input.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.Input.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers === 0)) { this.game.input.activePointer = this; this.game.input.x = this.x; @@ -368,9 +343,9 @@ Phaser.Pointer.prototype = { } // Easy out if we're dragging something and it still exists - if (this.targetObject !== null && this.targetObject.isDragged == true) + if (this.targetObject !== null && this.targetObject.isDragged === true) { - if (this.targetObject.update(this) == false) + if (this.targetObject.update(this) === false) { this.targetObject = null; } @@ -388,7 +363,7 @@ Phaser.Pointer.prototype = { { var currentNode = this.game.input.interactiveItems.next; - do + do { // If the object is using pixelPerfect checks, or has a higher InputManager.PriorityID OR if the priority ID is the same as the current highest AND it has a higher renderOrderID, then set it to the top if (currentNode.pixelPerfect || currentNode.priorityID > this._highestInputPriorityID || (currentNode.priorityID == this._highestInputPriorityID && currentNode.sprite.renderOrderID > this._highestRenderOrderID)) @@ -433,7 +408,7 @@ Phaser.Pointer.prototype = { { // Same target as before, so update it // console.log("Same target as before, so update it"); - if (this._highestRenderObject.update(this) == false) + if (this._highestRenderObject.update(this) === false) { this.targetObject = null; } @@ -455,10 +430,10 @@ Phaser.Pointer.prototype = { }, - /** + /** * Called when the Pointer leaves the target area. * @method Phaser.Pointer#leave - * @param {Any} event + * @param {MouseEvent|PointerEvent|TouchEvent} event - The event passed up from the input handler. */ leave: function (event) { @@ -467,10 +442,10 @@ Phaser.Pointer.prototype = { }, - /** + /** * Called when the Pointer leaves the touchscreen. * @method Phaser.Pointer#stop - * @param {Any} event + * @param {MouseEvent|PointerEvent|TouchEvent} event - The event passed up from the input handler. */ stop: function (event) { @@ -482,7 +457,7 @@ Phaser.Pointer.prototype = { this.timeUp = this.game.time.now; - if (this.game.input.multiInputOverride == Phaser.Input.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.Input.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.Input.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers == 0)) + if (this.game.input.multiInputOverride == Phaser.Input.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.Input.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.Input.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers === 0)) { this.game.input.onUp.dispatch(this, event); @@ -515,7 +490,7 @@ Phaser.Pointer.prototype = { this.isDown = false; this.isUp = true; - if (this.isMouse == false) + if (this.isMouse === false) { this.game.input.currentPointers--; } @@ -524,7 +499,7 @@ Phaser.Pointer.prototype = { { var currentNode = this.game.input.interactiveItems.next; - do + do { if (currentNode) { @@ -546,11 +521,13 @@ Phaser.Pointer.prototype = { }, - /** + /** * The Pointer is considered justPressed if the time it was pressed onto the touchscreen or clicked is less than justPressedRate. + * Note that calling justPressed doesn't reset the pressed status of the Pointer, it will return `true` for as long as the duration is valid. + * If you wish to check if the Pointer was pressed down just once then see the Sprite.events.onInputDown event. * @method Phaser.Pointer#justPressed - * @param {number} [duration] - * @return {boolean} + * @param {number} [duration] - The time to check against. If none given it will use InputManager.justPressedRate. + * @return {boolean} true if the Pointer was pressed down within the duration given. */ justPressed: function (duration) { @@ -560,11 +537,13 @@ Phaser.Pointer.prototype = { }, - /** + /** * The Pointer is considered justReleased if the time it left the touchscreen is less than justReleasedRate. + * Note that calling justReleased doesn't reset the pressed status of the Pointer, it will return `true` for as long as the duration is valid. + * If you wish to check if the Pointer was released just once then see the Sprite.events.onInputUp event. * @method Phaser.Pointer#justReleased - * @param {number} [duration] - * @return {boolean} + * @param {number} [duration] - The time to check against. If none given it will use InputManager.justReleasedRate. + * @return {boolean} true if the Pointer was released within the duration given. */ justReleased: function (duration) { @@ -574,13 +553,13 @@ Phaser.Pointer.prototype = { }, - /** + /** * Resets the Pointer properties. Called by InputManager.reset when you perform a State change. * @method Phaser.Pointer#reset */ reset: function () { - if (this.isMouse == false) + if (this.isMouse === false) { this.active = false; } @@ -600,15 +579,6 @@ Phaser.Pointer.prototype = { this.targetObject = null; - }, - - /** - * Returns a string representation of this object. - * @method Phaser.Pointer#toString - * @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 + ")}]"; } }; @@ -644,7 +614,7 @@ Object.defineProperty(Phaser.Pointer.prototype, "worldX", { get: function () { - return this.game.world.camera.x + this.x; + return this.game.world.camera.x + this.x; } @@ -660,7 +630,7 @@ Object.defineProperty(Phaser.Pointer.prototype, "worldY", { get: function () { - return this.game.world.camera.y + this.y; + return this.game.world.camera.y + this.y; } diff --git a/src/input/Touch.js b/src/input/Touch.js index 1cf58659..1be40ee1 100644 --- a/src/input/Touch.js +++ b/src/input/Touch.js @@ -15,70 +15,102 @@ Phaser.Touch = function (game) { /** - * @property {Phaser.Game} game - Local reference to game. + * @property {Phaser.Game} game - A reference to the currently running game. */ this.game = game; /** - * You can disable all Input by setting disabled = true. While set all new input related events will be ignored. - * @method Phaser.Touch#disabled + * @property {boolean} disabled - You can disable all Touch events by setting disabled = true. While set all new touch events will be ignored. * @return {boolean} */ this.disabled = false; /** - * @property {Phaser.Game} callbackContext - Description. + * @property {Object} callbackContext - The context under which callbacks are called. */ this.callbackContext = this.game; /** - * @property {Phaser.Game} touchStartCallback - Description. - * @default + * @property {function} touchStartCallback - A callback that can be fired on a touchStart event. */ this.touchStartCallback = null; /** - * @property {Phaser.Game} touchMoveCallback - Description. - * @default + * @property {function} touchMoveCallback - A callback that can be fired on a touchMove event. */ this.touchMoveCallback = null; /** - * @property {Phaser.Game} touchEndCallback - Description. - * @default + * @property {function} touchEndCallback - A callback that can be fired on a touchEnd event. */ this.touchEndCallback = null; /** - * @property {Phaser.Game} touchEnterCallback - Description. - * @default + * @property {function} touchEnterCallback - A callback that can be fired on a touchEnter event. */ this.touchEnterCallback = null; /** - * @property {Phaser.Game} touchLeaveCallback - Description. - * @default + * @property {function} touchLeaveCallback - A callback that can be fired on a touchLeave event. */ this.touchLeaveCallback = null; /** - * @property {Description} touchCancelCallback - Description. - * @default + * @property {function} touchCancelCallback - A callback that can be fired on a touchCancel event. */ this.touchCancelCallback = null; /** - * @property {boolean} preventDefault - Description. + * @property {boolean} preventDefault - If true the TouchEvent will have prevent.default called on it. * @default */ this.preventDefault = true; + /** + * @property {TouchEvent} event - The browser touch event. + */ + this.event = null; + + /** + * @property {function} _onTouchStart - Internal event handler reference. + * @private + */ this._onTouchStart = null; + + /** + * @property {function} _onTouchMove - Internal event handler reference. + * @private + */ this._onTouchMove = null; + + /** + * @property {function} _onTouchEnd - Internal event handler reference. + * @private + */ this._onTouchEnd = null; + + /** + * @property {function} _onTouchEnter - Internal event handler reference. + * @private + */ this._onTouchEnter = null; + + /** + * @property {function} _onTouchLeave - Internal event handler reference. + * @private + */ this._onTouchLeave = null; + + /** + * @property {function} _onTouchCancel - Internal event handler reference. + * @private + */ this._onTouchCancel = null; + + /** + * @property {function} _onTouchMove - Internal event handler reference. + * @private + */ this._onTouchMove = null; }; @@ -144,12 +176,14 @@ Phaser.Touch.prototype = { }, /** - * Description. + * The internal method that handles the touchstart event from the browser. * @method Phaser.Touch#onTouchStart - * @param {Any} event + * @param {TouchEvent} event - The native event from the browser. This gets stored in Touch.event. */ onTouchStart: function (event) { + this.event = event; + if (this.touchStartCallback) { this.touchStartCallback.call(this.callbackContext, event); @@ -179,10 +213,12 @@ 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. * @method Phaser.Touch#onTouchCancel - * @param {Any} event + * @param {TouchEvent} event - The native event from the browser. This gets stored in Touch.event. */ onTouchCancel: function (event) { + this.event = event; + if (this.touchCancelCallback) { this.touchCancelCallback.call(this.callbackContext, event); @@ -211,10 +247,12 @@ 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. * @method Phaser.Touch#onTouchEnter - * @param {Any} event + * @param {TouchEvent} event - The native event from the browser. This gets stored in Touch.event. */ onTouchEnter: function (event) { + this.event = event; + if (this.touchEnterCallback) { this.touchEnterCallback.call(this.callbackContext, event); @@ -230,10 +268,12 @@ Phaser.Touch.prototype = { event.preventDefault(); } + /* for (var i = 0; i < event.changedTouches.length; i++) { //console.log('touch enter'); } + */ }, @@ -241,10 +281,12 @@ 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. * @method Phaser.Touch#onTouchLeave - * @param {Any} event - */ + * @param {TouchEvent} event - The native event from the browser. This gets stored in Touch.event. + */ onTouchLeave: function (event) { + this.event = event; + if (this.touchLeaveCallback) { this.touchLeaveCallback.call(this.callbackContext, event); @@ -255,20 +297,24 @@ Phaser.Touch.prototype = { event.preventDefault(); } + /* for (var i = 0; i < event.changedTouches.length; i++) { //console.log('touch leave'); } + */ }, /** - * Description. + * The handler for the touchmove events. * @method Phaser.Touch#onTouchMove - * @param {Any} event + * @param {TouchEvent} event - The native event from the browser. This gets stored in Touch.event. */ onTouchMove: function (event) { + this.event = event; + if (this.touchMoveCallback) { this.touchMoveCallback.call(this.callbackContext, event); @@ -287,12 +333,14 @@ Phaser.Touch.prototype = { }, /** - * Description. + * The handler for the touchend events. * @method Phaser.Touch#onTouchEnd - * @param {Any} event + * @param {TouchEvent} event - The native event from the browser. This gets stored in Touch.event. */ onTouchEnd: function (event) { + this.event = event; + if (this.touchEndCallback) { this.touchEndCallback.call(this.callbackContext, event); diff --git a/src/loader/Cache.js b/src/loader/Cache.js index c88bb776..0481db68 100644 --- a/src/loader/Cache.js +++ b/src/loader/Cache.js @@ -588,7 +588,7 @@ Phaser.Cache.prototype = { */ getFrame: function (key) { - if (this._images[key] && this._images[key].spriteSheet == false) + if (this._images[key] && this._images[key].spriteSheet === false) { return this._images[key].frame; } @@ -692,7 +692,7 @@ Phaser.Cache.prototype = { */ isSoundReady: function (key) { - return (this._sounds[key] && this._sounds[key].decoded && this.game.sound.touchLocked == false); + return (this._sounds[key] && this._sounds[key].decoded && this.game.sound.touchLocked === false); }, diff --git a/src/loader/Loader.js b/src/loader/Loader.js index 34cca2e7..e786415d 100644 --- a/src/loader/Loader.js +++ b/src/loader/Loader.js @@ -149,7 +149,7 @@ Phaser.Loader.prototype = { this.preloadSprite = { sprite: sprite, direction: direction, width: sprite.width, height: sprite.height, crop: null }; - if (direction == 0) + if (direction === 0) { // Horizontal crop this.preloadSprite.crop = new Phaser.Rectangle(0, 0, 1, sprite.height); @@ -247,7 +247,7 @@ Phaser.Loader.prototype = { if (typeof overwrite === "undefined") { overwrite = false; } - if (overwrite || this.checkKeyExists(key) == false) + if (overwrite || this.checkKeyExists(key) === false) { this.addToFileList('image', key, url); } @@ -268,7 +268,7 @@ Phaser.Loader.prototype = { if (typeof overwrite === "undefined") { overwrite = false; } - if (overwrite || this.checkKeyExists(key) == false) + if (overwrite || this.checkKeyExists(key) === false) { this.addToFileList('text', key, url); } @@ -1085,7 +1085,7 @@ Phaser.Loader.prototype = { if (this.preloadSprite !== null) { - if (this.preloadSprite.direction == 0) + if (this.preloadSprite.direction === 0) { this.preloadSprite.crop.width = Math.floor((this.preloadSprite.width / 100) * this.progress); } diff --git a/src/math/Math.js b/src/math/Math.js index 334dde0e..13962e74 100644 --- a/src/math/Math.js +++ b/src/math/Math.js @@ -134,7 +134,7 @@ Phaser.Math = { if (typeof start === "undefined") { start = 0; } - if (gap == 0) { + if (gap === 0) { return input; } @@ -160,7 +160,7 @@ Phaser.Math = { if (typeof start === "undefined") { start = 0; } - if (gap == 0) { + if (gap === 0) { return input; } @@ -186,7 +186,7 @@ Phaser.Math = { if (typeof start === "undefined") { start = 0; } - if (gap == 0) { + if (gap === 0) { return input; } @@ -238,7 +238,7 @@ Phaser.Math = { * e.g. * 2000/7 ~= 285.714285714285714285714 ~= (bin)100011101.1011011011011011 * - * roundTo(2000/7,3) == 0 + * roundTo(2000/7,3) === 0 * roundTo(2000/7,2) == 300 * roundTo(2000/7,1) == 290 * roundTo(2000/7,0) == 286 @@ -844,7 +844,7 @@ Phaser.Math = { var l = length; - if ((l == 0) || (l > objects.length - startIndex)) + if ((l === 0) || (l > objects.length - startIndex)) { l = objects.length - startIndex; } @@ -972,7 +972,7 @@ Phaser.Math = { * @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) { var dx = x1 - x2; @@ -991,7 +991,7 @@ Phaser.Math = { * @param {number} x2 * @param {number} y2 * @return {number} The distance between this Point object and the destination Point object. - **/ + */ distanceRounded: function (x1, y1, x2, y2) { return Math.round(Phaser.Math.distance(x1, y1, x2, y2)); diff --git a/src/particles/arcade/Emitter.js b/src/particles/arcade/Emitter.js index 501afcb2..a76e5580 100644 --- a/src/particles/arcade/Emitter.js +++ b/src/particles/arcade/Emitter.js @@ -136,7 +136,7 @@ Phaser.Particles.Arcade.Emitter = function (game, x, y, maxParticles) { this.angularDrag = 0; /** - * How often a particle is emitted in ms (if emitter is started with Explode == false). + * How often a particle is emitted in ms (if emitter is started with Explode === false). * @property {boolean} frequency * @default */ diff --git a/src/physics/advanced/collision/GridBroadphase.js b/src/physics/advanced/collision/GridBroadphase.js index d0a7172b..747d78d6 100644 --- a/src/physics/advanced/collision/GridBroadphase.js +++ b/src/physics/advanced/collision/GridBroadphase.js @@ -104,7 +104,7 @@ GridBroadphase.prototype.getCollisionPairs = function(world){ } } else if(si instanceof Plane){ // Put in all bins for now - if(bi.angle == 0){ + if(bi.angle === 0){ var y = bi.position[1]; for(var j=0; j!==Nbins && ymin+binsizeY*(j-1)1) break; @@ -402,7 +402,7 @@ var day = (a1.y-a2.y), dby = (b1.y-b2.y); var Den = dax*dby - day*dbx; - if (Den == 0) return null; // parallel + if (Den === 0) return null; // parallel var A = (a1.x * a2.y - a1.y * a2.x); var B = (b1.x * b2.y - b1.y * b2.x); @@ -424,7 +424,7 @@ var day = (a1.y-a2.y), dby = (b1.y-b2.y); var Den = dax*dby - day*dbx; - if (Den == 0) return null; // parallel + if (Den === 0) return null; // parallel var A = (a1.x * a2.y - a1.y * a2.x); var B = (b1.x * b2.y - b1.y * b2.x); diff --git a/src/physics/advanced/objects/Body.js b/src/physics/advanced/objects/Body.js index ed1daead..eeaa004d 100644 --- a/src/physics/advanced/objects/Body.js +++ b/src/physics/advanced/objects/Body.js @@ -167,7 +167,7 @@ function Body(options){ * var kinematicBody = new Body(); * kinematicBody.motionState = Body.KINEMATIC; */ - this.motionState = this.mass == 0 ? Body.STATIC : Body.DYNAMIC; + this.motionState = this.mass === 0 ? Body.STATIC : Body.DYNAMIC; /** * Bounding circle radius diff --git a/src/physics/arcade/ArcadePhysics.js b/src/physics/arcade/ArcadePhysics.js index 467832e1..60c76c10 100644 --- a/src/physics/arcade/ArcadePhysics.js +++ b/src/physics/arcade/ArcadePhysics.js @@ -404,7 +404,7 @@ Phaser.Physics.Arcade.prototype = { this._mapData = tilemapLayer.getTiles(sprite.body.x, sprite.body.y, sprite.body.width, sprite.body.height, true); - if (this._mapData.length == 0) + if (this._mapData.length === 0) { return; } @@ -448,12 +448,12 @@ Phaser.Physics.Arcade.prototype = { */ collideGroupVsTilemapLayer: function (group, tilemapLayer, collideCallback, processCallback, callbackContext) { - if (group.length == 0) + if (group.length === 0) { return; } - if (group.length == 0) + if (group.length === 0) { return; } @@ -521,7 +521,7 @@ Phaser.Physics.Arcade.prototype = { */ collideSpriteVsGroup: function (sprite, group, collideCallback, processCallback, callbackContext) { - if (group.length == 0) + if (group.length === 0) { return; } @@ -563,7 +563,7 @@ Phaser.Physics.Arcade.prototype = { */ collideGroupVsGroup: function (group1, group2, collideCallback, processCallback, callbackContext) { - if (group1.length == 0 || group2.length == 0) + if (group1.length === 0 || group2.length === 0) { return; } @@ -620,7 +620,7 @@ Phaser.Physics.Arcade.prototype = { { this._maxOverlap = body1.deltaAbsX() + body2.deltaAbsX() + this.OVERLAP_BIAS; - if (body1.deltaX() == 0 && body2.deltaX() == 0) + if (body1.deltaX() === 0 && body2.deltaX() === 0) { // They overlap but neither of them are moving body1.embedded = true; @@ -631,7 +631,7 @@ Phaser.Physics.Arcade.prototype = { // Body1 is moving right and/or Body2 is moving left this._overlap = body1.x + body1.width - body2.x; - if ((this._overlap > this._maxOverlap) || body1.allowCollision.right == false || body2.allowCollision.left == false) + if ((this._overlap > this._maxOverlap) || body1.allowCollision.right === false || body2.allowCollision.left === false) { this._overlap = 0; } @@ -646,7 +646,7 @@ Phaser.Physics.Arcade.prototype = { // Body1 is moving left and/or Body2 is moving right this._overlap = body1.x - body2.width - body2.x; - if ((-this._overlap > this._maxOverlap) || body1.allowCollision.left == false || body2.allowCollision.right == false) + if ((-this._overlap > this._maxOverlap) || body1.allowCollision.left === false || body2.allowCollision.right === false) { this._overlap = 0; } @@ -728,7 +728,7 @@ Phaser.Physics.Arcade.prototype = { { this._maxOverlap = body1.deltaAbsY() + body2.deltaAbsY() + this.OVERLAP_BIAS; - if (body1.deltaY() == 0 && body2.deltaY() == 0) + if (body1.deltaY() === 0 && body2.deltaY() === 0) { // They overlap but neither of them are moving body1.embedded = true; @@ -739,7 +739,7 @@ Phaser.Physics.Arcade.prototype = { // Body1 is moving down and/or Body2 is moving up this._overlap = body1.y + body1.height - body2.y; - if ((this._overlap > this._maxOverlap) || body1.allowCollision.down == false || body2.allowCollision.up == false) + if ((this._overlap > this._maxOverlap) || body1.allowCollision.down === false || body2.allowCollision.up === false) { this._overlap = 0; } @@ -754,7 +754,7 @@ Phaser.Physics.Arcade.prototype = { // Body1 is moving up and/or Body2 is moving down this._overlap = body1.y - body2.height - body2.y; - if ((-this._overlap > this._maxOverlap) || body1.allowCollision.up == false || body2.allowCollision.down == false) + if ((-this._overlap > this._maxOverlap) || body1.allowCollision.up === false || body2.allowCollision.down === false) { this._overlap = 0; } @@ -852,7 +852,7 @@ Phaser.Physics.Arcade.prototype = { separateTileX: function (body, tile, separate) { // Can't separate two immovable objects (tiles are always immovable) - if (body.immovable || body.deltaX() == 0 || Phaser.Rectangle.intersects(body.hullX, tile) == false) + if (body.immovable || body.deltaX() === 0 || Phaser.Rectangle.intersects(body.hullX, tile) === false) { return false; } @@ -867,8 +867,8 @@ Phaser.Physics.Arcade.prototype = { // Moving left this._overlap = tile.right - body.hullX.x; - // if ((this._overlap > this._maxOverlap) || body.allowCollision.left == false || tile.tile.collideRight == false) - if (body.allowCollision.left == false || tile.tile.collideRight == false) + // if ((this._overlap > this._maxOverlap) || body.allowCollision.left === false || tile.tile.collideRight === false) + if (body.allowCollision.left === false || tile.tile.collideRight === false) { this._overlap = 0; } @@ -882,8 +882,8 @@ Phaser.Physics.Arcade.prototype = { // Moving right this._overlap = body.hullX.right - tile.x; - // if ((this._overlap > this._maxOverlap) || body.allowCollision.right == false || tile.tile.collideLeft == false) - if (body.allowCollision.right == false || tile.tile.collideLeft == false) + // if ((this._overlap > this._maxOverlap) || body.allowCollision.right === false || tile.tile.collideLeft === false) + if (body.allowCollision.right === false || tile.tile.collideLeft === false) { this._overlap = 0; } @@ -907,7 +907,7 @@ Phaser.Physics.Arcade.prototype = { body.x = body.x - this._overlap; } - if (body.bounce.x == 0) + if (body.bounce.x === 0) { body.velocity.x = 0; } @@ -938,7 +938,7 @@ Phaser.Physics.Arcade.prototype = { separateTileY: function (body, tile, separate) { // Can't separate two immovable objects (tiles are always immovable) - if (body.immovable || body.deltaY() == 0 || Phaser.Rectangle.intersects(body.hullY, tile) == false) + if (body.immovable || body.deltaY() === 0 || Phaser.Rectangle.intersects(body.hullY, tile) === false) { return false; } @@ -953,8 +953,8 @@ Phaser.Physics.Arcade.prototype = { // Moving up this._overlap = tile.bottom - body.hullY.y; - // if ((this._overlap > this._maxOverlap) || body.allowCollision.up == false || tile.tile.collideDown == false) - if (body.allowCollision.up == false || tile.tile.collideDown == false) + // if ((this._overlap > this._maxOverlap) || body.allowCollision.up === false || tile.tile.collideDown === false) + if (body.allowCollision.up === false || tile.tile.collideDown === false) { this._overlap = 0; } @@ -968,8 +968,8 @@ Phaser.Physics.Arcade.prototype = { // Moving down this._overlap = body.hullY.bottom - tile.y; - // if ((this._overlap > this._maxOverlap) || body.allowCollision.down == false || tile.tile.collideUp == false) - if (body.allowCollision.down == false || tile.tile.collideUp == false) + // if ((this._overlap > this._maxOverlap) || body.allowCollision.down === false || tile.tile.collideUp === false) + if (body.allowCollision.down === false || tile.tile.collideUp === false) { this._overlap = 0; } @@ -993,7 +993,7 @@ Phaser.Physics.Arcade.prototype = { body.y = body.y - this._overlap; } - if (body.bounce.y == 0) + if (body.bounce.y === 0) { body.velocity.y = 0; } diff --git a/src/physics/arcade/Body.js b/src/physics/arcade/Body.js index eba8cf1a..c8a5edad 100644 --- a/src/physics/arcade/Body.js +++ b/src/physics/arcade/Body.js @@ -380,7 +380,7 @@ Phaser.Physics.Arcade.Body.prototype = { this.updateHulls(); } - if (this.skipQuadTree == false && this.allowCollision.none == false && this.sprite.visible && this.sprite.alive) + if (this.skipQuadTree === false && this.allowCollision.none === false && this.sprite.visible && this.sprite.alive) { this.quadTreeIDs = []; this.quadTreeIndex = -1; @@ -582,7 +582,7 @@ Object.defineProperty(Phaser.Physics.Arcade.Body.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; }, @@ -591,7 +591,7 @@ Object.defineProperty(Phaser.Physics.Arcade.Body.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 * @param {number} value - **/ + */ set: function (value) { if (value <= this.y) @@ -618,7 +618,7 @@ Object.defineProperty(Phaser.Physics.Arcade.Body.prototype, "right", { * However it does affect the width property. * @method right * @return {number} - **/ + */ get: function () { return this.x + this.width; }, @@ -628,7 +628,7 @@ Object.defineProperty(Phaser.Physics.Arcade.Body.prototype, "right", { * However it does affect the width property. * @method right * @param {number} value - **/ + */ set: function (value) { if (value <= this.x) diff --git a/src/pixi/display/DisplayObjectContainer.js b/src/pixi/display/DisplayObjectContainer.js index 09d5b0ce..04a4df59 100644 --- a/src/pixi/display/DisplayObjectContainer.js +++ b/src/pixi/display/DisplayObjectContainer.js @@ -166,7 +166,7 @@ PIXI.DisplayObjectContainer.prototype.addChildAt = function(child, index) updateLast = updateLast.parent; } } - else if(index == 0) + else if(index === 0) { previousObject = this; } diff --git a/src/pixi/extras/Spine.js b/src/pixi/extras/Spine.js index 27995ae6..2249dda5 100644 --- a/src/pixi/extras/Spine.js +++ b/src/pixi/extras/Spine.js @@ -296,7 +296,7 @@ spine.Animation.prototype = { spine.binarySearch = function (values, target, step) { var low = 0; var high = Math.floor(values.length / step) - 2; - if (high == 0) return step; + if (high === 0) return step; var current = high >>> 1; while (true) { if (values[(current + 1) * step] <= target) @@ -368,7 +368,7 @@ spine.Curves.prototype = { var lastY = y - dfy; return lastY + (y - lastY) * (percent - lastX) / (x - lastX); } - if (i == 0) break; + if (i === 0) break; i--; dfx += ddfx; dfy += ddfy; @@ -711,7 +711,7 @@ spine.Skeleton.prototype = { }, /** @return May return null. */ getRootBone: function () { - return this.bones.length == 0 ? null : this.bones[0]; + return this.bones.length === 0 ? null : this.bones[0]; }, /** @return May be null. */ findBone: function (boneName) { @@ -983,7 +983,7 @@ spine.AnimationState.prototype = { entry.loop = loop; if (!delay || delay <= 0) { - var previousAnimation = this.queue.length == 0 ? this.current : this.queue[this.queue.length - 1].animation; + var previousAnimation = this.queue.length === 0 ? this.current : this.queue[this.queue.length - 1].animation; if (previousAnimation != null) delay = previousAnimation.duration - this.data.getMix(previousAnimation, animation) + (delay || 0); else @@ -1232,7 +1232,7 @@ spine.Atlas = function (atlasText, textureLoader) { var line = reader.readLine(); if (line == null) break; line = reader.trim(line); - if (line.length == 0) + if (line.length === 0) page = null; else if (!page) { page = new spine.AtlasPage(); @@ -1421,7 +1421,7 @@ spine.AtlasReader.prototype = { for (; i < 3; i++) { var comma = line.indexOf(",", lastMatch); if (comma == -1) { - if (i == 0) throw "Invalid line: " + line; + if (i === 0) throw "Invalid line: " + line; break; } tuple[i] = this.trim(line.substr(lastMatch, comma - lastMatch)); diff --git a/src/pixi/filters/CrossHatchFilter.js b/src/pixi/filters/CrossHatchFilter.js index 2d26715e..b5009114 100644 --- a/src/pixi/filters/CrossHatchFilter.js +++ b/src/pixi/filters/CrossHatchFilter.js @@ -29,25 +29,25 @@ PIXI.CrossHatchFilter = function() " gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);", " ", " if (lum < 1.00) {", - " if (mod(gl_FragCoord.x + gl_FragCoord.y, 10.0) == 0.0) {", + " if (mod(gl_FragCoord.x + gl_FragCoord.y, 10.0) === 0.0) {", " gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);", " }", " }", " ", " if (lum < 0.75) {", - " if (mod(gl_FragCoord.x - gl_FragCoord.y, 10.0) == 0.0) {", + " if (mod(gl_FragCoord.x - gl_FragCoord.y, 10.0) === 0.0) {", " gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);", " }", " }", " ", " if (lum < 0.50) {", - " if (mod(gl_FragCoord.x + gl_FragCoord.y - 5.0, 10.0) == 0.0) {", + " if (mod(gl_FragCoord.x + gl_FragCoord.y - 5.0, 10.0) === 0.0) {", " gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);", " }", " }", " ", " if (lum < 0.3) {", - " if (mod(gl_FragCoord.x - gl_FragCoord.y - 5.0, 10.0) == 0.0) {", + " if (mod(gl_FragCoord.x - gl_FragCoord.y - 5.0, 10.0) === 0.0) {", " gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);", " }", " }", diff --git a/src/pixi/loaders/AssetLoader.js b/src/pixi/loaders/AssetLoader.js index 57c4e8ab..ee3b016a 100644 --- a/src/pixi/loaders/AssetLoader.js +++ b/src/pixi/loaders/AssetLoader.js @@ -113,7 +113,7 @@ PIXI.AssetLoader.prototype.onAssetLoaded = function() this.dispatchEvent({type: "onProgress", content: this}); if(this.onProgress) this.onProgress(); - if(this.loadCount == 0) + if(this.loadCount === 0) { this.dispatchEvent({type: "onComplete", content: this}); if(this.onComplete) this.onComplete(); diff --git a/src/pixi/primitives/Graphics.js b/src/pixi/primitives/Graphics.js index 8e8c3dd2..0eeb147c 100644 --- a/src/pixi/primitives/Graphics.js +++ b/src/pixi/primitives/Graphics.js @@ -75,7 +75,7 @@ PIXI.Graphics.prototype.constructor = PIXI.Graphics; */ PIXI.Graphics.prototype.lineStyle = function(lineWidth, color, alpha) { - if(this.currentPath.points.length == 0)this.graphicsData.pop(); + if(this.currentPath.points.length === 0)this.graphicsData.pop(); this.lineWidth = lineWidth || 0; this.lineColor = color || 0; @@ -96,7 +96,7 @@ PIXI.Graphics.prototype.lineStyle = function(lineWidth, color, alpha) */ PIXI.Graphics.prototype.moveTo = function(x, y) { - if(this.currentPath.points.length == 0)this.graphicsData.pop(); + if(this.currentPath.points.length === 0)this.graphicsData.pop(); this.currentPath = this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha, fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, points:[], type:PIXI.Graphics.POLY}; @@ -157,7 +157,7 @@ PIXI.Graphics.prototype.endFill = function() */ PIXI.Graphics.prototype.drawRect = function( x, y, width, height ) { - if(this.currentPath.points.length == 0)this.graphicsData.pop(); + if(this.currentPath.points.length === 0)this.graphicsData.pop(); this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha, fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, @@ -177,7 +177,7 @@ PIXI.Graphics.prototype.drawRect = function( x, y, width, height ) */ PIXI.Graphics.prototype.drawCircle = function( x, y, radius) { - if(this.currentPath.points.length == 0)this.graphicsData.pop(); + if(this.currentPath.points.length === 0)this.graphicsData.pop(); this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha, fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, @@ -198,7 +198,7 @@ PIXI.Graphics.prototype.drawCircle = function( x, y, radius) */ PIXI.Graphics.prototype.drawElipse = function( x, y, width, height) { - if(this.currentPath.points.length == 0)this.graphicsData.pop(); + if(this.currentPath.points.length === 0)this.graphicsData.pop(); this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha, fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, diff --git a/src/pixi/renderers/webgl/WebGLBatch.js b/src/pixi/renderers/webgl/WebGLBatch.js index fa09fc43..32f82946 100644 --- a/src/pixi/renderers/webgl/WebGLBatch.js +++ b/src/pixi/renderers/webgl/WebGLBatch.js @@ -9,7 +9,7 @@ PIXI._batchs = []; */ PIXI._getBatch = function(gl) { - if(PIXI._batchs.length == 0) + if(PIXI._batchs.length === 0) { return new PIXI.WebGLBatch(gl); } @@ -189,7 +189,7 @@ PIXI.WebGLBatch.prototype.remove = function(sprite) { this.size--; - if(this.size == 0) + if(this.size === 0) { sprite.batch = null; sprite.__prev = null; @@ -522,7 +522,7 @@ PIXI.WebGLBatch.prototype.render = function(start, end) this.dirty = false; } - if (this.size == 0)return; + if (this.size === 0)return; this.update(); var gl = this.gl; diff --git a/src/pixi/renderers/webgl/WebGLGraphics.js b/src/pixi/renderers/webgl/WebGLGraphics.js index 1d949853..2c4a1284 100644 --- a/src/pixi/renderers/webgl/WebGLGraphics.js +++ b/src/pixi/renderers/webgl/WebGLGraphics.js @@ -280,7 +280,7 @@ PIXI.WebGLGraphics.buildLine = function(graphicsData, webGLData) var wrap = true; var points = graphicsData.points; - if(points.length == 0)return; + if(points.length === 0)return; // if the line width is an odd number add 0.5 to align to a whole pixel if(graphicsData.lineWidth%2) diff --git a/src/pixi/renderers/webgl/WebGLRenderGroup.js b/src/pixi/renderers/webgl/WebGLRenderGroup.js index b0f2da76..83ecf45f 100644 --- a/src/pixi/renderers/webgl/WebGLRenderGroup.js +++ b/src/pixi/renderers/webgl/WebGLRenderGroup.js @@ -775,7 +775,7 @@ PIXI.WebGLRenderGroup.prototype.removeObject = function(displayObject) // ok so.. check to see if you adjacent batchs should be joined. // TODO may optimise? - if(index == 0 || index == this.batchs.length-1) + if(index === 0 || index == this.batchs.length-1) { // wha - eva! just get of the empty batch! this.batchs.splice(index, 1); @@ -848,7 +848,7 @@ PIXI.WebGLRenderGroup.prototype.initTilingSprite = function(sprite) gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, sprite._indexBuffer); gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, sprite.indices, gl.STATIC_DRAW); -// return ( (x > 0) && ((x & (x - 1)) == 0) ); +// return ( (x > 0) && ((x & (x - 1)) === 0) ); if(sprite.texture.baseTexture._glTexture) { diff --git a/src/pixi/renderers/webgl/WebGLRenderer.js b/src/pixi/renderers/webgl/WebGLRenderer.js index e11cd44f..9cdff41c 100644 --- a/src/pixi/renderers/webgl/WebGLRenderer.js +++ b/src/pixi/renderers/webgl/WebGLRenderer.js @@ -111,7 +111,7 @@ PIXI.WebGLRenderer.prototype.constructor = PIXI.WebGLRenderer; */ PIXI.WebGLRenderer.getBatch = function() { - if(PIXI._batchs.length == 0) + if(PIXI._batchs.length === 0) { return new PIXI.WebGLBatch(PIXI.WebGLRenderer.gl); } diff --git a/src/sound/Sound.js b/src/sound/Sound.js index d6ed0946..95dcd13a 100644 --- a/src/sound/Sound.js +++ b/src/sound/Sound.js @@ -432,7 +432,7 @@ Phaser.Sound.prototype = { // console.log(this.name + ' play ' + marker + ' position ' + position + ' volume ' + volume + ' loop ' + loop, 'force', forceRestart); - if (this.isPlaying == true && forceRestart == false && this.override == false) + if (this.isPlaying === true && forceRestart === false && this.override === false) { // Use Restart instead return; @@ -517,7 +517,7 @@ Phaser.Sound.prototype = { this._sound.connect(this.gainNode); this.totalDuration = this._sound.buffer.duration; - if (this.duration == 0) + if (this.duration === 0) { // console.log('duration reset'); this.duration = this.totalDuration; @@ -552,7 +552,7 @@ Phaser.Sound.prototype = { { this.pendingPlayback = true; - if (this.game.cache.getSound(this.key) && this.game.cache.getSound(this.key).isDecoding == false) + if (this.game.cache.getSound(this.key) && this.game.cache.getSound(this.key).isDecoding === false) { this.game.sound.decode(this.key, this); } @@ -576,7 +576,7 @@ Phaser.Sound.prototype = { // This doesn't become available until you call play(), wonderful ... this.totalDuration = this._sound.duration; - if (this.duration == 0) + if (this.duration === 0) { this.duration = this.totalDuration; this.durationMS = this.totalDuration * 1000; diff --git a/src/sound/SoundManager.js b/src/sound/SoundManager.js index f17544ce..2a245714 100644 --- a/src/sound/SoundManager.js +++ b/src/sound/SoundManager.js @@ -101,7 +101,7 @@ Phaser.SoundManager.prototype = { */ boot: function () { - if (this.game.device.iOS && this.game.device.webAudio == false) + if (this.game.device.iOS && this.game.device.webAudio === false) { this.channels = 1; } @@ -123,7 +123,7 @@ Phaser.SoundManager.prototype = { if (window['PhaserGlobal']) { // Check to see if all audio playback is disabled (i.e. handled by a 3rd party class) - if (window['PhaserGlobal'].disableAudio == true) + if (window['PhaserGlobal'].disableAudio === true) { this.usingWebAudio = false; this.noAudio = true; @@ -131,7 +131,7 @@ Phaser.SoundManager.prototype = { } // Check if the Web Audio API is disabled (for testing Audio Tag playback during development) - if (window['PhaserGlobal'].disableWebAudio == true) + if (window['PhaserGlobal'].disableWebAudio === true) { this.usingWebAudio = false; this.usingAudioTag = true; @@ -183,13 +183,13 @@ Phaser.SoundManager.prototype = { */ unlock: function () { - if (this.touchLocked == false) + if (this.touchLocked === false) { return; } // Global override (mostly for Audio Tag testing) - if (this.game.device.webAudio == false || (window['PhaserGlobal'] && window['PhaserGlobal'].disableWebAudio == true)) + if (this.game.device.webAudio === false || (window['PhaserGlobal'] && window['PhaserGlobal'].disableWebAudio === true)) { // Create an Audio tag? this.touchLocked = false; @@ -404,7 +404,7 @@ Object.defineProperty(Phaser.SoundManager.prototype, "mute", { } else { - if (this._muted == false) + if (this._muted === false) { return; } diff --git a/src/system/StageScaleMode.js b/src/system/StageScaleMode.js index e0daa50a..8032c7c7 100644 --- a/src/system/StageScaleMode.js +++ b/src/system/StageScaleMode.js @@ -348,7 +348,7 @@ Phaser.StageScaleMode.prototype = { if (typeof orientationImage !== 'undefined') { - if (orientationImage == null || this.game.cache.checkImageKey(orientationImage) == false) + if (orientationImage == null || this.game.cache.checkImageKey(orientationImage) === false) { orientationImage = '__default'; } @@ -411,7 +411,7 @@ Phaser.StageScaleMode.prototype = { this.incorrectOrientation = true; this.enterIncorrectOrientation.dispatch(); - if (this.orientationSprite && this.orientationSprite.visible == false) + if (this.orientationSprite && this.orientationSprite.visible === false) { this.orientationSprite.visible = true; this.game.world.visible = false; @@ -488,9 +488,9 @@ Phaser.StageScaleMode.prototype = { refresh: function () { // We can't do anything about the status bars in iPads, web apps or desktops - if (this.game.device.iPad == false && this.game.device.webApp == false && this.game.device.desktop == false) + if (this.game.device.iPad === false && this.game.device.webApp === false && this.game.device.desktop === false) { - if (this.game.device.android && this.game.device.chrome == false) + if (this.game.device.android && this.game.device.chrome === false) { window.scrollTo(0, 1); } @@ -526,9 +526,9 @@ Phaser.StageScaleMode.prototype = { force = false; } - if (this.game.device.iPad == false && this.game.device.webApp == false && this.game.device.desktop == false) + if (this.game.device.iPad === false && this.game.device.webApp === false && this.game.device.desktop === false) { - if (this.game.device.android && this.game.device.chrome == false) + if (this.game.device.android && this.game.device.chrome === false) { window.scrollTo(0, 1); } @@ -545,7 +545,7 @@ Phaser.StageScaleMode.prototype = { // Set minimum height of content to new window height document.documentElement['style'].minHeight = window.innerHeight + 'px'; - if (this.incorrectOrientation == true) + if (this.incorrectOrientation === true) { this.setMaximum(); } @@ -571,7 +571,7 @@ Phaser.StageScaleMode.prototype = { */ setSize: function () { - if (this.incorrectOrientation == false) + if (this.incorrectOrientation === false) { if (this.maxWidth && this.width > this.maxWidth) { @@ -601,7 +601,7 @@ Phaser.StageScaleMode.prototype = { if (this.pageAlignHorizontally) { - if (this.width < window.innerWidth && this.incorrectOrientation == false) + if (this.width < window.innerWidth && this.incorrectOrientation === false) { this.margin.x = Math.round((window.innerWidth - this.width) / 2); this.game.canvas.style.marginLeft = this.margin.x + 'px'; @@ -615,7 +615,7 @@ Phaser.StageScaleMode.prototype = { if (this.pageAlignVertically) { - if (this.height < window.innerHeight && this.incorrectOrientation == false) + if (this.height < window.innerHeight && this.incorrectOrientation === false) { this.margin.y = Math.round((window.innerHeight - this.height) / 2); this.game.canvas.style.marginTop = this.margin.y + 'px'; @@ -723,7 +723,7 @@ Object.defineProperty(Phaser.StageScaleMode.prototype, "isFullScreen", { Object.defineProperty(Phaser.StageScaleMode.prototype, "isPortrait", { get: function () { - return this.orientation == 0 || this.orientation == 180; + return this.orientation === 0 || this.orientation == 180; } }); diff --git a/src/tilemap/Tile.js b/src/tilemap/Tile.js index fbdb26d6..dced62a3 100644 --- a/src/tilemap/Tile.js +++ b/src/tilemap/Tile.js @@ -191,7 +191,7 @@ Object.defineProperty(Phaser.Tile.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; } @@ -205,7 +205,7 @@ Object.defineProperty(Phaser.Tile.prototype, "right", { * However it does affect the width property. * @method right * @return {number} - **/ + */ get: function () { return this.x + this.width; } diff --git a/src/tilemap/TilemapLayer.js b/src/tilemap/TilemapLayer.js index 1d6b014b..7cc4cbd7 100644 --- a/src/tilemap/TilemapLayer.js +++ b/src/tilemap/TilemapLayer.js @@ -433,7 +433,7 @@ Phaser.TilemapLayer.prototype.getTiles = function (x, y, width, height, collides sx = _tile.width * this.scale.x; sy = _tile.height * this.scale.y; - if (collides == false || (collides && _tile.collideNone == false)) + if (collides === false || (collides && _tile.collideNone === false)) { // convert tile coordinates back to camera space for return var _wx = this._unfixX( wx*sx ) / tileWidth; diff --git a/src/tilemap/TilemapParser.js b/src/tilemap/TilemapParser.js index 4312c55b..638ba60d 100644 --- a/src/tilemap/TilemapParser.js +++ b/src/tilemap/TilemapParser.js @@ -34,7 +34,7 @@ Phaser.TilemapParser = { } // Zero or smaller than tile sizes? - if (width == 0 || height == 0 || width < tileWidth || height < tileHeight || total === 0) + if (width === 0 || height === 0 || width < tileWidth || height < tileHeight || total === 0) { console.warn("Phaser.TilemapParser.tileSet: width/height zero or width/height < given tileWidth/tileHeight"); return null; @@ -103,7 +103,7 @@ Phaser.TilemapParser = { output[i][c] = parseInt(column[c]); } - if (width == 0) + if (width === 0) { width = column.length; } @@ -155,7 +155,7 @@ Phaser.TilemapParser = { for (var t = 0; t < json.layers[i].data.length; t++) { - if (c == 0) + if (c === 0) { row = []; } diff --git a/src/time/Timer.js b/src/time/Timer.js index 2709f878..87cf67e0 100644 --- a/src/time/Timer.js +++ b/src/time/Timer.js @@ -98,7 +98,7 @@ Phaser.Timer.prototype = { for (var i = 0, len = this.events.length; i < len; i++) { - if (this.events[i].dispatched == false && seconds >= this.events[i].delay) + if (this.events[i].dispatched === false && seconds >= this.events[i].delay) { this.events[i].dispatched = true; // this.events[i].callback.apply(this.events[i].callbackContext, this.events[i].args); diff --git a/src/utils/Debug.js b/src/utils/Debug.js index 3ce3beff..a358ad6b 100644 --- a/src/utils/Debug.js +++ b/src/utils/Debug.js @@ -326,7 +326,7 @@ Phaser.Utils.Debug.prototype = { upColor = upColor || 'rgba(255,0,0,0.5)'; color = color || 'rgb(255,255,255)'; - if (hideIfUp == true && pointer.isUp == true) + if (hideIfUp === true && pointer.isUp === true) { return; }