Updating all files to adhere to the JSHint settings and fixing lots of documentation errors on the way.

This commit is contained in:
photonstorm
2013-11-25 03:13:04 +00:00
parent 373b97648d
commit 13a2cc2feb
68 changed files with 4622 additions and 4628 deletions
+2 -2
View File
@@ -35,7 +35,7 @@
"eqnull" : true, // Tolerate use of `== null`. "eqnull" : true, // Tolerate use of `== null`.
"evil" : false, // Tolerate use of `eval`. "evil" : false, // Tolerate use of `eval`.
"expr" : false, // Tolerate `ExpressionStatement` as Programs. "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. "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. "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(){}() );` "immed" : false, // Require immediate invocations to be wrapped in parens e.g. `( function(){}() );`
@@ -69,7 +69,7 @@
"noempty" : true, // Prohibit use of empty blocks. "noempty" : true, // Prohibit use of empty blocks.
"nonew" : true, // Prohibit use of constructors for side-effects. "nonew" : true, // Prohibit use of constructors for side-effects.
"plusplus" : false, // Prohibit use of `++` & `--`. "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`. "sub" : true, // Tolerate all forms of subscript notation besides dot notation e.g. `dict['key']` instead of `dict.key`.
"trailing" : true // Prohibit trailing whitespaces. "trailing" : true // Prohibit trailing whitespaces.
} }
+1 -1
View File
@@ -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: 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: 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: 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 You can view the complete Change Log for all previous versions at https://github.com/photonstorm/phaser/changelog.md
+1 -1
View File
@@ -53,7 +53,7 @@ PIXI.CanvasRenderer.prototype.renderDisplayObject = function(displayObject)
continue; continue;
} }
if (!displayObject.renderable || displayObject.alpha == 0) if (!displayObject.renderable || displayObject.alpha === 0)
{ {
displayObject = displayObject._iNext; displayObject = displayObject._iNext;
continue; continue;
+220 -220
View File
@@ -17,49 +17,49 @@ Phaser.AnimationManager = function (sprite) {
/** /**
* @property {Phaser.Sprite} sprite - A reference to the parent Sprite that owns this AnimationManager. * @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. * @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. * @property {Phaser.Frame} currentFrame - The currently displayed Frame of animation, if any.
* @default * @default
*/ */
this.currentFrame = null; this.currentFrame = null;
/** /**
* @property {boolean} updateIfVisible - Should the animation data continue to update even if the Sprite.visible is set to false. * @property {boolean} updateIfVisible - Should the animation data continue to update even if the Sprite.visible is set to false.
* @default * @default
*/ */
this.updateIfVisible = true; this.updateIfVisible = true;
/** /**
* @property {boolean} isLoaded - Set to true once animation data has been loaded. * @property {boolean} isLoaded - Set to true once animation data has been loaded.
* @default * @default
*/ */
this.isLoaded = false; this.isLoaded = false;
/** /**
* @property {Phaser.FrameData} _frameData - A temp. var for holding the currently playing Animations FrameData. * @property {Phaser.FrameData} _frameData - A temp. var for holding the currently playing Animations FrameData.
* @private * @private
* @default * @default
*/ */
this._frameData = null; this._frameData = null;
/** /**
* @property {object} _anims - An internal object that stores all of the Animation instances. * @property {object} _anims - An internal object that stores all of the Animation instances.
* @private * @private
*/ */
this._anims = {}; this._anims = {};
/** /**
* @property {object} _outputFrames - An internal object to help avoid gc. * @property {object} _outputFrames - An internal object to help avoid gc.
* @private * @private
*/ */
this._outputFrames = []; this._outputFrames = [];
}; };
@@ -73,226 +73,226 @@ Phaser.AnimationManager.prototype = {
* @private * @private
* @param {Phaser.FrameData} frameData - The FrameData set to load. * @param {Phaser.FrameData} frameData - The FrameData set to load.
*/ */
loadFrameData: function (frameData) { loadFrameData: function (frameData) {
this._frameData = frameData; this._frameData = frameData;
this.frame = 0; this.frame = 0;
this.isLoaded = true; this.isLoaded = true;
}, },
/** /**
* Adds a new animation under the given key. Optionally set the frames, frame rate and loop. * 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. * Animations added in this way are played back with the play function.
* *
* @method Phaser.AnimationManager#add * @method Phaser.AnimationManager#add
* @param {string} name - The unique (within this Sprite) name for the animation, i.e. "run", "fire", "walk". * @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 {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 {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} [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? * @param {boolean} [useNumericIndex=true] - Are the given frames using numeric indexes (default) or strings?
* @return {Phaser.Animation} The Animation object that was created. * @return {Phaser.Animation} The Animation object that was created.
*/ */
add: function (name, frames, frameRate, loop, useNumericIndex) { add: function (name, frames, frameRate, loop, useNumericIndex) {
if (this._frameData == null) if (this._frameData == null)
{ {
console.warn('No FrameData available for Phaser.Animation ' + name); console.warn('No FrameData available for Phaser.Animation ' + name);
return; 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 they didn't set the useNumericIndex then let's at least try and guess it
if (typeof useNumericIndex === 'undefined') if (typeof useNumericIndex === 'undefined')
{ {
if (frames && typeof frames[0] === 'number') if (frames && typeof frames[0] === 'number')
{ {
useNumericIndex = true; useNumericIndex = true;
} }
else else
{ {
useNumericIndex = false; useNumericIndex = false;
} }
} }
// Create the signals the AnimationManager will emit // Create the signals the AnimationManager will emit
if (this.sprite.events.onAnimationStart == null) if (this.sprite.events.onAnimationStart == null)
{ {
this.sprite.events.onAnimationStart = new Phaser.Signal(); this.sprite.events.onAnimationStart = new Phaser.Signal();
this.sprite.events.onAnimationComplete = new Phaser.Signal(); this.sprite.events.onAnimationComplete = new Phaser.Signal();
this.sprite.events.onAnimationLoop = 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._anims[name] = new Phaser.Animation(this.game, this.sprite, name, this._frameData, this._outputFrames, frameRate, loop);
this.currentAnim = this._anims[name]; this.currentAnim = this._anims[name];
this.currentFrame = this.currentAnim.currentFrame; this.currentFrame = this.currentAnim.currentFrame;
this.sprite.setTexture(PIXI.TextureCache[this.currentFrame.uuid]); 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 * @method Phaser.AnimationManager#validateFrames
* @param {Array} frames - An array of frames to be validated. * @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) * @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. * @return {boolean} True if all given Frames are valid, otherwise false.
*/ */
validateFrames: function (frames, useNumericIndex) { validateFrames: function (frames, useNumericIndex) {
if (typeof useNumericIndex == 'undefined') { useNumericIndex = true; } if (typeof useNumericIndex == 'undefined') { useNumericIndex = true; }
for (var i = 0; i < frames.length; i++) for (var i = 0; i < frames.length; i++)
{ {
if (useNumericIndex == true) if (useNumericIndex === true)
{ {
if (frames[i] > this._frameData.total) if (frames[i] > this._frameData.total)
{ {
return false; return false;
} }
} }
else else
{ {
if (this._frameData.checkFrameName(frames[i]) == false) if (this._frameData.checkFrameName(frames[i]) === false)
{ {
return 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() * 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. * 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 * @method Phaser.AnimationManager#play
* @param {string} name - The name of the animation to be played, e.g. "fire", "walk", "jump". * @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 {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} [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. * @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. * @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._anims[name])
{ {
if (this.currentAnim == this._anims[name]) if (this.currentAnim == this._anims[name])
{ {
if (this.currentAnim.isPlaying == false) if (this.currentAnim.isPlaying === false)
{ {
this.currentAnim.paused = false; this.currentAnim.paused = false;
return this.currentAnim.play(frameRate, loop, killOnComplete); return this.currentAnim.play(frameRate, loop, killOnComplete);
} }
} }
else else
{ {
this.currentAnim = this._anims[name]; this.currentAnim = this._anims[name];
this.currentAnim.paused = false; this.currentAnim.paused = false;
return this.currentAnim.play(frameRate, loop, killOnComplete); 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. * 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. * The currentAnim property of the AnimationManager is automatically set to the animation given.
* *
* @method Phaser.AnimationManager#stop * @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 {string} [name=null] - The name of the animation to be stopped, e.g. "fire". If none is given the currently running animation is stopped.
* @param {boolean} [resetFrame=false] - When the animation is stopped should the currentFrame be set to the first frame of the animation (true) or paused on the last frame displayed (false) * @param {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: function (name, resetFrame) {
if (typeof resetFrame == 'undefined') { resetFrame = false; } if (typeof resetFrame == 'undefined') { resetFrame = false; }
if (typeof name == 'string') if (typeof name == 'string')
{ {
if (this._anims[name]) if (this._anims[name])
{ {
this.currentAnim = this._anims[name]; this.currentAnim = this._anims[name];
this.currentAnim.stop(resetFrame); this.currentAnim.stop(resetFrame);
} }
} }
else else
{ {
if (this.currentAnim) if (this.currentAnim)
{ {
this.currentAnim.stop(resetFrame); 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. * 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 * @method Phaser.AnimationManager#update
* @protected * @protected
* @return {boolean} True if a new animation frame has been set, otherwise false. * @return {boolean} True if a new animation frame has been set, otherwise false.
*/ */
update: function () { update: function () {
if (this.updateIfVisible && this.sprite.visible == false) if (this.updateIfVisible && this.sprite.visible === false)
{ {
return false; return false;
} }
if (this.currentAnim && this.currentAnim.update() == true) if (this.currentAnim && this.currentAnim.update() === true)
{ {
this.currentFrame = this.currentAnim.currentFrame; this.currentFrame = this.currentAnim.currentFrame;
this.sprite.currentFrame = this.currentFrame; this.sprite.currentFrame = this.currentFrame;
return true; return true;
} }
return false; return false;
}, },
/** /**
* Returns an animation that was previously added by name. * Returns an animation that was previously added by name.
* *
* @method Phaser.AnimationManager#getAnimation * @method Phaser.AnimationManager#getAnimation
* @param {string} name - The name of the animation to be returned, e.g. "fire". * @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. * @return {Phaser.Animation|boolean} The Animation instance, if found, otherwise false.
*/ */
getAnimation: function (name) { getAnimation: function (name) {
if (typeof name == 'string') if (typeof name == 'string')
{ {
if (this._anims[name]) if (this._anims[name])
{ {
return 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. * Refreshes the current frame data back to the parent Sprite and also resets the texture data.
* *
* @method Phaser.AnimationManager#refreshFrame * @method Phaser.AnimationManager#refreshFrame
*/ */
refreshFrame: function () { refreshFrame: function () {
this.sprite.currentFrame = this.currentFrame; 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. * 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. * @property {Phaser.FrameData} frameData - The current animations FrameData.
* @readonly * @readonly
*/ */
Object.defineProperty(Phaser.AnimationManager.prototype, "frameData", { Object.defineProperty(Phaser.AnimationManager.prototype, 'frameData', {
get: function () { get: function () {
return this._frameData; 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. * @property {number} frameTotal - The total number of frames in the currently loaded FrameData, or -1 if no FrameData is loaded.
* @readonly * @readonly
*/ */
Object.defineProperty(Phaser.AnimationManager.prototype, "frameTotal", { Object.defineProperty(Phaser.AnimationManager.prototype, 'frameTotal', {
get: function () { get: function () {
@@ -349,7 +349,7 @@ Object.defineProperty(Phaser.AnimationManager.prototype, "frameTotal", {
* @name Phaser.AnimationManager#paused * @name Phaser.AnimationManager#paused
* @property {boolean} paused - Gets and sets the paused state of the current animation. * @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 () { get: function () {
@@ -369,15 +369,15 @@ Object.defineProperty(Phaser.AnimationManager.prototype, "paused", {
* @name Phaser.AnimationManager#frame * @name Phaser.AnimationManager#frame
* @property {number} frame - Gets or sets the current frame index and updates the Texture Cache for display. * @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 () { get: function () {
if (this.currentFrame) if (this.currentFrame)
{ {
return this._frameIndex; return this._frameIndex;
} }
}, },
set: function (value) { set: function (value) {
@@ -387,7 +387,7 @@ Object.defineProperty(Phaser.AnimationManager.prototype, "frame", {
this.currentFrame = this._frameData.getFrame(value); this.currentFrame = this._frameData.getFrame(value);
this._frameIndex = value; this._frameIndex = value;
this.sprite.currentFrame = this.currentFrame; 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 * @name Phaser.AnimationManager#frameName
* @property {string} frameName - Gets or sets the current frame name and updates the Texture Cache for display. * @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 () { get: function () {
if (this.currentFrame) if (this.currentFrame)
{ {
return this.currentFrame.name; return this.currentFrame.name;
} }
}, },
@@ -416,11 +416,11 @@ Object.defineProperty(Phaser.AnimationManager.prototype, "frameName", {
this.currentFrame = this._frameData.getFrameByName(value); this.currentFrame = this._frameData.getFrameByName(value);
this._frameIndex = this.currentFrame.index; this._frameIndex = this.currentFrame.index;
this.sprite.currentFrame = this.currentFrame; this.sprite.currentFrame = this.currentFrame;
this.sprite.setTexture(PIXI.TextureCache[this.currentFrame.uuid]); this.sprite.setTexture(PIXI.TextureCache[this.currentFrame.uuid]);
} }
else else
{ {
console.warn("Cannot set frameName: " + value); console.warn('Cannot set frameName: ' + value);
} }
} }
+32 -31
View File
@@ -55,7 +55,7 @@ Phaser.AnimationParser = {
} }
// Zero or smaller than frame sizes? // 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"); console.warn("Phaser.AnimationParser.spriteSheet: width/height zero or width/height < given frameWidth/frameHeight");
return null; return null;
@@ -124,13 +124,13 @@ Phaser.AnimationParser = {
newFrame = data.addFrame(new Phaser.Frame( newFrame = data.addFrame(new Phaser.Frame(
i, i,
frames[i].frame.x, frames[i].frame.x,
frames[i].frame.y, frames[i].frame.y,
frames[i].frame.w, frames[i].frame.w,
frames[i].frame.h, frames[i].frame.h,
frames[i].filename, frames[i].filename,
uuid uuid
)); ));
PIXI.TextureCache[uuid] = new PIXI.Texture(PIXI.BaseTextureCache[cacheKey], { PIXI.TextureCache[uuid] = new PIXI.Texture(PIXI.BaseTextureCache[cacheKey], {
x: frames[i].frame.x, x: frames[i].frame.x,
@@ -142,12 +142,12 @@ Phaser.AnimationParser = {
if (frames[i].trimmed) if (frames[i].trimmed)
{ {
newFrame.setTrim( newFrame.setTrim(
frames[i].trimmed, frames[i].trimmed,
frames[i].sourceSize.w, frames[i].sourceSize.w,
frames[i].sourceSize.h, frames[i].sourceSize.h,
frames[i].spriteSourceSize.x, frames[i].spriteSourceSize.x,
frames[i].spriteSourceSize.y, frames[i].spriteSourceSize.y,
frames[i].spriteSourceSize.w, frames[i].spriteSourceSize.w,
frames[i].spriteSourceSize.h frames[i].spriteSourceSize.h
); );
@@ -196,10 +196,10 @@ Phaser.AnimationParser = {
newFrame = data.addFrame(new Phaser.Frame( newFrame = data.addFrame(new Phaser.Frame(
i, i,
frames[key].frame.x, frames[key].frame.x,
frames[key].frame.y, frames[key].frame.y,
frames[key].frame.w, frames[key].frame.w,
frames[key].frame.h, frames[key].frame.h,
key, key,
uuid uuid
)); ));
@@ -214,12 +214,12 @@ Phaser.AnimationParser = {
if (frames[key].trimmed) if (frames[key].trimmed)
{ {
newFrame.setTrim( newFrame.setTrim(
frames[key].trimmed, frames[key].trimmed,
frames[key].sourceSize.w, frames[key].sourceSize.w,
frames[key].sourceSize.h, frames[key].sourceSize.h,
frames[key].spriteSourceSize.x, frames[key].spriteSourceSize.x,
frames[key].spriteSourceSize.y, frames[key].spriteSourceSize.y,
frames[key].spriteSourceSize.w, frames[key].spriteSourceSize.w,
frames[key].spriteSourceSize.h frames[key].spriteSourceSize.h
); );
@@ -261,6 +261,7 @@ Phaser.AnimationParser = {
var newFrame; var newFrame;
var uuid; var uuid;
var name;
var frame; var frame;
var x; var x;
var y; var y;
@@ -278,20 +279,20 @@ Phaser.AnimationParser = {
frame = frames[i].attributes; frame = frames[i].attributes;
name = frame.name.nodeValue; name = frame.name.nodeValue;
x = parseInt(frame.x.nodeValue); x = parseInt(frame.x.nodeValue, 10);
y = parseInt(frame.y.nodeValue); y = parseInt(frame.y.nodeValue, 10);
width = parseInt(frame.width.nodeValue); width = parseInt(frame.width.nodeValue, 10);
height = parseInt(frame.height.nodeValue); height = parseInt(frame.height.nodeValue, 10);
frameX = null; frameX = null;
frameY = null; frameY = null;
if (frame.frameX) if (frame.frameX)
{ {
frameX = Math.abs(parseInt(frame.frameX.nodeValue)); frameX = Math.abs(parseInt(frame.frameX.nodeValue, 10));
frameY = Math.abs(parseInt(frame.frameY.nodeValue)); frameY = Math.abs(parseInt(frame.frameY.nodeValue, 10));
frameWidth = parseInt(frame.frameWidth.nodeValue); frameWidth = parseInt(frame.frameWidth.nodeValue, 10);
frameHeight = parseInt(frame.frameHeight.nodeValue); frameHeight = parseInt(frame.frameHeight.nodeValue, 10);
} }
newFrame = data.addFrame(new Phaser.Frame(i, x, y, width, height, name, uuid)); newFrame = data.addFrame(new Phaser.Frame(i, x, y, width, height, name, uuid));
+94 -94
View File
@@ -19,124 +19,124 @@
*/ */
Phaser.Frame = function (index, x, y, width, height, name, uuid) { 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. * @property {number} index - The index of this Frame within the FrameData set it is being added to.
*/ */
this.index = index; this.index = index;
/** /**
* @property {number} x - X position within the image to cut from. * @property {number} x - X position within the image to cut from.
*/ */
this.x = x; this.x = x;
/** /**
* @property {number} y - Y position within the image to cut from. * @property {number} y - Y position within the image to cut from.
*/ */
this.y = y; this.y = y;
/** /**
* @property {number} width - Width of the frame. * @property {number} width - Width of the frame.
*/ */
this.width = width; this.width = width;
/** /**
* @property {number} height - Height of the frame. * @property {number} height - Height of the frame.
*/ */
this.height = height; this.height = height;
/** /**
* @property {string} name - Useful for Texture Atlas files (is set to the filename value). * @property {string} name - Useful for Texture Atlas files (is set to the filename value).
*/ */
this.name = name; this.name = name;
/** /**
* @property {string} uuid - A link to the PIXI.TextureCache entry. * @property {string} uuid - A link to the PIXI.TextureCache entry.
*/ */
this.uuid = uuid; 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); 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); this.centerY = Math.floor(height / 2);
/** /**
* @property {number} distance - The distance from the top left to the bottom-right of this Frame. * @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); this.distance = Phaser.Math.distance(0, 0, width, height);
/** /**
* @property {boolean} rotated - Rotated? (not yet implemented) * @property {boolean} rotated - Rotated? (not yet implemented)
* @default * @default
*/ */
this.rotated = false; this.rotated = false;
/** /**
* @property {string} rotationDirection - Either 'cw' or 'ccw', rotation is always 90 degrees. * @property {string} rotationDirection - Either 'cw' or 'ccw', rotation is always 90 degrees.
* @default 'cw' * @default 'cw'
*/ */
this.rotationDirection = 'cw'; this.rotationDirection = 'cw';
/** /**
* @property {boolean} trimmed - Was it trimmed when packed? * @property {boolean} trimmed - Was it trimmed when packed?
* @default * @default
*/ */
this.trimmed = false; this.trimmed = false;
/** /**
* @property {number} sourceSizeW - Width of the original sprite. * @property {number} sourceSizeW - Width of the original sprite.
*/ */
this.sourceSizeW = width; this.sourceSizeW = width;
/** /**
* @property {number} sourceSizeH - Height of the original sprite. * @property {number} sourceSizeH - Height of the original sprite.
*/ */
this.sourceSizeH = height; this.sourceSizeH = height;
/** /**
* @property {number} spriteSourceSizeX - X position of the trimmed sprite inside original sprite. * @property {number} spriteSourceSizeX - X position of the trimmed sprite inside original sprite.
* @default * @default
*/ */
this.spriteSourceSizeX = 0; this.spriteSourceSizeX = 0;
/** /**
* @property {number} spriteSourceSizeY - Y position of the trimmed sprite inside original sprite. * @property {number} spriteSourceSizeY - Y position of the trimmed sprite inside original sprite.
* @default * @default
*/ */
this.spriteSourceSizeY = 0; this.spriteSourceSizeY = 0;
/** /**
* @property {number} spriteSourceSizeW - Width of the trimmed sprite. * @property {number} spriteSourceSizeW - Width of the trimmed sprite.
* @default * @default
*/ */
this.spriteSourceSizeW = 0; this.spriteSourceSizeW = 0;
/** /**
* @property {number} spriteSourceSizeH - Height of the trimmed sprite. * @property {number} spriteSourceSizeH - Height of the trimmed sprite.
* @default * @default
*/ */
this.spriteSourceSizeH = 0; this.spriteSourceSizeH = 0;
}; };
Phaser.Frame.prototype = { Phaser.Frame.prototype = {
/** /**
* If the frame was trimmed when added to the Texture Atlas this records the trim and source data. * If the frame was trimmed when added to the Texture Atlas this records the trim and source data.
* *
* @method Phaser.Frame#setTrim * @method Phaser.Frame#setTrim
* @param {boolean} trimmed - If this frame was trimmed or not. * @param {boolean} trimmed - If this frame was trimmed or not.
* @param {number} actualWidth - The width of the frame before being trimmed. * @param {number} actualWidth - The width of the frame before being trimmed.
* @param {number} actualHeight - The height 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} 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} 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} destWidth - The destination width of the trimmed frame for display.
* @param {number} destHeight - The destination height 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) { setTrim: function (trimmed, actualWidth, actualHeight, destX, destY, destWidth, destHeight) {
this.trimmed = trimmed; this.trimmed = trimmed;
@@ -147,8 +147,8 @@ Phaser.Frame.prototype = {
this.height = actualHeight; this.height = actualHeight;
this.sourceSizeW = actualWidth; this.sourceSizeW = actualWidth;
this.sourceSizeH = actualHeight; this.sourceSizeH = actualHeight;
this.centerX = Math.floor(actualWidth / 2); this.centerX = Math.floor(actualWidth / 2);
this.centerY = Math.floor(actualHeight / 2); this.centerY = Math.floor(actualHeight / 2);
this.spriteSourceSizeX = destX; this.spriteSourceSizeX = destX;
this.spriteSourceSizeY = destY; this.spriteSourceSizeY = destY;
this.spriteSourceSizeW = destWidth; this.spriteSourceSizeW = destWidth;
+24 -24
View File
@@ -12,17 +12,17 @@
*/ */
Phaser.FrameData = function () { Phaser.FrameData = function () {
/** /**
* @property {Array} _frames - Local array of frames. * @property {Array} _frames - Local array of frames.
* @private * @private
*/ */
this._frames = []; this._frames = [];
/** /**
* @property {Array} _frameNames - Local array of frame names for name to index conversions. * @property {Array} _frameNames - Local array of frame names for name to index conversions.
* @private * @private
*/ */
this._frameNames = []; 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 * @method Phaser.FrameData#getFrame
* @param {number} index - The index of the frame you want to get. * @param {number} index - The index of the frame you want to get.
* @return {Phaser.Frame} The frame, if found. * @return {Phaser.Frame} The frame, if found.
*/ */
getFrame: function (index) { getFrame: function (index) {
if (this._frames.length > 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 * @method Phaser.FrameData#getFrameRange
* @param {number} start - The starting frame index. * @param {number} start - The starting frame index.
* @param {number} end - The ending 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. * @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. * @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) { getFrameRange: function (start, end, output) {
if (typeof output === "undefined") { 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. * The frames are returned in the output array, or if none is provided in a new Array object.
* *
* @method Phaser.FrameData#getFrames * @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 {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. * @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. * @return {Array} An array of all Frames in this FrameData set matching the given names or IDs.
*/ */
getFrames: function (frames, useNumericIndex, output) { getFrames: function (frames, useNumericIndex, output) {
if (typeof useNumericIndex === "undefined") { useNumericIndex = true; } if (typeof useNumericIndex === "undefined") { useNumericIndex = true; }
if (typeof output === "undefined") { output = []; } 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 // No input array, so we loop through all frames
for (var i = 0; i < this._frames.length; i++) for (var i = 0; i < this._frames.length; i++)
@@ -189,7 +189,7 @@ Phaser.FrameData.prototype = {
if (typeof useNumericIndex === "undefined") { useNumericIndex = true; } if (typeof useNumericIndex === "undefined") { useNumericIndex = true; }
if (typeof output === "undefined") { output = []; } 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 // No frames array, so we loop through all frames
for (var i = 0, len = this._frames.length; i < len; i++) for (var i = 0, len = this._frames.length; i < len; i++)
+41 -38
View File
@@ -19,35 +19,35 @@
*/ */
Phaser.Camera = function (game, id, x, y, width, height) { Phaser.Camera = function (game, id, x, y, width, height) {
/** /**
* @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; this.game = game;
/** /**
* @property {Phaser.World} world - A reference to the game world. * @property {Phaser.World} world - A reference to the game world.
*/ */
this.world = game.world; this.world = game.world;
/** /**
* @property {number} id - Reserved for future multiple camera set-ups. * @property {number} id - Reserved for future multiple camera set-ups.
* @default * @default
*/ */
this.id = 0; this.id = 0;
/** /**
* Camera view. * Camera view.
* The view into the world we wish to render (by default the game dimensions). * 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. * 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?). * 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); this.view = new Phaser.Rectangle(x, y, width, height);
/** /**
* @property {Phaser.Rectangle} screenView - Used by Sprites to work out Camera culling. * @property {Phaser.Rectangle} screenView - Used by Sprites to work out Camera culling.
*/ */
this.screenView = new Phaser.Rectangle(x, y, width, height); 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. * 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); 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; this.deadzone = null;
/** /**
* @property {boolean} visible - Whether this camera is visible or not. * @property {boolean} visible - Whether this camera is visible or not.
* @default * @default
*/ */
this.visible = true; 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 }; 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 * @default
*/ */
this.target = null; this.target = null;
/** /**
* @property {number} edge - Edge property. * @property {number} edge - Edge property.
* @private * @private
* @default * @default
*/ */
this._edge = 0; this._edge = 0;
this.displayObject = null; this.displayObject = null;
}; };
/** /**
@@ -116,7 +116,7 @@ Phaser.Camera.FOLLOW_TOPDOWN_TIGHT = 3;
Phaser.Camera.prototype = { Phaser.Camera.prototype = {
/** /**
* Tells this camera which sprite to follow. * Tells this camera which sprite to follow.
* @method Phaser.Camera#follow * @method Phaser.Camera#follow
* @param {Phaser.Sprite} target - The object you want the camera to track. Set to null to not follow anything. * @param {Phaser.Sprite} target - The object you want the camera to track. Set to null to not follow anything.
@@ -149,6 +149,9 @@ Phaser.Camera.prototype = {
break; break;
case Phaser.Camera.FOLLOW_LOCKON: case Phaser.Camera.FOLLOW_LOCKON:
this.deadzone = null;
break;
default: default:
this.deadzone = null; this.deadzone = null;
break; break;
@@ -167,7 +170,7 @@ Phaser.Camera.prototype = {
}, },
/** /**
* Move the camera focus on a location instantly. * Move the camera focus on a location instantly.
* @method Phaser.Camera#focusOnXY * @method Phaser.Camera#focusOnXY
* @param {number} x - X position. * @param {number} x - X position.
@@ -179,7 +182,7 @@ Phaser.Camera.prototype = {
}, },
/** /**
* Update focusing and scrolling. * Update focusing and scrolling.
* @method Phaser.Camera#update * @method Phaser.Camera#update
*/ */
@@ -348,7 +351,7 @@ Object.defineProperty(Phaser.Camera.prototype, "x", {
* @property {number} y - Gets or sets the cameras y position. * @property {number} y - Gets or sets the cameras y position.
*/ */
Object.defineProperty(Phaser.Camera.prototype, "y", { Object.defineProperty(Phaser.Camera.prototype, "y", {
get: function () { get: function () {
return this.view.y; return this.view.y;
}, },
+4 -4
View File
@@ -16,9 +16,9 @@
*/ */
Phaser.Filter = function (game, uniforms, fragmentSrc) { 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; this.game = game;
/** /**
@@ -86,7 +86,7 @@ Phaser.Filter.prototype = {
this.uniforms.mouse.y = pointer.y; this.uniforms.mouse.y = pointer.y;
} }
this.uniforms.time.value = this.game.time.totalElapsedSeconds(); this.uniforms.time.value = this.game.time.totalElapsedSeconds();
}, },
+313 -313
View File
@@ -24,380 +24,380 @@
*/ */
Phaser.Game = function (width, height, renderer, parent, state, transparent, antialias) { Phaser.Game = function (width, height, renderer, parent, state, transparent, antialias) {
width = width || 800; width = width || 800;
height = height || 600; height = height || 600;
renderer = renderer || Phaser.AUTO; renderer = renderer || Phaser.AUTO;
parent = parent || ''; parent = parent || '';
state = state || null; state = state || null;
if (typeof transparent == 'undefined') { transparent = false; } if (typeof transparent == 'undefined') { transparent = false; }
if (typeof antialias == 'undefined') { antialias = true; } if (typeof antialias == 'undefined') { antialias = true; }
/** /**
* @property {number} id - Phaser Game ID (for when Pixi supports multiple instances). * @property {number} id - Phaser Game ID (for when Pixi supports multiple instances).
*/ */
this.id = Phaser.GAMES.push(this) - 1; this.id = Phaser.GAMES.push(this) - 1;
/** /**
* @property {HTMLElement} parent - The Games DOM parent. * @property {HTMLElement} parent - The Games DOM parent.
*/ */
this.parent = 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). * @property {number} width - The Game width (in pixels).
*/ */
this.width = width; this.width = width;
/** /**
* @property {number} height - The Game height (in pixels). * @property {number} height - The Game height (in pixels).
*/ */
this.height = height; this.height = height;
/** /**
* @property {boolean} transparent - Use a transparent canvas background or not. * @property {boolean} transparent - Use a transparent canvas background or not.
*/ */
this.transparent = transparent; this.transparent = transparent;
/** /**
* @property {boolean} antialias - Anti-alias graphics (in WebGL this helps with edges, in Canvas2D it retains pixel-art quality). * @property {boolean} antialias - Anti-alias graphics (in WebGL this helps with edges, in Canvas2D it retains pixel-art quality).
*/ */
this.antialias = antialias; this.antialias = antialias;
/** /**
* @property {number} renderer - The Pixi Renderer * @property {number} renderer - The Pixi Renderer
* @default * @default
*/ */
this.renderer = null; this.renderer = null;
/** /**
* @property {number} state - The StateManager. * @property {number} state - The StateManager.
*/ */
this.state = new Phaser.StateManager(this, state); this.state = new Phaser.StateManager(this, state);
/** /**
* @property {boolean} _paused - Is game paused? * @property {boolean} _paused - Is game paused?
* @private * @private
* @default * @default
*/ */
this._paused = false; this._paused = false;
/** /**
* @property {number} renderType - The Renderer this Phaser.Game will use. Either Phaser.RENDERER_AUTO, Phaser.RENDERER_CANVAS or Phaser.RENDERER_WEBGL. * @property {number} renderType - The Renderer this Phaser.Game will use. Either Phaser.RENDERER_AUTO, Phaser.RENDERER_CANVAS or Phaser.RENDERER_WEBGL.
*/ */
this.renderType = renderer; this.renderType = renderer;
/** /**
* @property {boolean} _loadComplete - Whether load complete loading or not. * @property {boolean} _loadComplete - Whether load complete loading or not.
* @private * @private
* @default * @default
*/ */
this._loadComplete = false; this._loadComplete = false;
/** /**
* @property {boolean} isBooted - Whether the game engine is booted, aka available. * @property {boolean} isBooted - Whether the game engine is booted, aka available.
* @default * @default
*/ */
this.isBooted = false; this.isBooted = false;
/** /**
* @property {boolean} id -Is game running or paused? * @property {boolean} id -Is game running or paused?
* @default * @default
*/ */
this.isRunning = false; this.isRunning = false;
/** /**
* @property {Phaser.RequestAnimationFrame} raf - Automatically handles the core game loop via requestAnimationFrame or setTimeout * @property {Phaser.RequestAnimationFrame} raf - Automatically handles the core game loop via requestAnimationFrame or setTimeout
* @default * @default
*/ */
this.raf = null; this.raf = null;
/** /**
* @property {Phaser.GameObjectFactory} add - Reference to the GameObject Factory. * @property {Phaser.GameObjectFactory} add - Reference to the GameObject Factory.
* @default * @default
*/ */
this.add = null; this.add = null;
/** /**
* @property {Phaser.Cache} cache - Reference to the assets cache. * @property {Phaser.Cache} cache - Reference to the assets cache.
* @default * @default
*/ */
this.cache = null; this.cache = null;
/** /**
* @property {Phaser.Input} input - Reference to the input manager * @property {Phaser.Input} input - Reference to the input manager
* @default * @default
*/ */
this.input = null; this.input = null;
/** /**
* @property {Phaser.Loader} load - Reference to the assets loader. * @property {Phaser.Loader} load - Reference to the assets loader.
* @default * @default
*/ */
this.load = null; this.load = null;
/** /**
* @property {Phaser.Math} math - Reference to the math helper. * @property {Phaser.Math} math - Reference to the math helper.
* @default * @default
*/ */
this.math = null; this.math = null;
/** /**
* @property {Phaser.Net} net - Reference to the network class. * @property {Phaser.Net} net - Reference to the network class.
* @default * @default
*/ */
this.net = null; this.net = null;
/** /**
* @property {Phaser.SoundManager} sound - Reference to the sound manager. * @property {Phaser.SoundManager} sound - Reference to the sound manager.
* @default * @default
*/ */
this.sound = null; this.sound = null;
/** /**
* @property {Phaser.Stage} stage - Reference to the stage. * @property {Phaser.Stage} stage - Reference to the stage.
* @default * @default
*/ */
this.stage = null; this.stage = null;
/** /**
* @property {Phaser.TimeManager} time - Reference to game clock. * @property {Phaser.TimeManager} time - Reference to game clock.
* @default * @default
*/ */
this.time = null; this.time = null;
/** /**
* @property {Phaser.TweenManager} tweens - Reference to the tween manager. * @property {Phaser.TweenManager} tweens - Reference to the tween manager.
* @default * @default
*/ */
this.tweens = null; this.tweens = null;
/** /**
* @property {Phaser.World} world - Reference to the world. * @property {Phaser.World} world - Reference to the world.
* @default * @default
*/ */
this.world = null; this.world = null;
/** /**
* @property {Phaser.Physics.PhysicsManager} physics - Reference to the physics manager. * @property {Phaser.Physics.PhysicsManager} physics - Reference to the physics manager.
* @default * @default
*/ */
this.physics = null; this.physics = null;
/** /**
* @property {Phaser.RandomDataGenerator} rnd - Instance of repeatable random data generator helper. * @property {Phaser.RandomDataGenerator} rnd - Instance of repeatable random data generator helper.
* @default * @default
*/ */
this.rnd = null; this.rnd = null;
/** /**
* @property {Phaser.Device} device - Contains device information and capabilities. * @property {Phaser.Device} device - Contains device information and capabilities.
* @default * @default
*/ */
this.device = null; this.device = null;
/** /**
* @property {Phaser.Physics.PhysicsManager} camera - A handy reference to world.camera. * @property {Phaser.Physics.PhysicsManager} camera - A handy reference to world.camera.
* @default * @default
*/ */
this.camera = null; this.camera = null;
/** /**
* @property {HTMLCanvasElement} canvas - A handy reference to renderer.view. * @property {HTMLCanvasElement} canvas - A handy reference to renderer.view.
* @default * @default
*/ */
this.canvas = null; this.canvas = null;
/**
* @property {Context} context - A handy reference to renderer.context (only set for CANVAS games)
* @default
*/
this.context = null;
/** /**
* @property {Phaser.Utils.Debug} debug - A set of useful debug utilitie. * @property {Context} context - A handy reference to renderer.context (only set for CANVAS games)
* @default * @default
*/ */
this.debug = null; this.context = null;
/** /**
* @property {Phaser.Particles} particles - The Particle Manager. * @property {Phaser.Utils.Debug} debug - A set of useful debug utilitie.
* @default * @default
*/ */
this.particles = null; this.debug = null;
var _this = this; /**
* @property {Phaser.Particles} particles - The Particle Manager.
* @default
*/
this.particles = null;
var _this = this;
this._onBoot = function () { this._onBoot = function () {
return _this.boot(); return _this.boot();
} }
if (document.readyState === 'complete' || document.readyState === 'interactive') if (document.readyState === 'complete' || document.readyState === 'interactive')
{ {
window.setTimeout(this._onBoot, 0); window.setTimeout(this._onBoot, 0);
} }
else else
{ {
document.addEventListener('DOMContentLoaded', this._onBoot, false); document.addEventListener('DOMContentLoaded', this._onBoot, false);
window.addEventListener('load', this._onBoot, false); window.addEventListener('load', this._onBoot, false);
} }
return this; return this;
}; };
Phaser.Game.prototype = { Phaser.Game.prototype = {
/** /**
* Initialize engine sub modules and start the game. * Initialize engine sub modules and start the game.
* *
* @method Phaser.Game#boot * @method Phaser.Game#boot
* @protected * @protected
*/ */
boot: function () { boot: function () {
if (this.isBooted) if (this.isBooted)
{ {
return; return;
} }
if (!document.body) if (!document.body)
{ {
window.setTimeout(this._onBoot, 20); window.setTimeout(this._onBoot, 20);
} }
else else
{ {
document.removeEventListener('DOMContentLoaded', this._onBoot); document.removeEventListener('DOMContentLoaded', this._onBoot);
window.removeEventListener('load', this._onBoot); window.removeEventListener('load', this._onBoot);
this.onPause = new Phaser.Signal; this.onPause = new Phaser.Signal();
this.onResume = new Phaser.Signal; this.onResume = new Phaser.Signal();
this.isBooted = true; this.isBooted = true;
this.device = new Phaser.Device(); this.device = new Phaser.Device();
this.math = Phaser.Math; this.math = Phaser.Math;
this.rnd = new Phaser.RandomDataGenerator([(Date.now() * Math.random()).toString()]); 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.world = new Phaser.World(this);
this.add = new Phaser.GameObjectFactory(this); this.add = new Phaser.GameObjectFactory(this);
this.cache = new Phaser.Cache(this); this.cache = new Phaser.Cache(this);
this.load = new Phaser.Loader(this); this.load = new Phaser.Loader(this);
this.time = new Phaser.Time(this); this.time = new Phaser.Time(this);
this.tweens = new Phaser.TweenManager(this); this.tweens = new Phaser.TweenManager(this);
this.input = new Phaser.Input(this); this.input = new Phaser.Input(this);
this.sound = new Phaser.SoundManager(this); this.sound = new Phaser.SoundManager(this);
this.physics = new Phaser.Physics.Arcade(this); this.physics = new Phaser.Physics.Arcade(this);
this.particles = new Phaser.Particles(this); this.particles = new Phaser.Particles(this);
this.plugins = new Phaser.PluginManager(this, this); this.plugins = new Phaser.PluginManager(this, this);
this.net = new Phaser.Net(this); this.net = new Phaser.Net(this);
this.debug = new Phaser.Utils.Debug(this); this.debug = new Phaser.Utils.Debug(this);
this.stage.boot(); this.stage.boot();
this.world.boot(); this.world.boot();
this.input.boot(); this.input.boot();
this.sound.boot(); this.sound.boot();
this.state.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._loadComplete = false;
this.raf = new Phaser.RequestAnimationFrame(this); this.raf = new Phaser.RequestAnimationFrame(this);
this.raf.start(); this.raf.start();
} }
}, },
/** /**
* Displays a Phaser version debug header in the console. * Displays a Phaser version debug header in the console.
* *
* @method Phaser.Game#showDebugHeader * @method Phaser.Game#showDebugHeader
* @protected * @protected
*/ */
showDebugHeader: function () { showDebugHeader: function () {
var v = Phaser.DEV_VERSION; var v = Phaser.DEV_VERSION;
var r = 'Canvas'; var r = 'Canvas';
var a = 'HTML Audio'; var a = 'HTML Audio';
if (this.renderType == Phaser.WEBGL) if (this.renderType == Phaser.WEBGL)
{ {
r = 'WebGL'; r = 'WebGL';
} }
if (this.device.webAudio) if (this.device.webAudio)
{ {
a = 'WebAudio'; a = 'WebAudio';
} }
if (this.device.chrome) if (this.device.chrome)
{ {
var args = [ var args = [
'%c %c %c Phaser v' + v + ' - Renderer: ' + r + ' - Audio: ' + a + ' %c %c ', '%c %c %c Phaser v' + v + ' - Renderer: ' + r + ' - Audio: ' + a + ' %c %c ',
'background: #00bff3', 'background: #00bff3',
'background: #0072bc', 'background: #0072bc',
'color: #ffffff; background: #003471', 'color: #ffffff; background: #003471',
'background: #0072bc', 'background: #0072bc',
'background: #00bff3' 'background: #00bff3'
]; ];
console.log.apply(console, args); console.log.apply(console, args);
} }
else else
{ {
console.log('Phaser v' + v + ' - Renderer: ' + r + ' - Audio: ' + a); 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. * Checks if the device is capable of using the requested renderer and sets it up or an alternative if not.
* *
* @method Phaser.Game#setUpRenderer * @method Phaser.Game#setUpRenderer
* @protected * @protected
*/ */
setUpRenderer: function () { setUpRenderer: function () {
if (this.renderType === Phaser.CANVAS || (this.renderType === Phaser.AUTO && this.device.webGL == false)) if (this.renderType === Phaser.CANVAS || (this.renderType === Phaser.AUTO && this.device.webGL === false))
{ {
if (this.device.canvas) if (this.device.canvas)
{ {
this.renderType = Phaser.CANVAS; this.renderType = Phaser.CANVAS;
this.renderer = new PIXI.CanvasRenderer(this.width, this.height, this.stage.canvas, this.transparent); this.renderer = new PIXI.CanvasRenderer(this.width, this.height, this.stage.canvas, this.transparent);
Phaser.Canvas.setSmoothingEnabled(this.renderer.context, this.antialias); Phaser.Canvas.setSmoothingEnabled(this.renderer.context, this.antialias);
this.canvas = this.renderer.view; this.canvas = this.renderer.view;
this.context = this.renderer.context; this.context = this.renderer.context;
} }
else else
{ {
throw new Error('Phaser.Game - cannot create Canvas or WebGL context, aborting.'); throw new Error('Phaser.Game - cannot create Canvas or WebGL context, aborting.');
} }
} }
else else
{ {
// They requested WebGL, and their browser supports it // They requested WebGL, and their browser supports it
this.renderType = Phaser.WEBGL; this.renderType = Phaser.WEBGL;
this.renderer = new PIXI.WebGLRenderer(this.width, this.height, this.stage.canvas, this.transparent, this.antialias); this.renderer = new PIXI.WebGLRenderer(this.width, this.height, this.stage.canvas, this.transparent, this.antialias);
this.canvas = this.renderer.view; this.canvas = this.renderer.view;
this.context = null; this.context = null;
} }
Phaser.Canvas.addToDOM(this.renderer.view, this.parent, true); Phaser.Canvas.addToDOM(this.renderer.view, this.parent, true);
Phaser.Canvas.setTouchAction(this.renderer.view); Phaser.Canvas.setTouchAction(this.renderer.view);
}, },
/** /**
* Called when the load has finished, after preload was run. * Called when the load has finished, after preload was run.
* *
* @method Phaser.Game#loadComplete * @method Phaser.Game#loadComplete
@@ -411,61 +411,61 @@ Phaser.Game.prototype = {
}, },
/** /**
* The core game loop. * The core game loop.
* *
* @method Phaser.Game#update * @method Phaser.Game#update
* @protected * @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) if (this._paused)
{ {
this.renderer.render(this.stage._stage); this.renderer.render(this.stage._stage);
this.plugins.render(); this.plugins.render();
this.state.render(); this.state.render();
} }
else else
{ {
this.plugins.preUpdate(); this.plugins.preUpdate();
this.physics.preUpdate(); this.physics.preUpdate();
this.stage.update(); this.stage.update();
this.input.update(); this.input.update();
this.tweens.update(); this.tweens.update();
this.sound.update(); this.sound.update();
this.world.update(); this.world.update();
this.particles.update(); this.particles.update();
this.state.update(); this.state.update();
this.plugins.update(); this.plugins.update();
this.world.postUpdate(); this.world.postUpdate();
this.plugins.postUpdate(); this.plugins.postUpdate();
this.renderer.render(this.stage._stage); this.renderer.render(this.stage._stage);
this.plugins.render(); this.plugins.render();
this.state.render(); this.state.render();
this.plugins.postRender(); this.plugins.postRender();
} }
}, },
/** /**
* Nuke the entire game from orbit * Nuke the entire game from orbit
* *
* @method Phaser.Game#destroy * @method Phaser.Game#destroy
*/ */
destroy: function () { destroy: function () {
this.raf.stop(); this.raf.stop();
this.input.destroy(); this.input.destroy();
this.state.destroy(); this.state.destroy();
this.state = null; this.state = null;
this.cache = null; this.cache = null;
@@ -495,22 +495,22 @@ Object.defineProperty(Phaser.Game.prototype, "paused", {
set: function (value) { set: function (value) {
if (value === true) if (value === true)
{ {
if (this._paused == false) if (this._paused === false)
{ {
this._paused = true; this._paused = true;
this.onPause.dispatch(this); this.onPause.dispatch(this);
} }
} }
else else
{ {
if (this._paused) if (this._paused)
{ {
this._paused = false; this._paused = false;
this.onResume.dispatch(this); this.onResume.dispatch(this);
} }
} }
} }
+978 -979
View File
File diff suppressed because it is too large Load Diff
+85 -85
View File
@@ -13,141 +13,141 @@
Phaser.LinkedList = function () { Phaser.LinkedList = function () {
/** /**
* @property {object} next - Next element in the list. * @property {object} next - Next element in the list.
* @default * @default
*/ */
this.next = null; this.next = null;
/** /**
* @property {object} prev - Previous element in the list. * @property {object} prev - Previous element in the list.
* @default * @default
*/ */
this.prev = null; this.prev = null;
/** /**
* @property {object} first - First element in the list. * @property {object} first - First element in the list.
* @default * @default
*/ */
this.first = null; this.first = null;
/** /**
* @property {object} last - Last element in the list. * @property {object} last - Last element in the list.
* @default * @default
*/ */
this.last = null; this.last = null;
/** /**
* @property {object} game - Number of elements in the list. * @property {object} game - Number of elements in the list.
* @default * @default
*/ */
this.total = 0; this.total = 0;
}; };
Phaser.LinkedList.prototype = { Phaser.LinkedList.prototype = {
/** /**
* Adds a new element to this linked list. * Adds a new element to this linked list.
* *
* @method Phaser.LinkedList#add * @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. * @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. * @return {object} The child that was added.
*/ */
add: function (child) { add: function (child) {
// If the list is empty // If the list is empty
if (this.total == 0 && this.first == null && this.last == null) if (this.total === 0 && this.first == null && this.last == null)
{ {
this.first = child; this.first = child;
this.last = child; this.last = child;
this.next = child; this.next = child;
child.prev = this; child.prev = this;
this.total++; this.total++;
return child; 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) // 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; 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. * Removes the given element from this linked list if it exists.
* *
* @method Phaser.LinkedList#remove * @method Phaser.LinkedList#remove
* @param {object} child - The child to be removed from the list. * @param {object} child - The child to be removed from the list.
*/ */
remove: function (child) { remove: function (child) {
if (child == this.first) if (child == this.first)
{ {
// It was 'first', make 'first' point to first.next // It was 'first', make 'first' point to first.next
this.first = this.first.next; this.first = this.first.next;
} }
else if (child == this.last) else if (child == this.last)
{ {
// It was 'last', make 'last' point to last.prev // It was 'last', make 'last' point to last.prev
this.last = this.last.prev; this.last = this.last.prev;
} }
if (child.prev) if (child.prev)
{ {
// make child.prev.next point to childs.next instead of child // make child.prev.next point to childs.next instead of child
child.prev.next = child.next; child.prev.next = child.next;
} }
if (child.next) if (child.next)
{ {
// make child.next.prev point to child.prev instead of child // make child.next.prev point to child.prev instead of child
child.next.prev = child.prev; child.next.prev = child.prev;
} }
child.next = child.prev = null; child.next = child.prev = null;
if (this.first == null ) if (this.first == null )
{ {
this.last = 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. * 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. * The function must exist on the member.
* *
* @method Phaser.LinkedList#callAll * @method Phaser.LinkedList#callAll
* @param {function} callback - The function to call. * @param {function} callback - The function to call.
*/ */
callAll: function (callback) { callAll: function (callback) {
if (!this.first || !this.last) if (!this.first || !this.last)
{ {
return; return;
} }
var entity = this.first; var entity = this.first;
do do
{ {
if (entity && entity[callback]) if (entity && entity[callback])
{ {
entity[callback].call(entity); entity[callback].call(entity);
} }
entity = entity.next; entity = entity.next;
} }
while(entity != this.last.next) while(entity != this.last.next)
} }
+23 -23
View File
@@ -17,38 +17,38 @@ Phaser.Plugin = function (game, parent) {
if (typeof parent === 'undefined') { parent = null; } 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; 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; 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. * @property {boolean} active - A Plugin with active=true has its preUpdate and update methods called by the parent, otherwise they are skipped.
* @default * @default
*/ */
this.active = false; 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. * @property {boolean} visible - A Plugin with visible=true has its render and postRender methods called by the parent, otherwise they are skipped.
* @default * @default
*/ */
this.visible = false; this.visible = false;
/** /**
* @property {boolean} hasPreUpdate - A flag to indicate if this plugin has a preUpdate method. * @property {boolean} hasPreUpdate - A flag to indicate if this plugin has a preUpdate method.
* @default * @default
*/ */
this.hasPreUpdate = false; this.hasPreUpdate = false;
/** /**
* @property {boolean} hasUpdate - A flag to indicate if this plugin has an update method. * @property {boolean} hasUpdate - A flag to indicate if this plugin has an update method.
* @default * @default
*/ */
this.hasUpdate = false; this.hasUpdate = false;
/** /**
@@ -58,15 +58,15 @@ Phaser.Plugin = function (game, parent) {
this.hasPostUpdate = false; this.hasPostUpdate = false;
/** /**
* @property {boolean} hasRender - A flag to indicate if this plugin has a render method. * @property {boolean} hasRender - A flag to indicate if this plugin has a render method.
* @default * @default
*/ */
this.hasRender = false; this.hasRender = false;
/** /**
* @property {boolean} hasPostRender - A flag to indicate if this plugin has a postRender method. * @property {boolean} hasPostRender - A flag to indicate if this plugin has a postRender method.
* @default * @default
*/ */
this.hasPostRender = false; this.hasPostRender = false;
}; };
+21 -19
View File
@@ -1,3 +1,5 @@
/* jshint newcap: false */
/** /**
* @author Richard Davey <rich@photonstorm.com> * @author Richard Davey <rich@photonstorm.com>
* @copyright 2013 Photon Storm Ltd. * @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 * @class Phaser.PluginManager
* @classdesc Phaser - PluginManager * @classdesc Phaser - PluginManager
@@ -15,27 +17,27 @@
*/ */
Phaser.PluginManager = function(game, parent) { 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; this.game = game;
/** /**
* @property {Description} _parent - Description. * @property {Description} _parent - Description.
* @private * @private
*/ */
this._parent = parent; this._parent = parent;
/** /**
* @property {array} plugins - Description. * @property {array} plugins - Description.
*/ */
this.plugins = []; this.plugins = [];
/** /**
* @property {array} _pluginsLength - Description. * @property {array} _pluginsLength - Description.
* @private * @private
* @default * @default
*/ */
this._pluginsLength = 0; this._pluginsLength = 0;
}; };
@@ -131,7 +133,7 @@ Phaser.PluginManager.prototype = {
*/ */
remove: function (plugin) { remove: function (plugin) {
if (this._pluginsLength == 0) if (this._pluginsLength === 0)
{ {
return; return;
} }
@@ -170,7 +172,7 @@ Phaser.PluginManager.prototype = {
*/ */
preUpdate: function () { preUpdate: function () {
if (this._pluginsLength == 0) if (this._pluginsLength === 0)
{ {
return; return;
} }
@@ -193,7 +195,7 @@ Phaser.PluginManager.prototype = {
*/ */
update: function () { update: function () {
if (this._pluginsLength == 0) if (this._pluginsLength === 0)
{ {
return; return;
} }
@@ -217,7 +219,7 @@ Phaser.PluginManager.prototype = {
*/ */
postUpdate: function () { postUpdate: function () {
if (this._pluginsLength == 0) if (this._pluginsLength === 0)
{ {
return; return;
} }
@@ -240,7 +242,7 @@ Phaser.PluginManager.prototype = {
*/ */
render: function () { render: function () {
if (this._pluginsLength == 0) if (this._pluginsLength === 0)
{ {
return; return;
} }
@@ -263,7 +265,7 @@ Phaser.PluginManager.prototype = {
*/ */
postRender: function () { postRender: function () {
if (this._pluginsLength == 0) if (this._pluginsLength === 0)
{ {
return; return;
} }
+244 -239
View File
@@ -12,286 +12,291 @@
*/ */
Phaser.Signal = function () { Phaser.Signal = function () {
/** /**
* @property {Array.<Phaser.SignalBinding>} _bindings - Description. * @property {Array.<Phaser.SignalBinding>} _bindings - Description.
* @private * @private
*/ */
this._bindings = []; this._bindings = [];
/** /**
* @property {Description} _prevParams - Description. * @property {Description} _prevParams - Description.
* @private * @private
*/ */
this._prevParams = null; this._prevParams = null;
// enforce dispatch to aways work on same context (#47) // enforce dispatch to aways work on same context (#47)
var self = this; var self = this;
/** /**
* @property {Description} dispatch - Description. * @property {Description} dispatch - Description.
*/ */
this.dispatch = function(){ this.dispatch = function(){
Phaser.Signal.prototype.dispatch.apply(self, arguments); Phaser.Signal.prototype.dispatch.apply(self, arguments);
}; };
}; };
Phaser.Signal.prototype = { Phaser.Signal.prototype = {
/** /**
* If Signal should keep record of previously dispatched parameters and * If Signal should keep record of previously dispatched parameters and
* automatically execute listener during `add()`/`addOnce()` if Signal was * automatically execute listener during `add()`/`addOnce()` if Signal was
* already dispatched before. * already dispatched before.
* @property {boolean} memorize * @property {boolean} memorize
*/ */
memorize: false, memorize: false,
/** /**
* @property {boolean} _shouldPropagate * @property {boolean} _shouldPropagate
* @private * @private
*/ */
_shouldPropagate: true, _shouldPropagate: true,
/** /**
* If Signal is active and should broadcast events. * If Signal is active and should broadcast events.
* <p><strong>IMPORTANT:</strong> Setting this property during a dispatch will only affect the next dispatch, if you want to stop the propagation of a signal use `halt()` instead.</p> * <p><strong>IMPORTANT:</strong> Setting this property during a dispatch will only affect the next dispatch, if you want to stop the propagation of a signal use `halt()` instead.</p>
* @property {boolean} active * @property {boolean} active
* @default * @default
*/ */
active: true, active: true,
/** /**
* @method Phaser.Signal#validateListener * @method Phaser.Signal#validateListener
* @param {function} listener - Signal handler function. * @param {function} listener - Signal handler function.
* @param {Description} fnName - Description. * @param {Description} fnName - Description.
* @private * @private
*/ */
validateListener: function (listener, fnName) { validateListener: function (listener, fnName) {
if (typeof listener !== 'function') { if (typeof listener !== 'function') {
throw new Error( 'listener is a required param of {fn}() and should be a Function.'.replace('{fn}', fnName) ); throw new Error( 'listener is a required param of {fn}() and should be a Function.'.replace('{fn}', fnName) );
} }
}, },
/** /**
* @method Phaser.Signal#_registerListener * @method Phaser.Signal#_registerListener
* @param {function} listener - Signal handler function. * @param {function} listener - Signal handler function.
* @param {boolean} isOnce - Description. * @param {boolean} isOnce - Description.
* @param {object} [listenerContext] - 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). * @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. * @return {Phaser.SignalBinding} An Object representing the binding between the Signal and listener.
* @private * @private
*/ */
_registerListener: function (listener, isOnce, listenerContext, priority) { _registerListener: function (listener, isOnce, listenerContext, priority) {
var prevIndex = this._indexOfListener(listener, listenerContext), var prevIndex = this._indexOfListener(listener, listenerContext),
binding; binding;
if (prevIndex !== -1) { if (prevIndex !== -1) {
binding = this._bindings[prevIndex]; binding = this._bindings[prevIndex];
if (binding.isOnce() !== isOnce) { if (binding.isOnce() !== isOnce) {
throw new Error('You cannot add'+ (isOnce? '' : 'Once') +'() then add'+ (!isOnce? '' : 'Once') +'() the same listener without removing the relationship first.'); throw new Error('You cannot add'+ (isOnce? '' : 'Once') +'() then add'+ (!isOnce? '' : 'Once') +'() the same listener without removing the relationship first.');
} }
} else { } else {
binding = new Phaser.SignalBinding(this, listener, isOnce, listenerContext, priority); binding = new Phaser.SignalBinding(this, listener, isOnce, listenerContext, priority);
this._addBinding(binding); this._addBinding(binding);
} }
if (this.memorize && this._prevParams){ if (this.memorize && this._prevParams){
binding.execute(this._prevParams); binding.execute(this._prevParams);
} }
return binding; return binding;
}, },
/** /**
* @method Phaser.Signal#_addBinding * @method Phaser.Signal#_addBinding
* @param {Phaser.SignalBinding} binding - An Object representing the binding between the Signal and listener. * @param {Phaser.SignalBinding} binding - An Object representing the binding between the Signal and listener.
* @private * @private
*/ */
_addBinding: function (binding) { _addBinding: function (binding) {
//simplified insertion sort //simplified insertion sort
var n = this._bindings.length; var n = this._bindings.length;
do { --n; } while (this._bindings[n] && binding._priority <= this._bindings[n]._priority); do { --n; } while (this._bindings[n] && binding._priority <= this._bindings[n]._priority);
this._bindings.splice(n + 1, 0, binding); this._bindings.splice(n + 1, 0, binding);
}, },
/** /**
* @method Phaser.Signal#_indexOfListener * @method Phaser.Signal#_indexOfListener
* @param {function} listener - Signal handler function. * @param {function} listener - Signal handler function.
* @return {number} Description. * @return {number} Description.
* @private * @private
*/ */
_indexOfListener: function (listener, context) { _indexOfListener: function (listener, context) {
var n = this._bindings.length, var n = this._bindings.length,
cur; cur;
while (n--) { while (n--) {
cur = this._bindings[n]; cur = this._bindings[n];
if (cur._listener === listener && cur.context === context) { if (cur._listener === listener && cur.context === context) {
return n; return n;
} }
} }
return -1; return -1;
}, },
/** /**
* Check if listener was attached to Signal. * Check if listener was attached to Signal.
* *
* @method Phaser.Signal#has * @method Phaser.Signal#has
* @param {Function} listener - Signal handler function. * @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). * @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. * @return {boolean} If Signal has the specified listener.
*/ */
has: function (listener, context) { has: function (listener, context) {
return this._indexOfListener(listener, context) !== -1; return this._indexOfListener(listener, context) !== -1;
}, },
/** /**
* Add a listener to the signal. * Add a listener to the signal.
* *
* @method Phaser.Signal#add * @method Phaser.Signal#add
* @param {function} listener - Signal handler function. * @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 {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). * @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. * @return {Phaser.SignalBinding} An Object representing the binding between the Signal and listener.
*/ */
add: function (listener, listenerContext, priority) { add: function (listener, listenerContext, priority) {
this.validateListener(listener, 'add'); this.validateListener(listener, 'add');
return this._registerListener(listener, false, listenerContext, priority); return this._registerListener(listener, false, listenerContext, priority);
}, },
/** /**
* Add listener to the signal that should be removed after first execution (will be executed only once). * Add listener to the signal that should be removed after first execution (will be executed only once).
* *
* @method Phaser.Signal#addOnce * @method Phaser.Signal#addOnce
* @param {function} listener Signal handler function. * @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 {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) * @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. * @return {Phaser.SignalBinding} An Object representing the binding between the Signal and listener.
*/ */
addOnce: function (listener, listenerContext, priority) { addOnce: function (listener, listenerContext, priority) {
this.validateListener(listener, 'addOnce'); this.validateListener(listener, 'addOnce');
return this._registerListener(listener, true, listenerContext, priority); return this._registerListener(listener, true, listenerContext, priority);
}, },
/** /**
* Remove a single listener from the dispatch queue. * Remove a single listener from the dispatch queue.
* *
* @method Phaser.Signal#remove * @method Phaser.Signal#remove
* @param {function} listener Handler function that should be removed. * @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). * @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. * @return {function} Listener handler function.
*/ */
remove: function (listener, context) { 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) if (i !== -1)
{ {
this._bindings[i]._destroy(); //no reason to a Phaser.SignalBinding exist if it isn't attached to a signal this._bindings[i]._destroy(); //no reason to a Phaser.SignalBinding exist if it isn't attached to a signal
this._bindings.splice(i, 1); this._bindings.splice(i, 1);
} }
return listener; return listener;
}, },
/** /**
* Remove all listeners from the Signal. * Remove all listeners from the Signal.
* *
* @method Phaser.Signal#removeAll * @method Phaser.Signal#removeAll
*/ */
removeAll: function () { removeAll: function () {
var n = this._bindings.length; var n = this._bindings.length;
while (n--) { while (n--) {
this._bindings[n]._destroy(); this._bindings[n]._destroy();
} }
this._bindings.length = 0; this._bindings.length = 0;
}, },
/** /**
* Gets the total number of listeneres attached to ths Signal. * Gets the total number of listeneres attached to ths Signal.
* *
* @method Phaser.Signal#getNumListeners * @method Phaser.Signal#getNumListeners
* @return {number} Number of listeners attached to the Signal. * @return {number} Number of listeners attached to the Signal.
*/ */
getNumListeners: function () { getNumListeners: function () {
return this._bindings.length; return this._bindings.length;
}, },
/** /**
* Stop propagation of the event, blocking the dispatch to next listeners on the queue. * Stop propagation of the event, blocking the dispatch to next listeners on the queue.
* <p><strong>IMPORTANT:</strong> should be called only during signal dispatch, calling it before/after dispatch won't affect signal broadcast.</p> * <p><strong>IMPORTANT:</strong> should be called only during signal dispatch, calling it before/after dispatch won't affect signal broadcast.</p>
* @see Signal.prototype.disable * @see Signal.prototype.disable
* *
* @method Phaser.Signal#halt * @method Phaser.Signal#halt
*/ */
halt: function () { halt: function () {
this._shouldPropagate = false; this._shouldPropagate = false;
}, },
/** /**
* Dispatch/Broadcast Signal to all listeners added to the queue. * Dispatch/Broadcast Signal to all listeners added to the queue.
* *
* @method Phaser.Signal#dispatch * @method Phaser.Signal#dispatch
* @param {any} [params] - Parameters that should be passed to each handler. * @param {...} [params] - Parameters that should be passed to each handler.
*/ */
dispatch: function (params) { dispatch: function () {
if (! this.active) {
return;
}
var paramsArr = Array.prototype.slice.call(arguments), if (!this.active)
n = this._bindings.length, {
bindings; return;
}
if (this.memorize) { var paramsArr = Array.prototype.slice.call(arguments);
this._prevParams = paramsArr; var n = this._bindings.length;
} var bindings;
if (! n) { if (this.memorize)
//should come after memorize {
return; this._prevParams = paramsArr;
} }
bindings = this._bindings.slice(); //clone array in case add/remove items during dispatch if (!n)
this._shouldPropagate = true; //in case `halt` was called before dispatch or during the previous dispatch. {
// Should come after memorize
return;
}
//execute all callbacks until end of the list or until a callback returns `false` or stops propagation bindings = this._bindings.slice(); //clone array in case add/remove items during dispatch
//reverse loop since listeners with higher priority will be added at the end of the list this._shouldPropagate = true; //in case `halt` was called before dispatch or during the previous dispatch.
do { n--; } while (bindings[n] && this._shouldPropagate && bindings[n].execute(paramsArr) !== false);
},
/** //execute all callbacks until end of the list or until a callback returns `false` or stops propagation
* Forget memorized arguments. //reverse loop since listeners with higher priority will be added at the end of the list
* @see Signal.memorize do { n--; } while (bindings[n] && this._shouldPropagate && bindings[n].execute(paramsArr) !== false);
*
* @method Phaser.Signal#forget },
*/
forget: function(){
this._prevParams = null;
},
/** /**
* Remove all bindings from signal and destroy any reference to external objects (destroy Signal object). * Forget memorized arguments.
* <p><strong>IMPORTANT:</strong> calling any method on the signal instance after calling dispose will throw errors.</p> * @see Signal.memorize
* *
* @method Phaser.Signal#dispose * @method Phaser.Signal#forget
*/ */
dispose: function () { forget: function(){
this.removeAll(); this._prevParams = null;
delete this._bindings; },
delete this._prevParams;
},
/** /**
* * Remove all bindings from signal and destroy any reference to external objects (destroy Signal object).
* @method Phaser.Signal#toString * <p><strong>IMPORTANT:</strong> calling any method on the signal instance after calling dispose will throw errors.</p>
* @return {string} String representation of the object. *
*/ * @method Phaser.Signal#dispose
toString: function () { */
return '[Phaser.Signal active:'+ this.active +' numListeners:'+ this.getNumListeners() +']'; dispose: function () {
} this.removeAll();
delete this._bindings;
delete this._prevParams;
},
/**
*
* @method Phaser.Signal#toString
* @return {string} String representation of the object.
*/
toString: function () {
return '[Phaser.Signal active:'+ this.active +' numListeners:'+ this.getNumListeners() +']';
}
}; };
+16 -16
View File
@@ -25,33 +25,33 @@
Phaser.SignalBinding = function (signal, listener, isOnce, listenerContext, priority) { Phaser.SignalBinding = function (signal, listener, isOnce, listenerContext, priority) {
/** /**
* @property {Phaser.Game} _listener - Handler function bound to the signal. * @property {Phaser.Game} _listener - Handler function bound to the signal.
* @private * @private
*/ */
this._listener = listener; this._listener = listener;
/** /**
* @property {boolean} _isOnce - If binding should be executed just once. * @property {boolean} _isOnce - If binding should be executed just once.
* @private * @private
*/ */
this._isOnce = isOnce; 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). * @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 * @memberof SignalBinding.prototype
*/ */
this.context = listenerContext; this.context = listenerContext;
/** /**
* @property {Signal} _signal - Reference to Signal object that listener is currently bound to. * @property {Signal} _signal - Reference to Signal object that listener is currently bound to.
* @private * @private
*/ */
this._signal = signal; this._signal = signal;
/** /**
* @property {number} _priority - Listener priority. * @property {number} _priority - Listener priority.
* @private * @private
*/ */
this._priority = priority || 0; this._priority = priority || 0;
}; };
@@ -62,7 +62,7 @@ Phaser.SignalBinding.prototype = {
* If binding is active and should be executed. * If binding is active and should be executed.
* @property {boolean} active * @property {boolean} active
* @default * @default
*/ */
active: true, active: true,
/** /**
+17 -17
View File
@@ -17,26 +17,26 @@
Phaser.Stage = function (game, width, height) { Phaser.Stage = function (game, width, height) {
/** /**
* @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; this.game = game;
/** /**
* @property {string} game - Background color of the stage (defaults to black). Set via the public backgroundColor property. * @property {string} game - Background color of the stage (defaults to black). Set via the public backgroundColor property.
* @private * @private
* @default 'rgb(0,0,0)' * @default 'rgb(0,0,0)'
*/ */
this._backgroundColor = 'rgb(0,0,0)'; this._backgroundColor = 'rgb(0,0,0)';
/** /**
* @property {Phaser.Point} offset - Get the offset values (for input and other things). * @property {Phaser.Point} offset - Get the offset values (for input and other things).
*/ */
this.offset = new Phaser.Point; this.offset = new Phaser.Point();
/** /**
* @property {HTMLCanvasElement} canvas - Reference to the newly created &lt;canvas&gt; element. * @property {HTMLCanvasElement} canvas - Reference to the newly created &lt;canvas&gt; element.
*/ */
this.canvas = Phaser.Canvas.create(width, height); this.canvas = Phaser.Canvas.create(width, height);
this.canvas.style['-webkit-full-screen'] = 'width: 100%; height: 100%'; 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. * @property {number} scaleMode - The current scaleMode.
*/ */
this.scaleMode = Phaser.StageScaleMode.NO_SCALE; this.scaleMode = Phaser.StageScaleMode.NO_SCALE;
/** /**
@@ -126,7 +126,7 @@ Phaser.Stage.prototype = {
}, },
/** /**
* This method is called when the document visibility is changed. * This method is called when the document visibility is changed.
* @method Phaser.Stage#visibilityChange * @method Phaser.Stage#visibilityChange
* @param {Event} event - Its type will be used to decide whether the game should be paused or not. * @param {Event} event - Its type will be used to decide whether the game should be paused or not.
@@ -138,16 +138,16 @@ Phaser.Stage.prototype = {
return; 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 else
{ {
this.game.paused = false; this.game.paused = false;
} }
}, }
}; };
+43 -43
View File
@@ -15,86 +15,86 @@
Phaser.State = function () { 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; this.game = null;
/** /**
* @property {Phaser.GameObjectFactory} add - Reference to the GameObjectFactory. * @property {Phaser.GameObjectFactory} add - Reference to the GameObjectFactory.
* @default * @default
*/ */
this.add = null; this.add = null;
/** /**
* @property {Phaser.Physics.PhysicsManager} camera - A handy reference to world.camera. * @property {Phaser.Camera} camera - A handy reference to world.camera.
* @default * @default
*/ */
this.camera = null; this.camera = null;
/** /**
* @property {Phaser.Cache} cache - Reference to the assets cache. * @property {Phaser.Cache} cache - Reference to the assets cache.
* @default * @default
*/ */
this.cache = null; this.cache = null;
/** /**
* @property {Phaser.Input} input - Reference to the input manager * @property {Phaser.Input} input - Reference to the input manager
* @default * @default
*/ */
this.input = null; this.input = null;
/** /**
* @property {Phaser.Loader} load - Reference to the assets loader. * @property {Phaser.Loader} load - Reference to the assets loader.
* @default * @default
*/ */
this.load = null; this.load = null;
/** /**
* @property {Phaser.Math} math - Reference to the math helper. * @property {Phaser.Math} math - Reference to the math helper.
* @default * @default
*/ */
this.math = null; this.math = null;
/** /**
* @property {Phaser.SoundManager} sound - Reference to the sound manager. * @property {Phaser.SoundManager} sound - Reference to the sound manager.
* @default * @default
*/ */
this.sound = null; this.sound = null;
/** /**
* @property {Phaser.Stage} stage - Reference to the stage. * @property {Phaser.Stage} stage - Reference to the stage.
* @default * @default
*/ */
this.stage = null; this.stage = null;
/** /**
* @property {Phaser.TimeManager} time - Reference to game clock. * @property {Phaser.TimeManager} time - Reference to game clock.
* @default * @default
*/ */
this.time = null; this.time = null;
/** /**
* @property {Phaser.TweenManager} tweens - Reference to the tween manager. * @property {Phaser.TweenManager} tweens - Reference to the tween manager.
* @default * @default
*/ */
this.tweens = null; this.tweens = null;
/** /**
* @property {Phaser.World} world - Reference to the world. * @property {Phaser.World} world - Reference to the world.
* @default * @default
*/ */
this.world = null; this.world = null;
/** /**
* @property {Description} add - Description. * @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 * @default
*/ */
this.particles = null; this.particles = null;
/** /**
* @property {Phaser.Physics.PhysicsManager} physics - Reference to the physics manager. * @property {Phaser.Physics.PhysicsManager} physics - Reference to the physics manager.
* @default * @default
*/ */
this.physics = null; this.physics = null;
}; };
+259 -310
View File
@@ -1,3 +1,5 @@
/* jshint newcap: false */
/** /**
* @author Richard Davey <rich@photonstorm.com> * @author Richard Davey <rich@photonstorm.com>
* @copyright 2013 Photon Storm Ltd. * @copyright 2013 Photon Storm Ltd.
@@ -14,148 +16,117 @@
*/ */
Phaser.StateManager = function (game, pendingState) { Phaser.StateManager = function (game, pendingState) {
/** /**
* A reference to the currently running game. * @property {Phaser.Game} game - A reference to the currently running game.
* @property {Phaser.Game} game. */
*/ this.game = game;
this.game = game;
/** /**
* Description. * @property {Object} states - The object containing Phaser.States.
* @property {Description} states. */
*/ this.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 = { 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. * The Boot handler is called by Phaser.Game when it first starts up.
* @property {State} _pendingState * @method Phaser.StateManager#boot
* @private * @private
*/ */
_pendingState: null, boot: function () {
/** if (this._pendingState !== null)
* Flag that sets if the State has been created or not. {
* @property {boolean}_created if (typeof this._pendingState === 'string')
* @private {
*/ // State was already added, so just start it
_created: false, 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. * Add a new State.
* @method Phaser.StateManager#add * @method Phaser.StateManager#add
* @param key {string} - A unique key you use to reference this state, i.e. "MainMenu", "Level1". * @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; } if (typeof autoStart === "undefined") { autoStart = false; }
// console.log('Phaser.StateManager.addState', key); var newState;
// console.log(typeof state);
// console.log('autoStart?', autoStart);
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) this.states[key] = newState;
{
// 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; if (autoStart)
{
if (this.game.isBooted)
{
this.start(key);
}
else
{
this._pendingState = key;
}
}
if (autoStart) return newState;
{
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;
}, },
/** /**
* Delete the given state. * Delete the given state.
* @method Phaser.StateManager#remove * @method Phaser.StateManager#remove
* @param {string} key - A unique key you use to reference this state, i.e. "MainMenu", "Level1". * @param {string} key - A unique key you use to reference this state, i.e. "MainMenu", "Level1".
*/ */
remove: function (key) { remove: function (key) {
if (this.current == key) if (this.current == key)
{ {
this.callbackContext = null; this.callbackContext = null;
this.onInitCallback = null; this.onInitCallback = null;
this.onShutDownCallback = null; this.onShutDownCallback = null;
this.onPreloadCallback = null; this.onPreloadCallback = null;
this.onLoadRenderCallback = null; this.onLoadRenderCallback = null;
this.onLoadUpdateCallback = null; this.onLoadUpdateCallback = null;
this.onCreateCallback = null; this.onCreateCallback = null;
this.onUpdateCallback = null; this.onUpdateCallback = null;
this.onRenderCallback = null; this.onRenderCallback = null;
this.onPausedCallback = null; this.onPausedCallback = null;
this.onDestroyCallback = null; this.onDestroyCallback = null;
} }
delete this.states[key]; delete this.states[key];
}, },
/** /**
* Start the given state * Start the given state
* @method Phaser.StateManager#start * @method Phaser.StateManager#start
* @param {string} key - The key of the state you want to 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) { 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 clearWorld === "undefined") { clearWorld = true; }
if (typeof clearCache === "undefined") { clearCache = false; } 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;
this._pendingState = key; return;
return;
} }
if (this.checkState(key) == false) if (this.checkState(key) === false)
{ {
return; return;
} }
else else
{ {
// Already got a state running? // Already got a state running?
if (this.current) if (this.current)
{ {
this.onShutDownCallback.call(this.callbackContext, this.game); this.onShutDownCallback.call(this.callbackContext, this.game);
} }
if (clearWorld) if (clearWorld)
{ {
this.game.tweens.removeAll(); this.game.tweens.removeAll();
this.game.world.destroy(); this.game.world.destroy();
if (clearCache == true) if (clearCache === true)
{ {
this.game.cache.destroy(); this.game.cache.destroy();
} }
} }
this.setCurrentState(key); this.setCurrentState(key);
} }
if (this.onPreloadCallback) if (this.onPreloadCallback)
{ {
// console.log('Preload Callback found');
this.game.load.reset(); this.game.load.reset();
this.onPreloadCallback.call(this.callbackContext, this.game); this.onPreloadCallback.call(this.callbackContext, this.game);
// Is the loader empty? // Is the loader empty?
if (this.game.load.queueSize == 0) if (this.game.load.queueSize === 0)
{ {
// console.log('Loader queue empty');
this.game.loadComplete(); this.game.loadComplete();
} }
else else
{ {
// console.log('Loader started');
// Start the loader going as we have something in the queue // Start the loader going as we have something in the queue
this.game.load.start(); this.game.load.start();
} }
} }
else else
{ {
// console.log('Preload callback not found');
// No init? Then there was nothing to load either // No init? Then there was nothing to load either
this.game.loadComplete(); 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 * @method Phaser.StateManager#dummy
* @private * @private
*/ */
dummy: function () { dummy: function () {
}, },
/** /**
* Description. * Description.
* @method Phaser.StateManager#checkState * @method Phaser.StateManager#checkState
* @param {string} key - The key of the state you want to check. * @param {string} key - The key of the state you want to check.
@@ -331,37 +284,37 @@ Phaser.StateManager.prototype = {
*/ */
checkState: function (key) { checkState: function (key) {
if (this.states[key]) if (this.states[key])
{ {
var valid = false; 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]['loadRender']) { valid = true; }
if (valid == false && this.states[key]['loadUpdate']) { 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]['create']) { valid = true; }
if (valid == false && this.states[key]['update']) { 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]['preRender']) { valid = true; }
if (valid == false && this.states[key]['render']) { 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]['paused']) { valid = true; }
if (valid == false) if (valid === false)
{ {
console.warn("Invalid Phaser State object given. Must contain at least a one of the required functions."); console.warn("Invalid Phaser State object given. Must contain at least a one of the required functions.");
return false; return false;
} }
return true; return true;
} }
else else
{ {
console.warn("Phaser.StateManager - No state found with the key: " + key); console.warn("Phaser.StateManager - No state found with the key: " + key);
return false; return false;
} }
}, },
/** /**
* Links game properties to the State given by the key. * Links game properties to the State given by the key.
* @method Phaser.StateManager#link * @method Phaser.StateManager#link
* @param {string} key - State key. * @param {string} key - State key.
@@ -369,7 +322,6 @@ Phaser.StateManager.prototype = {
*/ */
link: function (key) { link: function (key) {
// console.log('linked');
this.states[key].game = this.game; this.states[key].game = this.game;
this.states[key].add = this.game.add; this.states[key].add = this.game.add;
this.states[key].camera = this.game.camera; 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) * Sets the current State. Should not be called directly (use StateManager.start)
* @method Phaser.StateManager#setCurrentState * @method Phaser.StateManager#setCurrentState
* @param {string} key - State key. * @param {string} key - State key.
* @protected * @protected
*/ */
setCurrentState: function (key) { setCurrentState: function (key) {
this.callbackContext = this.states[key]; this.callbackContext = this.states[key];
this.link(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.onInitCallback = this.states[key]['init'] || this.dummy;
this.onPreloadCallback = this.states[key]['preload'] || null; this.onPreloadCallback = this.states[key]['preload'] || null;
@@ -412,102 +364,99 @@ Phaser.StateManager.prototype = {
this.onRenderCallback = this.states[key]['render'] || null; this.onRenderCallback = this.states[key]['render'] || null;
this.onPausedCallback = this.states[key]['paused'] || 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.onShutDownCallback = this.states[key]['shutdown'] || this.dummy;
this.current = key; this.current = key;
this._created = false; 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 * @protected
*/ */
loadComplete: function () { 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); this.onCreateCallback.call(this.callbackContext, this.game);
} }
else else
{ {
this._created = true; this._created = true;
} }
}, },
/** /**
* @method Phaser.StateManager#update * @method Phaser.StateManager#update
* @protected * @protected
*/ */
update: function () { update: function () {
if (this._created && this.onUpdateCallback) if (this._created && this.onUpdateCallback)
{ {
this.onUpdateCallback.call(this.callbackContext, this.game); this.onUpdateCallback.call(this.callbackContext, this.game);
} }
else else
{ {
if (this.onLoadUpdateCallback) if (this.onLoadUpdateCallback)
{ {
this.onLoadUpdateCallback.call(this.callbackContext, this.game); this.onLoadUpdateCallback.call(this.callbackContext, this.game);
} }
} }
}, },
/** /**
* @method Phaser.StateManager#preRender * @method Phaser.StateManager#preRender
* @protected * @protected
*/ */
preRender: function () { preRender: function () {
if (this.onPreRenderCallback) if (this.onPreRenderCallback)
{ {
this.onPreRenderCallback.call(this.callbackContext, this.game); this.onPreRenderCallback.call(this.callbackContext, this.game);
} }
}, },
/** /**
* @method Phaser.StateManager#render * @method Phaser.StateManager#render
* @protected * @protected
*/ */
render: function () { render: function () {
if (this._created && this.onRenderCallback) if (this._created && this.onRenderCallback)
{ {
if (this.game.renderType === Phaser.CANVAS) if (this.game.renderType === Phaser.CANVAS)
{ {
this.game.context.save(); this.game.context.save();
this.game.context.setTransform(1, 0, 0, 1, 0, 0); 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) if (this.game.renderType === Phaser.CANVAS)
{ {
this.game.context.restore(); this.game.context.restore();
} }
} }
else else
{ {
if (this.onLoadRenderCallback) if (this.onLoadRenderCallback)
{ {
this.onLoadRenderCallback.call(this.callbackContext, this.game); this.onLoadRenderCallback.call(this.callbackContext, this.game);
} }
} }
}, },
/** /**
* Nuke the entire game from orbit * Nuke the entire game from orbit
* @method Phaser.StateManager#destroy * @method Phaser.StateManager#destroy
*/ */
+32 -32
View File
@@ -21,7 +21,7 @@ Phaser.World = function (game) {
/** /**
* @property {Phaser.Point} scale - Replaces the PIXI.Point with a slightly more flexible one. * @property {Phaser.Point} scale - Replaces the PIXI.Point with a slightly more flexible one.
*/ */
this.scale = new Phaser.Point(1, 1); 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. * 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. * 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. * 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. * @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); this.bounds = new Phaser.Rectangle(0, 0, game.width, game.height);
/** /**
* @property {Phaser.Camera} camera - Camera instance. * @property {Phaser.Camera} camera - Camera instance.
*/ */
this.camera = null; this.camera = null;
/** /**
* @property {number} currentRenderOrderID - Reset each frame, keeps a count of the total number of objects updated. * @property {number} currentRenderOrderID - Reset each frame, keeps a count of the total number of objects updated.
*/ */
this.currentRenderOrderID = 0; this.currentRenderOrderID = 0;
}; };
Phaser.World.prototype = Object.create(Phaser.Group.prototype); Phaser.World.prototype = Object.create(Phaser.Group.prototype);
@@ -71,27 +71,27 @@ Phaser.World.prototype.boot = function () {
*/ */
Phaser.World.prototype.update = function () { Phaser.World.prototype.update = function () {
this.currentRenderOrderID = 0; this.currentRenderOrderID = 0;
if (this.game.stage._stage.first._iNext) if (this.game.stage._stage.first._iNext)
{ {
var currentNode = this.game.stage._stage.first._iNext; var currentNode = this.game.stage._stage.first._iNext;
var skipChildren; var skipChildren;
do do
{ {
skipChildren = false; skipChildren = false;
if (currentNode['preUpdate']) if (currentNode['preUpdate'])
{ {
skipChildren = (currentNode.preUpdate() === false); skipChildren = (currentNode.preUpdate() === false);
} }
if (currentNode['update']) if (currentNode['update'])
{ {
skipChildren = (currentNode.update() === false) || skipChildren; skipChildren = (currentNode.update() === false) || skipChildren;
} }
if (skipChildren) if (skipChildren)
{ {
currentNode = currentNode.last._iNext; currentNode = currentNode.last._iNext;
@@ -100,10 +100,10 @@ Phaser.World.prototype.update = function () {
{ {
currentNode = currentNode._iNext; 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; var currentNode = this.game.stage._stage.first._iNext;
do do
{ {
if (currentNode['postUpdate']) if (currentNode['postUpdate'])
{ {
File diff suppressed because it is too large Load Diff
+45 -37
View File
@@ -25,28 +25,28 @@ Phaser.BitmapText = function (game, x, y, text, style) {
text = text || ''; text = text || '';
style = style || ''; style = style || '';
/** /**
* @property {boolean} exists - If exists = false then the Sprite isn't updated by the core game loop or physics subsystem at all. * @property {boolean} exists - If exists = false then the Sprite isn't updated by the core game loop or physics subsystem at all.
* @default * @default
*/ */
this.exists = true; 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. * @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; this.alive = true;
/** /**
* @property {Description} group - Description. * @property {Description} group - Description.
* @default * @default
*/ */
this.group = null; this.group = null;
/** /**
* @property {string} name - Description. * @property {string} name - Description.
* @default * @default
*/ */
this.name = ''; this.name = '';
/** /**
@@ -61,54 +61,62 @@ Phaser.BitmapText = function (game, x, y, text, style) {
*/ */
this.type = Phaser.BITMAPTEXT; this.type = Phaser.BITMAPTEXT;
/** /**
* @property {number} position.x - Description. * @property {number} position.x - Description.
*/ */
this.position.x = x; this.position.x = x;
/** /**
* @property {number} position.y - Description. * @property {number} position.y - Description.
*/ */
this.position.y = y; this.position.y = y;
// Replaces the PIXI.Point with a slightly more flexible one // 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(); this.anchor = new Phaser.Point();
/** /**
* @property {Phaser.Point} scale - Description. * @property {Phaser.Point} scale - Description.
*/ */
this.scale = new Phaser.Point(1, 1); this.scale = new Phaser.Point(1, 1);
// A mini cache for storing all of the calculated values // A mini cache for storing all of the calculated values
/** /**
* @property {function} _cache - Description. * @property {function} _cache - Description.
* @private * @private
*/ */
this._cache = { this._cache = {
dirty: false, dirty: false,
// Transform cache // 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 // The previous calculated position
x: -1, y: -1, x: -1,
y: -1,
// The actual scale values based on the worldTransform // The actual scale values based on the worldTransform
scaleX: 1, scaleY: 1 scaleX: 1,
scaleY: 1
}; };
this._cache.x = this.x; this._cache.x = this.x;
this._cache.y = this.y; this._cache.y = this.y;
/** /**
* @property {boolean} renderable - Description. * @property {boolean} renderable - Description.
* @private * @private
*/ */
this.renderable = true; this.renderable = true;
}; };
+67 -67
View File
@@ -33,67 +33,67 @@ Phaser.Button = function (game, x, y, key, callback, callbackContext, overFrame,
callback = callback || null; callback = callback || null;
callbackContext = callbackContext || this; 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; this.type = Phaser.BUTTON;
/** /**
* @property {string} _onOverFrameName - Internal variable. * @property {string} _onOverFrameName - Internal variable.
* @private * @private
* @default * @default
*/ */
this._onOverFrameName = null; this._onOverFrameName = null;
/** /**
* @property {string} _onOutFrameName - Internal variable. * @property {string} _onOutFrameName - Internal variable.
* @private * @private
* @default * @default
*/ */
this._onOutFrameName = null; this._onOutFrameName = null;
/** /**
* @property {string} _onDownFrameName - Internal variable. * @property {string} _onDownFrameName - Internal variable.
* @private * @private
* @default * @default
*/ */
this._onDownFrameName = null; this._onDownFrameName = null;
/** /**
* @property {string} _onUpFrameName - Internal variable. * @property {string} _onUpFrameName - Internal variable.
* @private * @private
* @default * @default
*/ */
this._onUpFrameName = null; this._onUpFrameName = null;
/** /**
* @property {number} _onOverFrameID - Internal variable. * @property {number} _onOverFrameID - Internal variable.
* @private * @private
* @default * @default
*/ */
this._onOverFrameID = null; this._onOverFrameID = null;
/** /**
* @property {number} _onOutFrameID - Internal variable. * @property {number} _onOutFrameID - Internal variable.
* @private * @private
* @default * @default
*/ */
this._onOutFrameID = null; this._onOutFrameID = null;
/** /**
* @property {number} _onDownFrameID - Internal variable. * @property {number} _onDownFrameID - Internal variable.
* @private * @private
* @default * @default
*/ */
this._onDownFrameID = null; this._onDownFrameID = null;
/** /**
* @property {number} _onUpFrameID - Internal variable. * @property {number} _onUpFrameID - Internal variable.
* @private * @private
* @default * @default
*/ */
this._onUpFrameID = null; this._onUpFrameID = null;
/** /**
@@ -144,25 +144,25 @@ Phaser.Button = function (game, x, y, key, callback, callbackContext, overFrame,
*/ */
this.onUpSoundMarker = ''; this.onUpSoundMarker = '';
/** /**
* @property {Phaser.Signal} onInputOver - The Signal (or event) dispatched when this Button is in an Over state. * @property {Phaser.Signal} onInputOver - The Signal (or event) dispatched when this Button is in an Over state.
*/ */
this.onInputOver = new Phaser.Signal; this.onInputOver = new Phaser.Signal();
/** /**
* @property {Phaser.Signal} onInputOut - The Signal (or event) dispatched when this Button is in an Out state. * @property {Phaser.Signal} onInputOut - The Signal (or event) dispatched when this Button is in an Out state.
*/ */
this.onInputOut = new Phaser.Signal; this.onInputOut = new Phaser.Signal();
/** /**
* @property {Phaser.Signal} onInputDown - The Signal (or event) dispatched when this Button is in an Down state. * @property {Phaser.Signal} onInputDown - The Signal (or event) dispatched when this Button is in an Down state.
*/ */
this.onInputDown = new Phaser.Signal; this.onInputDown = new Phaser.Signal();
/** /**
* @property {Phaser.Signal} onInputUp - The Signal (or event) dispatched when this Button is in an Up state. * @property {Phaser.Signal} onInputUp - The Signal (or event) dispatched when this Button is in an Up state.
*/ */
this.onInputUp = new Phaser.Signal; 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). * @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._onOutFrameName = outFrame;
this._onUpFrameName = outFrame; this._onUpFrameName = outFrame;
if (this.input.pointerOver() == false) if (this.input.pointerOver() === false)
{ {
this.frameName = outFrame; this.frameName = outFrame;
} }
@@ -247,7 +247,7 @@ Phaser.Button.prototype.setFrames = function (overFrame, outFrame, downFrame) {
this._onOutFrameID = outFrame; this._onOutFrameID = outFrame;
this._onUpFrameID = outFrame; this._onUpFrameID = outFrame;
if (this.input.pointerOver() == false) if (this.input.pointerOver() === false)
{ {
this.frame = outFrame; this.frame = outFrame;
} }
@@ -407,7 +407,7 @@ Phaser.Button.prototype.setDownSound = function (sound, marker) {
*/ */
Phaser.Button.prototype.onInputOverHandler = function (pointer) { Phaser.Button.prototype.onInputOverHandler = function (pointer) {
if (this.freezeFrames == false) if (this.freezeFrames === false)
{ {
if (this._onOverFrameName != null) if (this._onOverFrameName != null)
{ {
@@ -439,7 +439,7 @@ Phaser.Button.prototype.onInputOverHandler = function (pointer) {
*/ */
Phaser.Button.prototype.onInputOutHandler = function (pointer) { Phaser.Button.prototype.onInputOutHandler = function (pointer) {
if (this.freezeFrames == false) if (this.freezeFrames === false)
{ {
if (this._onOutFrameName != null) if (this._onOutFrameName != null)
{ {
@@ -471,7 +471,7 @@ Phaser.Button.prototype.onInputOutHandler = function (pointer) {
*/ */
Phaser.Button.prototype.onInputDownHandler = function (pointer) { Phaser.Button.prototype.onInputDownHandler = function (pointer) {
if (this.freezeFrames == false) if (this.freezeFrames === false)
{ {
if (this._onDownFrameName != null) if (this._onDownFrameName != null)
{ {
@@ -503,7 +503,7 @@ Phaser.Button.prototype.onInputDownHandler = function (pointer) {
*/ */
Phaser.Button.prototype.onInputUpHandler = function (pointer) { Phaser.Button.prototype.onInputUpHandler = function (pointer) {
if (this.freezeFrames == false) if (this.freezeFrames === false)
{ {
if (this._onUpFrameName != null) if (this._onUpFrameName != null)
{ {
@@ -520,7 +520,7 @@ Phaser.Button.prototype.onInputUpHandler = function (pointer) {
this.onUpSound.play(this.onUpSoundMarker); this.onUpSound.play(this.onUpSoundMarker);
} }
if (this.forceOut && this.freezeFrames == false) if (this.forceOut && this.freezeFrames === false)
{ {
if (this._onOutFrameName != null) if (this._onOutFrameName != null)
{ {
+33 -34
View File
@@ -4,7 +4,6 @@
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} * @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. * 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. * @param {Phaser.Sprite} sprite - A reference to Description.
*/ */
Phaser.Events = function (sprite) { Phaser.Events = function (sprite) {
this.parent = sprite; this.parent = sprite;
this.onAddedToGroup = new Phaser.Signal; this.onAddedToGroup = new Phaser.Signal();
this.onRemovedFromGroup = new Phaser.Signal; this.onRemovedFromGroup = new Phaser.Signal();
this.onKilled = new Phaser.Signal; this.onKilled = new Phaser.Signal();
this.onRevived = new Phaser.Signal; this.onRevived = new Phaser.Signal();
this.onOutOfBounds = new Phaser.Signal; this.onOutOfBounds = new Phaser.Signal();
this.onInputOver = null; this.onInputOver = null;
this.onInputOut = null; this.onInputOut = null;
@@ -29,40 +28,40 @@ Phaser.Events = function (sprite) {
this.onDragStart = null; this.onDragStart = null;
this.onDragStop = null; this.onDragStop = null;
this.onAnimationStart = null; this.onAnimationStart = null;
this.onAnimationComplete = null; this.onAnimationComplete = null;
this.onAnimationLoop = null; this.onAnimationLoop = null;
}; };
Phaser.Events.prototype = { Phaser.Events.prototype = {
destroy: function () { destroy: function () {
this.parent = null; this.parent = null;
this.onAddedToGroup.dispose(); this.onAddedToGroup.dispose();
this.onRemovedFromGroup.dispose(); this.onRemovedFromGroup.dispose();
this.onKilled.dispose(); this.onKilled.dispose();
this.onRevived.dispose(); this.onRevived.dispose();
this.onOutOfBounds.dispose(); this.onOutOfBounds.dispose();
if (this.onInputOver) if (this.onInputOver)
{ {
this.onInputOver.dispose(); this.onInputOver.dispose();
this.onInputOut.dispose(); this.onInputOut.dispose();
this.onInputDown.dispose(); this.onInputDown.dispose();
this.onInputUp.dispose(); this.onInputUp.dispose();
this.onDragStart.dispose(); this.onDragStart.dispose();
this.onDragStop.dispose(); this.onDragStop.dispose();
} }
if (this.onAnimationStart) if (this.onAnimationStart)
{ {
this.onAnimationStart.dispose(); this.onAnimationStart.dispose();
this.onAnimationComplete.dispose(); this.onAnimationComplete.dispose();
this.onAnimationLoop.dispose(); this.onAnimationLoop.dispose();
} }
} }
}; };
+8 -8
View File
@@ -14,14 +14,14 @@
Phaser.GameObjectFactory = function (game) { Phaser.GameObjectFactory = function (game) {
/** /**
* @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; this.game = game;
/** /**
* @property {Phaser.World} world - A reference to the game world. * @property {Phaser.World} world - A reference to the game world.
*/ */
this.world = this.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. * Create a new Sprite with specific position and sprite sheet key.
* *
* @method Phaser.GameObjectFactory#sprite * @method Phaser.GameObjectFactory#sprite
+7 -9
View File
@@ -5,7 +5,7 @@
*/ */
/** /**
* Creates a new <code>Graphics</code> object. * Creates a new `Graphics` object.
* *
* @class Phaser.Graphics * @class Phaser.Graphics
* @constructor * @constructor
@@ -21,22 +21,20 @@ Phaser.Graphics = function (game, x, y) {
PIXI.Graphics.call(this); PIXI.Graphics.call(this);
/** /**
* @property {Description} type - Description. * @property {number} type - The Phaser Object Type.
*/ */
this.type = Phaser.GRAPHICS; this.type = Phaser.GRAPHICS;
this.position.x = x; this.position.x = x;
this.position.y = y; this.position.y = y;
}; };
Phaser.Graphics.prototype = Object.create(PIXI.Graphics.prototype); Phaser.Graphics.prototype = Object.create(PIXI.Graphics.prototype);
Phaser.Graphics.prototype.constructor = Phaser.Graphics; Phaser.Graphics.prototype.constructor = Phaser.Graphics;
// Add our own custom methods
/** /**
* Description. * Destroy this Graphics instance.
* *
* @method Phaser.Sprite.prototype.destroy * @method Phaser.Sprite.prototype.destroy
*/ */
@@ -58,14 +56,14 @@ Phaser.Graphics.prototype.destroy = function() {
*/ */
Phaser.Graphics.prototype.drawPolygon = function (poly) { 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) 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);
} }
+165 -161
View File
@@ -15,54 +15,54 @@
*/ */
Phaser.RenderTexture = function (game, key, width, height) { Phaser.RenderTexture = function (game, key, width, height) {
/** /**
* @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; this.game = game;
/** /**
* @property {string} name - the name of the object. * @property {string} name - the name of the object.
*/ */
this.name = key; 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; this.width = width || 100;
/** /**
* @property {number} height - the height. * @property {number} height - the height.
*/ */
this.height = height || 100; this.height = height || 100;
/** /**
* @property {PIXI.mat3} indetityMatrix - Matrix object. * @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._tempPoint = { x: 0, y: 0 };
{
this.initWebGL(); if (PIXI.gl)
} {
else this.initWebGL();
{ }
this.initCanvas(); else
} {
this.initCanvas();
}
}; };
Phaser.RenderTexture.prototype = Object.create(PIXI.Texture.prototype); 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) { Phaser.RenderTexture.prototype.render = function(displayObject, position, clear) {
if (typeof position === 'undefined') { position = false; } if (typeof position === 'undefined') { position = false; }
if (typeof clear === 'undefined') { clear = false; } if (typeof clear === 'undefined') { clear = false; }
if (displayObject instanceof Phaser.Group) if (displayObject instanceof Phaser.Group)
{ {
displayObject = displayObject._container; displayObject = displayObject._container;
} }
if (PIXI.gl) if (PIXI.gl)
{ {
this.renderWebGL(displayObject, position, clear); this.renderWebGL(displayObject, position, clear);
} }
else else
{ {
this.renderCanvas(displayObject, position, clear); 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) { Phaser.RenderTexture.prototype.renderXY = function(displayObject, x, y, clear) {
this._tempPoint.x = x; this._tempPoint.x = x;
this._tempPoint.y = y; 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() Phaser.RenderTexture.prototype.initWebGL = function()
{ {
var gl = PIXI.gl; var gl = PIXI.gl;
this.glFramebuffer = gl.createFramebuffer(); this.glFramebuffer = gl.createFramebuffer();
gl.bindFramebuffer(gl.FRAMEBUFFER, this.glFramebuffer ); gl.bindFramebuffer(gl.FRAMEBUFFER, this.glFramebuffer );
this.glFramebuffer.width = this.width; 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.width = this.width;
this.baseTexture.height = this.height; this.baseTexture.height = this.height;
this.baseTexture._glTexture = gl.createTexture(); this.baseTexture._glTexture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, this.baseTexture._glTexture); 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_MAG_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_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_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_WRAP_T, gl.CLAMP_TO_EDGE);
this.baseTexture.isRender = true; this.baseTexture.isRender = true;
gl.bindFramebuffer(gl.FRAMEBUFFER, this.glFramebuffer ); gl.bindFramebuffer(gl.FRAMEBUFFER, this.glFramebuffer );
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this.baseTexture._glTexture, 0); gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this.baseTexture._glTexture, 0);
// create a projection matrix.. // create a projection matrix..
this.projection = new PIXI.Point(this.width/2 , -this.height/2); this.projection = new PIXI.Point(this.width/2 , -this.height/2);
// set the correct render function.. // set the correct render function..
// this.render = this.renderWebGL; // this.render = this.renderWebGL;
} }
Phaser.RenderTexture.prototype.resize = function(width, height) Phaser.RenderTexture.prototype.resize = function(width, height)
{ {
this.width = width; this.width = width;
this.height = height; this.height = height;
if(PIXI.gl) if(PIXI.gl)
{ {
this.projection.x = this.width/2 this.projection.x = this.width/2
this.projection.y = -this.height/2; this.projection.y = -this.height/2;
var gl = PIXI.gl; var gl = PIXI.gl;
gl.bindTexture(gl.TEXTURE_2D, this.baseTexture._glTexture); 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);
} }
else else
{ {
this.frame.width = this.width this.frame.width = this.width
this.frame.height = this.height; this.frame.height = this.height;
this.renderer.resize(this.width, 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() 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.baseTexture = new PIXI.BaseTexture(this.renderer.view);
this.frame = new PIXI.Rectangle(0, 0, this.width, this.height); 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) Phaser.RenderTexture.prototype.renderWebGL = function(displayObject, position, clear)
{ {
var gl = PIXI.gl; var gl = PIXI.gl;
// enable the alpha color mask.. // enable the alpha color mask..
gl.colorMask(true, true, true, true); 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) if (clear)
{ {
gl.clearColor(0,0,0, 0); gl.clearColor(0,0,0, 0);
gl.clear(gl.COLOR_BUFFER_BIT); gl.clear(gl.COLOR_BUFFER_BIT);
} }
// THIS WILL MESS WITH HIT TESTING! // THIS WILL MESS WITH HIT TESTING!
var children = displayObject.children; var children = displayObject.children;
//TODO -? create a new one??? dont think so! //TODO -? create a new one??? dont think so!
var originalWorldTransform = displayObject.worldTransform; var originalWorldTransform = displayObject.worldTransform;
displayObject.worldTransform = PIXI.mat3.create();//sthis.indetityMatrix; displayObject.worldTransform = PIXI.mat3.create();//sthis.indetityMatrix;
// modify to flip... // modify to flip...
displayObject.worldTransform[4] = -1; displayObject.worldTransform[4] = -1;
displayObject.worldTransform[5] = this.projection.y * -2; displayObject.worldTransform[5] = this.projection.y * -2;
if(position) if (position)
{ {
displayObject.worldTransform[2] = position.x; displayObject.worldTransform[2] = position.x;
displayObject.worldTransform[5] -= position.y; displayObject.worldTransform[5] -= position.y;
} }
PIXI.visibleCount++; PIXI.visibleCount++;
displayObject.vcount = PIXI.visibleCount; displayObject.vcount = PIXI.visibleCount;
for(var i=0,j=children.length; i<j; i++) for (var i = 0, j = children.length; i < j; i++)
{ {
children[i].updateTransform(); children[i].updateTransform();
} }
var renderGroup = displayObject.__renderGroup; var renderGroup = displayObject.__renderGroup;
if(renderGroup) if (renderGroup)
{ {
if(displayObject == renderGroup.root) if (displayObject == renderGroup.root)
{ {
renderGroup.render(this.projection, this.glFramebuffer); renderGroup.render(this.projection, this.glFramebuffer);
} }
else else
{ {
renderGroup.renderSpecific(displayObject, this.projection, this.glFramebuffer); renderGroup.renderSpecific(displayObject, this.projection, this.glFramebuffer);
} }
} }
else else
{ {
if(!this.renderGroup)this.renderGroup = new PIXI.WebGLRenderGroup(gl); if (!this.renderGroup)
this.renderGroup.setRenderable(displayObject); {
this.renderGroup.render(this.projection, this.glFramebuffer); this.renderGroup = new PIXI.WebGLRenderGroup(gl);
} }
displayObject.worldTransform = originalWorldTransform; this.renderGroup.setRenderable(displayObject);
this.renderGroup.render(this.projection, this.glFramebuffer);
}
displayObject.worldTransform = originalWorldTransform;
} }
/** /**
* This function will draw the display object to the texture. * This function will draw the display object to the texture.
* *
@@ -284,28 +287,29 @@ Phaser.RenderTexture.prototype.renderWebGL = function(displayObject, position, c
*/ */
Phaser.RenderTexture.prototype.renderCanvas = function(displayObject, position, clear) Phaser.RenderTexture.prototype.renderCanvas = function(displayObject, position, clear)
{ {
var children = displayObject.children; var children = displayObject.children;
displayObject.worldTransform = PIXI.mat3.create(); displayObject.worldTransform = PIXI.mat3.create();
if(position) if (position)
{ {
displayObject.worldTransform[2] = position.x; displayObject.worldTransform[2] = position.x;
displayObject.worldTransform[5] = position.y; displayObject.worldTransform[5] = position.y;
} }
for(var i=0,j=children.length; i<j; i++) for (var i = 0, j = children.length; i < j; i++)
{ {
children[i].updateTransform(); children[i].updateTransform();
} }
if(clear)this.renderer.context.clearRect(0,0, this.width, this.height); if (clear)
{
this.renderer.context.clearRect(0, 0, this.width, this.height);
}
this.renderer.renderDisplayObject(displayObject); this.renderer.renderDisplayObject(displayObject);
this.renderer.context.setTransform(1,0,0,1,0,0); this.renderer.context.setTransform(1, 0, 0, 1, 0, 0);
// PIXI.texturesToUpdate.push(this.baseTexture); // PIXI.texturesToUpdate.push(this.baseTexture);
} }
+71 -49
View File
@@ -26,51 +26,51 @@ Phaser.Sprite = function (game, x, y, key, frame) {
frame = frame || null; frame = frame || 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; this.game = game;
/** /**
* @property {boolean} exists - If exists = false then the Sprite isn't updated by the core game loop or physics subsystem at all. * @property {boolean} exists - If exists = false then the Sprite isn't updated by the core game loop or physics subsystem at all.
* @default * @default
*/ */
this.exists = true; 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. * @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; this.alive = true;
/** /**
* @property {Phaser.Group} group - The parent Group of this Sprite. This is usually set after Sprite instantiation by the parent. * @property {Phaser.Group} group - The parent Group of this Sprite. This is usually set after Sprite instantiation by the parent.
*/ */
this.group = null; this.group = null;
/** /**
* @property {string} name - The user defined name given to this Sprite. * @property {string} name - The user defined name given to this Sprite.
* @default * @default
*/ */
this.name = ''; this.name = '';
/** /**
* @property {number} type - The const type of this object. * @property {number} type - The const type of this object.
* @default * @readonly
*/ */
this.type = Phaser.SPRITE; this.type = Phaser.SPRITE;
/** /**
* @property {number} renderOrderID - Used by the Renderer and Input Manager to control picking order. * @property {number} renderOrderID - Used by the Renderer and Input Manager to control picking order.
* @default * @default
*/ */
this.renderOrderID = -1; this.renderOrderID = -1;
/** /**
* If you would like the Sprite to have a lifespan once 'born' you can set this to a positive value. Handy for particles, bullets, etc. * If you would like the Sprite to have a lifespan once 'born' you can set this to a positive value. Handy for particles, bullets, etc.
* The lifespan is decremented by game.time.elapsed each update, once it reaches zero the kill() function is called. * The lifespan is decremented by game.time.elapsed each update, once it reaches zero the kill() function is called.
* @property {number} lifespan - The lifespan of the Sprite (in ms) before it will be killed. * @property {number} lifespan - The lifespan of the Sprite (in ms) before it will be killed.
* @default * @default
*/ */
this.lifespan = 0; this.lifespan = 0;
/** /**
@@ -123,7 +123,7 @@ Phaser.Sprite = function (game, x, y, key, frame) {
key = '__default'; key = '__default';
this.key = key; this.key = key;
} }
else if (typeof key === 'string' && this.game.cache.checkImageKey(key) == false) else if (typeof key === 'string' && this.game.cache.checkImageKey(key) === false)
{ {
key = '__missing'; key = '__missing';
this.key = key; this.key = key;
@@ -179,8 +179,8 @@ Phaser.Sprite = function (game, x, y, key, frame) {
*/ */
this.y = y; this.y = y;
this.position.x = x; this.position.x = x;
this.position.y = y; this.position.y = y;
/** /**
* @property {Phaser.Point} world - The world coordinates of this Sprite. This differs from the x/y coordinates which are relative to the Sprites container. * @property {Phaser.Point} world - The world coordinates of this Sprite. This differs from the x/y coordinates which are relative to the Sprites container.
@@ -198,60 +198,82 @@ Phaser.Sprite = function (game, x, y, key, frame) {
/** /**
* @property {Phaser.Point} scale - The scale of the Sprite when rendered. By default it's set to 1 (no scale). You can modify it via scale.x or scale.y or scale.setTo(x, y). A value of 1 means no change to the scale, 0.5 means "half the size", 2 means "twice the size", etc. * @property {Phaser.Point} scale - The scale of the Sprite when rendered. By default it's set to 1 (no scale). You can modify it via scale.x or scale.y or scale.setTo(x, y). A value of 1 means no change to the scale, 0.5 means "half the size", 2 means "twice the size", etc.
*/ */
this.scale = new Phaser.Point(1, 1); this.scale = new Phaser.Point(1, 1);
/** /**
* @property {Phaser.Point} _cache - A mini cache for storing all of the calculated values. * @property {object} _cache - A mini cache for storing all of the calculated values.
* @private * @private
*/ */
this._cache = { this._cache = {
dirty: false, dirty: false,
// Transform cache // Transform cache
a00: -1, a01: -1, a02: -1, a10: -1, a11: -1, a12: -1, id: -1, a00: -1,
a01: -1,
a02: -1,
a10: -1,
a11: -1,
a12: -1,
id: -1,
// Input specific transform cache // Input specific transform cache
i01: -1, i10: -1, idi: -1, i01: -1,
i10: -1,
idi: -1,
// Bounds check // Bounds check
left: null, right: null, top: null, bottom: null, left: null,
right: null,
top: null,
bottom: null,
// delta cache // delta cache
prevX: x, prevY: y, prevX: x,
prevY: y,
// The previous calculated position // The previous calculated position
x: -1, y: -1, x: -1,
y: -1,
// The actual scale values based on the worldTransform // The actual scale values based on the worldTransform
scaleX: 1, scaleY: 1, scaleX: 1,
scaleY: 1,
// The width/height of the image, based on the un-modified frame size multiplied by the final calculated scale size // The width/height of the image, based on the un-modified frame size multiplied by the final calculated scale size
width: this.currentFrame.sourceSizeW, height: this.currentFrame.sourceSizeH, width: this.currentFrame.sourceSizeW,
height: this.currentFrame.sourceSizeH,
// The actual width/height of the image if from a trimmed atlas, multiplied by the final calculated scale size // The actual width/height of the image if from a trimmed atlas, multiplied by the final calculated scale size
halfWidth: Math.floor(this.currentFrame.sourceSizeW / 2), halfHeight: Math.floor(this.currentFrame.sourceSizeH / 2), halfWidth: Math.floor(this.currentFrame.sourceSizeW / 2),
halfHeight: Math.floor(this.currentFrame.sourceSizeH / 2),
// The width/height of the image, based on the un-modified frame size multiplied by the final calculated scale size // The width/height of the image, based on the un-modified frame size multiplied by the final calculated scale size
calcWidth: -1, calcHeight: -1, calcWidth: -1,
calcHeight: -1,
// The current frame details // The current frame details
// frameID: this.currentFrame.uuid, frameWidth: this.currentFrame.width, frameHeight: this.currentFrame.height, // frameID: this.currentFrame.uuid, frameWidth: this.currentFrame.width, frameHeight: this.currentFrame.height,
frameID: -1, frameWidth: this.currentFrame.width, frameHeight: this.currentFrame.height, frameID: -1,
frameWidth: this.currentFrame.width,
frameHeight: this.currentFrame.height,
// If this sprite visible to the camera (regardless of being set to visible or not) // If this sprite visible to the camera (regardless of being set to visible or not)
cameraVisible: true, cameraVisible: true,
// Crop cache // Crop cache
cropX: 0, cropY: 0, cropWidth: this.currentFrame.sourceSizeW, cropHeight: this.currentFrame.sourceSizeH cropX: 0,
cropY: 0,
cropWidth: this.currentFrame.sourceSizeW,
cropHeight: this.currentFrame.sourceSizeH
}; };
/** /**
* @property {Phaser.Point} offset - Corner point defaults. Should not typically be modified. * @property {Phaser.Point} offset - Corner point defaults. Should not typically be modified.
*/ */
this.offset = new Phaser.Point; this.offset = new Phaser.Point();
/** /**
* @property {Phaser.Point} center - A Point containing the center coordinate of the Sprite. Takes rotation and scale into account. * @property {Phaser.Point} center - A Point containing the center coordinate of the Sprite. Takes rotation and scale into account.
@@ -293,7 +315,7 @@ Phaser.Sprite = function (game, x, y, key, frame) {
/** /**
* @property {number} health - Health value. Used in combination with damage() to allow for quick killing of Sprites. * @property {number} health - Health value. Used in combination with damage() to allow for quick killing of Sprites.
*/ */
this.health = 1; this.health = 1;
/** /**
@@ -330,7 +352,7 @@ Phaser.Sprite = function (game, x, y, key, frame) {
/** /**
* @property {Phaser.Point} cameraOffset - If this Sprite is fixed to the camera then use this Point to specify how far away from the Camera x/y it's rendered. * @property {Phaser.Point} cameraOffset - If this Sprite is fixed to the camera then use this Point to specify how far away from the Camera x/y it's rendered.
*/ */
this.cameraOffset = new Phaser.Point; this.cameraOffset = new Phaser.Point();
/** /**
* You can crop the Sprites texture by modifying the crop properties. For example crop.width = 50 would set the Sprite to only render 50px wide. * You can crop the Sprites texture by modifying the crop properties. For example crop.width = 50 would set the Sprite to only render 50px wide.
@@ -537,7 +559,7 @@ Phaser.Sprite.prototype.updateBounds = function() {
this.updateFrame = true; this.updateFrame = true;
if (this.inWorld == false) if (this.inWorld === false)
{ {
// Sprite WAS out of the screen, is it still? // Sprite WAS out of the screen, is it still?
this.inWorld = Phaser.Rectangle.intersects(this.bounds, this.game.world.bounds, this.inWorldThreshold); this.inWorld = Phaser.Rectangle.intersects(this.bounds, this.game.world.bounds, this.inWorldThreshold);
@@ -553,7 +575,7 @@ Phaser.Sprite.prototype.updateBounds = function() {
// Sprite WAS in the screen, has it now left? // Sprite WAS in the screen, has it now left?
this.inWorld = Phaser.Rectangle.intersects(this.bounds, this.game.world.bounds, this.inWorldThreshold); this.inWorld = Phaser.Rectangle.intersects(this.bounds, this.game.world.bounds, this.inWorldThreshold);
if (this.inWorld == false) if (this.inWorld === false)
{ {
this.events.onOutOfBounds.dispatch(this); this.events.onOutOfBounds.dispatch(this);
this._outOfBoundsFired = true; this._outOfBoundsFired = true;
@@ -1079,7 +1101,7 @@ Object.defineProperty(Phaser.Sprite.prototype, "inputEnabled", {
if (value) if (value)
{ {
if (this.input.enabled == false) if (this.input.enabled === false)
{ {
this.input.start(); this.input.start();
} }
+56 -38
View File
@@ -21,81 +21,99 @@ Phaser.Text = function (game, x, y, text, style) {
text = text || ''; text = text || '';
style = style || ''; style = style || '';
// If exists = false then the Sprite isn't updated by the core game loop or physics subsystem at all /**
/** * @property {Phaser.Game} game - A reference to the currently running Game.
* @property {boolean} exists - Description. */
* @default this.game = game;
*/
/**
* @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; this.exists = true;
// This is a handy little var your game can use to determine if a sprite is alive or not, it doesn't effect rendering /**
/** * @property {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.
* @property {boolean} alive - Description. * @default
* @default */
*/
this.alive = true; this.alive = true;
/** /**
* @property {Description} group - Description. * @property {Phaser.Group} group - The parent Group of this Sprite. This is usually set after Sprite instantiation by the parent.
* @default */
*/
this.group = null; this.group = null;
/** /**
* @property {string} name - Description. * @property {string} name - The user defined name given to this Sprite.
* @default * @default
*/ */
this.name = ''; this.name = '';
/** /**
* @property {Phaser.Game} game - A reference to the currently running game. * @property {number} type - The const type of this object.
* @default
*/ */
this.game = game; this.type = Phaser.TEXT;
/**
* @property {string} _text - Internal value.
* @private
*/
this._text = text; this._text = text;
/**
* @property {string} _style - Internal value.
* @private
*/
this._style = style; this._style = style;
PIXI.Text.call(this, text, style); PIXI.Text.call(this, text, style);
/** /**
* @property {Description} type - Description. * @property {Phaser.Point} position - The position of this Text object in world space.
*/
this.type = Phaser.TEXT;
/**
* @property {Description} position - Description.
*/ */
this.position.x = this.x = x; this.position.x = this.x = x;
this.position.y = this.y = y; this.position.y = this.y = y;
// Replaces the PIXI.Point with a slightly more flexible one
/** /**
* @property {Phaser.Point} anchor - Description. * The anchor sets the origin point of the texture.
*/ * The default is 0,0 this means the textures origin is the top left
* Setting than anchor to 0.5,0.5 means the textures origin is centered
* Setting the anchor to 1,1 would mean the textures origin points will be the bottom right
*
* @property {Phaser.Point} anchor - The anchor around with Sprite rotation and scaling takes place.
*/
this.anchor = new Phaser.Point(); this.anchor = new Phaser.Point();
/** /**
* @property {Phaser.Point} scale - Description. * @property {Phaser.Point} scale - The scale of the object when rendered. By default it's set to 1 (no scale). You can modify it via scale.x or scale.y or scale.setTo(x, y). A value of 1 means no change to the scale, 0.5 means "half the size", 2 means "twice the size", etc.
*/ */
this.scale = new Phaser.Point(1, 1); this.scale = new Phaser.Point(1, 1);
// A mini cache for storing all of the calculated values
/** /**
* @property {Description} _cache - Description. * @property {object} _cache - A mini cache for storing all of the calculated values.
* @private * @private
*/ */
this._cache = { this._cache = {
dirty: false, dirty: false,
// Transform cache // 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 // The previous calculated position
x: -1, y: -1, x: -1,
y: -1,
// The actual scale values based on the worldTransform // The actual scale values based on the worldTransform
scaleX: 1, scaleY: 1 scaleX: 1,
scaleY: 1
}; };
@@ -103,7 +121,7 @@ Phaser.Text = function (game, x, y, text, style) {
this._cache.y = this.y; this._cache.y = this.y;
/** /**
* @property {boolean} renderable - Description. * @property {boolean} renderable - A renderable object will be rendered to the context each frame.
*/ */
this.renderable = true; this.renderable = true;
+18 -17
View File
@@ -5,8 +5,9 @@
*/ */
/** /**
* Create a new <code>TileSprite</code>. * 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 * @class Phaser.Tilemap
* @extends Phaser.Sprite
* @constructor * @constructor
* @param {Phaser.Game} game - Current game instance. * @param {Phaser.Game} game - Current game instance.
* @param {number} x - X position of the new tileSprite. * @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; key = key || null;
frame = frame || 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]; 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. * @property {Phaser.Point} tileScale - The scaling of the image that is being tiled.
*/ */
this.tileScale = new Phaser.Point(1, 1); this.tileScale = new Phaser.Point(1, 1);
/** /**
* @property {Point} tilePosition - The offset position of the image that is being tiled. * @property {Phaser.Point} tilePosition - The offset position of the image that is being tiled.
*/ */
this.tilePosition = new Phaser.Point(0, 0); this.tilePosition = new Phaser.Point(0, 0);
}; };
Phaser.TileSprite.prototype = Phaser.Utils.extend(true, PIXI.TilingSprite.prototype, Phaser.Sprite.prototype); Phaser.TileSprite.prototype = Phaser.Utils.extend(true, PIXI.TilingSprite.prototype, Phaser.Sprite.prototype);
Phaser.TileSprite.prototype.constructor = Phaser.TileSprite; Phaser.TileSprite.prototype.constructor = Phaser.TileSprite;
// Add our own custom methods
+26 -21
View File
@@ -13,7 +13,7 @@
* @param {number} [y] The y coordinate of the center of the circle. * @param {number} [y] The y coordinate of the center of the circle.
* @param {number} [diameter] The diameter of the circle. * @param {number} [diameter] The diameter of the circle.
* @return {Phaser.Circle} This circle object * @return {Phaser.Circle} This circle object
**/ */
Phaser.Circle = function (x, y, diameter) { Phaser.Circle = function (x, y, diameter) {
x = x || 0; 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. * @property {number} x - The x coordinate of the center of the circle.
**/ */
this.x = x; this.x = x;
/** /**
* @property {number} y - The y coordinate of the center of the circle. * @property {number} y - The y coordinate of the center of the circle.
**/ */
this.y = y; this.y = y;
/** /**
* @property {number} _diameter - The diameter of the circle. * @property {number} _diameter - The diameter of the circle.
* @private * @private
**/ */
this._diameter = diameter; this._diameter = diameter;
if (diameter > 0) if (diameter > 0)
{ {
/** /**
* @property {number} _radius - The radius of the circle. * @property {number} _radius - The radius of the circle.
* @private * @private
**/ */
this._radius = diameter * 0.5; this._radius = diameter * 0.5;
} }
else else
@@ -57,7 +57,7 @@ Phaser.Circle.prototype = {
* The circumference of the circle. * The circumference of the circle.
* @method Phaser.Circle#circumference * @method Phaser.Circle#circumference
* @return {number} * @return {number}
**/ */
circumference: function () { circumference: function () {
return 2 * (Math.PI * this._radius); 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} y - The y coordinate of the center of the circle.
* @param {number} diameter - The diameter of the circle in pixels. * @param {number} diameter - The diameter of the circle in pixels.
* @return {Circle} This circle object. * @return {Circle} This circle object.
**/ */
setTo: function (x, y, diameter) { setTo: function (x, y, diameter) {
this.x = x; this.x = x;
this.y = y; this.y = y;
@@ -83,7 +83,7 @@ Phaser.Circle.prototype = {
* @method Phaser.Circle#copyFrom * @method Phaser.Circle#copyFrom
* @param {any} source - The object to copy from. * @param {any} source - The object to copy from.
* @return {Circle} This Circle object. * @return {Circle} This Circle object.
**/ */
copyFrom: function (source) { copyFrom: function (source) {
return this.setTo(source.x, source.y, source.diameter); return this.setTo(source.x, source.y, source.diameter);
}, },
@@ -93,11 +93,11 @@ Phaser.Circle.prototype = {
* @method Phaser.Circle#copyTo * @method Phaser.Circle#copyTo
* @param {any} dest - The object to copy to. * @param {any} dest - The object to copy to.
* @return {Object} This dest object. * @return {Object} This dest object.
**/ */
copyTo: function(dest) { copyTo: function(dest) {
dest[x] = this.x; dest.x = this.x;
dest[y] = this.y; dest.y = this.y;
dest[diameter] = this._diameter; dest.diameter = this._diameter;
return dest; return dest;
}, },
@@ -134,7 +134,7 @@ Phaser.Circle.prototype = {
if (typeof out === "undefined") { out = new Phaser.Circle(); } 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} dx - Moves the x value of the Circle object by this amount.
* @param {number} dy - Moves the y value of the Circle object by this amount. * @param {number} dy - Moves the y value of the Circle object by this amount.
* @return {Circle} This Circle object. * @return {Circle} This Circle object.
**/ */
offset: function (dx, dy) { offset: function (dx, dy) {
this.x += dx; this.x += dx;
this.y += dy; this.y += dy;
@@ -179,7 +179,7 @@ Phaser.Circle.prototype = {
* @method Phaser.Circle#offsetPoint * @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). * @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. * @return {Circle} This Circle object.
**/ */
offsetPoint: function (point) { offsetPoint: function (point) {
return this.offset(point.x, point.y); return this.offset(point.x, point.y);
}, },
@@ -188,7 +188,7 @@ Phaser.Circle.prototype = {
* Returns a string representation of this object. * Returns a string representation of this object.
* @method Phaser.Circle#toString * @method Phaser.Circle#toString
* @return {string} a string representation of the instance. * @return {string} a string representation of the instance.
**/ */
toString: function () { toString: function () {
return "[{Phaser.Circle (x=" + this.x + " y=" + this.y + " diameter=" + this.diameter + " radius=" + this.radius + ")}]"; 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", { Object.defineProperty(Phaser.Circle.prototype, "empty", {
get: function () { get: function () {
return (this._diameter == 0); return (this._diameter === 0);
}, },
set: function (value) { set: function (value) {
this.setTo(0, 0, 0);
if (value === true)
{
this.setTo(0, 0, 0);
}
} }
}); });
+18 -28
View File
@@ -11,20 +11,20 @@
* @constructor * @constructor
* @param {number} x The horizontal position of this Point (default 0) * @param {number} x The horizontal position of this Point (default 0)
* @param {number} y The vertical position of this Point (default 0) * @param {number} y The vertical position of this Point (default 0)
**/ */
Phaser.Point = function (x, y) { Phaser.Point = function (x, y) {
x = x || 0; x = x || 0;
y = y || 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; this.x = x;
/** /**
* @property {number} y - The y coordinate of the point. * @property {number} y - The y coordinate of the point.
**/ */
this.y = y; this.y = y;
}; };
@@ -36,7 +36,7 @@ Phaser.Point.prototype = {
* @method Phaser.Point#copyFrom * @method Phaser.Point#copyFrom
* @param {any} source - The object to copy from. * @param {any} source - The object to copy from.
* @return {Point} This Point object. * @return {Point} This Point object.
**/ */
copyFrom: function (source) { copyFrom: function (source) {
return this.setTo(source.x, source.y); return this.setTo(source.x, source.y);
}, },
@@ -45,7 +45,7 @@ Phaser.Point.prototype = {
* Inverts the x and y values of this Point * Inverts the x and y values of this Point
* @method Phaser.Point#invert * @method Phaser.Point#invert
* @return {Point} This Point object. * @return {Point} This Point object.
**/ */
invert: function () { invert: function () {
return this.setTo(this.y, this.x); 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} x - The horizontal position of this point.
* @param {number} y - The vertical position of this point. * @param {number} y - The vertical position of this point.
* @return {Point} This Point object. Useful for chaining method calls. * @return {Point} This Point object. Useful for chaining method calls.
**/ */
setTo: function (x, y) { setTo: function (x, y) {
this.x = x; this.x = x;
@@ -71,7 +71,7 @@ Phaser.Point.prototype = {
* @param {number} x - The value to add to Point.x. * @param {number} x - The value to add to Point.x.
* @param {number} y - The value to add to Point.y. * @param {number} y - The value to add to Point.y.
* @return {Phaser.Point} This Point object. Useful for chaining method calls. * @return {Phaser.Point} This Point object. Useful for chaining method calls.
**/ */
add: function (x, y) { add: function (x, y) {
this.x += x; this.x += x;
@@ -86,7 +86,7 @@ Phaser.Point.prototype = {
* @param {number} x - The value to subtract from Point.x. * @param {number} x - The value to subtract from Point.x.
* @param {number} y - The value to subtract from Point.y. * @param {number} y - The value to subtract from Point.y.
* @return {Phaser.Point} This Point object. Useful for chaining method calls. * @return {Phaser.Point} This Point object. Useful for chaining method calls.
**/ */
subtract: function (x, y) { subtract: function (x, y) {
this.x -= x; this.x -= x;
@@ -101,7 +101,7 @@ Phaser.Point.prototype = {
* @param {number} x - The value to multiply Point.x by. * @param {number} x - The value to multiply Point.x by.
* @param {number} y - 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. * @return {Phaser.Point} This Point object. Useful for chaining method calls.
**/ */
multiply: function (x, y) { multiply: function (x, y) {
this.x *= x; this.x *= x;
@@ -116,7 +116,7 @@ Phaser.Point.prototype = {
* @param {number} x - The value to divide Point.x by. * @param {number} x - The value to divide Point.x by.
* @param {number} y - 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. * @return {Phaser.Point} This Point object. Useful for chaining method calls.
**/ */
divide: function (x, y) { divide: function (x, y) {
this.x /= x; this.x /= x;
@@ -176,32 +176,22 @@ Phaser.Point.prototype = {
*/ */
clone: function (output) { 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); 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. * Copies the x and y properties from this Point to any given object.
* @method Phaser.Point#copyTo * @method Phaser.Point#copyTo
* @param {any} dest - The object to copy to. * @param {any} dest - The object to copy to.
* @return {Object} The dest object. * @return {Object} The dest object.
**/ */
copyTo: function(dest) { copyTo: function(dest) {
dest[x] = this.x; dest.x = this.x;
dest[y] = this.y; dest.y = this.y;
return dest; return dest;
@@ -291,7 +281,7 @@ Phaser.Point.prototype = {
* Returns a string representation of this object. * Returns a string representation of this object.
* @method Phaser.Point#toString * @method Phaser.Point#toString
* @return {string} A string representation of the instance. * @return {string} A string representation of the instance.
**/ */
toString: function () { toString: function () {
return '[{Point (x=' + this.x + ' y=' + this.y + ')}]'; 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); 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. * Rotates a Point around the x/y coordinates given to the desired angle.
+2 -2
View File
@@ -20,8 +20,8 @@ Phaser.Polygon = function (points) {
PIXI.Polygon.call(this, points); PIXI.Polygon.call(this, points);
/** /**
* @property {number} type - The base object type. * @property {number} type - The base object type.
*/ */
this.type = Phaser.POLYGON; this.type = Phaser.POLYGON;
}; };
+23 -18
View File
@@ -11,10 +11,10 @@
* @constructor * @constructor
* @param {number} x - The x coordinate of the top-left corner of the Rectangle. * @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} y - The y coordinate of the top-left corner of the Rectangle.
* @param {number} width - The width of the Rectangle in pixels. * @param {number} width - The width of the Rectangle.
* @param {number} height - The height of the Rectangle in pixels. * @param {number} height - The height of the Rectangle.
* @return {Rectangle} This Rectangle object. * @return {Rectangle} This Rectangle object.
**/ */
Phaser.Rectangle = function (x, y, width, height) { Phaser.Rectangle = function (x, y, width, height) {
x = x || 0; x = x || 0;
@@ -23,22 +23,22 @@ Phaser.Rectangle = function (x, y, width, height) {
height = height || 0; height = height || 0;
/** /**
* @property {number} x - Description. * @property {number} x - The x coordinate of the top-left corner of the Rectangle.
*/ */
this.x = x; this.x = x;
/** /**
* @property {number} y - Description. * @property {number} y - The y coordinate of the top-left corner of the Rectangle.
*/ */
this.y = y; this.y = y;
/** /**
* @property {number} width - Description. * @property {number} width - The width of the Rectangle.
*/ */
this.width = width; this.width = width;
/** /**
* @property {number} height - Description. * @property {number} height - The height of the Rectangle.
*/ */
this.height = height; 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} dx - Moves the x value of the Rectangle object by this amount.
* @param {number} dy - Moves the y value of the Rectangle object by this amount. * @param {number} dy - Moves the y value of the Rectangle object by this amount.
* @return {Rectangle} This Rectangle object. * @return {Rectangle} This Rectangle object.
**/ */
offset: function (dx, dy) { offset: function (dx, dy) {
this.x += dx; this.x += dx;
@@ -67,7 +67,7 @@ Phaser.Rectangle.prototype = {
* @method Phaser.Rectangle#offsetPoint * @method Phaser.Rectangle#offsetPoint
* @param {Point} point - A Point object to use to offset this Rectangle object. * @param {Point} point - A Point object to use to offset this Rectangle object.
* @return {Rectangle} This Rectangle object. * @return {Rectangle} This Rectangle object.
**/ */
offsetPoint: function (point) { offsetPoint: function (point) {
return this.offset(point.x, point.y); 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} width - The width of the Rectangle in pixels.
* @param {number} height - The height of the Rectangle in pixels. * @param {number} height - The height of the Rectangle in pixels.
* @return {Rectangle} This Rectangle object * @return {Rectangle} This Rectangle object
**/ */
setTo: function (x, y, width, height) { setTo: function (x, y, width, height) {
this.x = x; this.x = x;
@@ -95,7 +95,7 @@ Phaser.Rectangle.prototype = {
/** /**
* Runs Math.floor() on both the x and y values of this Rectangle. * Runs Math.floor() on both the x and y values of this Rectangle.
* @method Phaser.Rectangle#floor * @method Phaser.Rectangle#floor
**/ */
floor: function () { floor: function () {
this.x = Math.floor(this.x); 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. * Runs Math.floor() on the x, y, width and height values of this Rectangle.
* @method Phaser.Rectangle#floorAll * @method Phaser.Rectangle#floorAll
**/ */
floorAll: function () { floorAll: function () {
this.x = Math.floor(this.x); this.x = Math.floor(this.x);
@@ -121,7 +121,7 @@ Phaser.Rectangle.prototype = {
* @method Phaser.Rectangle#copyFrom * @method Phaser.Rectangle#copyFrom
* @param {any} source - The object to copy from. * @param {any} source - The object to copy from.
* @return {Rectangle} This Rectangle object. * @return {Rectangle} This Rectangle object.
**/ */
copyFrom: function (source) { copyFrom: function (source) {
return this.setTo(source.x, source.y, source.width, source.height); return this.setTo(source.x, source.y, source.width, source.height);
}, },
@@ -131,7 +131,7 @@ Phaser.Rectangle.prototype = {
* @method Phaser.Rectangle#copyTo * @method Phaser.Rectangle#copyTo
* @param {any} source - The object to copy to. * @param {any} source - The object to copy to.
* @return {object} This object. * @return {object} This object.
**/ */
copyTo: function (dest) { copyTo: function (dest) {
dest.x = this.x; 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. * @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) { 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. * Returns a string representation of this object.
* @method Phaser.Rectangle#toString * @method Phaser.Rectangle#toString
* @return {string} A string representation of the instance. * @return {string} A string representation of the instance.
**/ */
toString: function () { toString: function () {
return "[{Rectangle (x=" + this.x + " y=" + this.y + " width=" + this.width + " height=" + this.height + " empty=" + this.empty + ")}]"; 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) { 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) { Phaser.Rectangle.intersection = function (a, b, out) {
out = out || new Phaser.Rectangle; out = out || new Phaser.Rectangle();
if (Phaser.Rectangle.intersects(a, b)) if (Phaser.Rectangle.intersects(a, b))
{ {
+60 -73
View File
@@ -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 * @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 * @constructor
* @param {Phaser.Game} game - Current game instance. * @param {Phaser.Game} game - Current game instance.
*/ */
Phaser.Input = function (game) { Phaser.Input = function (game) {
/** /**
* @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; 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 * @default
*/ */
this.hitCanvas = null; this.hitCanvas = null;
/** /**
* @property {Description} hitContext - Description. * @property {CanvasRenderingContext2D} hitContext - The context of the pixel perfect hit canvas.
* @default * @default
*/ */
this.hitContext = null; this.hitContext = null;
}; };
/** /**
@@ -53,11 +53,6 @@ Phaser.Input.MOUSE_TOUCH_COMBINE = 2;
Phaser.Input.prototype = { Phaser.Input.prototype = {
/**
* @property {Phaser.Game} game
*/
game: null,
/** /**
* How often should the input pointers be checked for updates? * 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. * 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, pollRate: 0,
/** /**
* @property {number} _pollCounter - Description. * @property {number} _pollCounter - Internal var holding the current poll counter.
* @private * @private
* @default * @default
*/ */
_pollCounter: 0, _pollCounter: 0,
/** /**
* A vector object representing the previous position of the Pointer. * @property {Phaser.Point} _oldPosition - A point object representing the previous position of the Pointer.
* @property {Vec2} vector
* @private * @private
* @default * @default
*/ */
_oldPosition: null, _oldPosition: null,
/** /**
* X coordinate of the most recent Pointer event * @property {number} _x - x coordinate of the most recent Pointer event
* @property {number} _x
* @private * @private
* @default * @default
*/ */
_x: 0, _x: 0,
/** /**
* Y coordinate of the most recent Pointer event * @property {number} _y - Y coordinate of the most recent Pointer event
* @property {number} _y
* @private * @private
* @default * @default
*/ */
@@ -112,17 +104,14 @@ Phaser.Input.prototype = {
multiInputOverride: Phaser.Input.MOUSE_TOUCH_COMBINE, multiInputOverride: Phaser.Input.MOUSE_TOUCH_COMBINE,
/** /**
* A vector object representing the current position of the Pointer. * @property {Phaser.Point} position - A point object representing the current position of the Pointer.
* @property {Phaser.Point} position
* @default * @default
*/ */
position: null, position: null,
/** /**
* A vector object representing the speed of the Pointer. Only really useful in single Pointer games, * A point object representing the speed of the Pointer. Only really useful in single Pointer games, otherwise see the Pointer objects directly.
* otherwise see the Pointer objects directly.
* @property {Phaser.Point} speed * @property {Phaser.Point} speed
* @default
*/ */
speed: null, speed: null,
@@ -130,7 +119,6 @@ Phaser.Input.prototype = {
* A Circle object centered on the x/y screen coordinates of the Input. * 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. * Default size of 44px (Apples recommended "finger tip" size) but can be changed to anything.
* @property {Phaser.Circle} circle * @property {Phaser.Circle} circle
* @default
*/ */
circle: null, circle: null,
@@ -138,7 +126,6 @@ Phaser.Input.prototype = {
* The scale by which all input coordinates are multiplied, calculated by the StageScaleMode. * 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. * In an un-scaled game the values will be x: 1 and y: 1.
* @property {Phaser.Point} scale * @property {Phaser.Point} scale
* @default
*/ */
scale: null, scale: null,
@@ -267,7 +254,7 @@ Phaser.Input.prototype = {
/** /**
* A Pointer object * A Pointer object
* @property {Phaser.Pointer} pointer9 * @property {Phaser.Pointer} pointer9
*/ */
pointer9: null, pointer9: null,
/** /**
@@ -353,40 +340,40 @@ Phaser.Input.prototype = {
*/ */
interactiveItems: new Phaser.LinkedList(), interactiveItems: new Phaser.LinkedList(),
/** /**
* Starts the Input Manager running. * Starts the Input Manager running.
* @method Phaser.Input#boot * @method Phaser.Input#boot
* @protected * @protected
*/ */
boot: function () { boot: function () {
this.mousePointer = new Phaser.Pointer(this.game, 0); this.mousePointer = new Phaser.Pointer(this.game, 0);
this.pointer1 = new Phaser.Pointer(this.game, 1); this.pointer1 = new Phaser.Pointer(this.game, 1);
this.pointer2 = new Phaser.Pointer(this.game, 2); this.pointer2 = new Phaser.Pointer(this.game, 2);
this.mouse = new Phaser.Mouse(this.game); this.mouse = new Phaser.Mouse(this.game);
this.keyboard = new Phaser.Keyboard(this.game); this.keyboard = new Phaser.Keyboard(this.game);
this.touch = new Phaser.Touch(this.game); this.touch = new Phaser.Touch(this.game);
this.mspointer = new Phaser.MSPointer(this.game); this.mspointer = new Phaser.MSPointer(this.game);
this.onDown = new Phaser.Signal(); this.onDown = new Phaser.Signal();
this.onUp = new Phaser.Signal(); this.onUp = new Phaser.Signal();
this.onTap = new Phaser.Signal(); this.onTap = new Phaser.Signal();
this.onHold = new Phaser.Signal(); this.onHold = new Phaser.Signal();
this.scale = new Phaser.Point(1, 1); this.scale = new Phaser.Point(1, 1);
this.speed = new Phaser.Point(); this.speed = new Phaser.Point();
this.position = new Phaser.Point(); this.position = new Phaser.Point();
this._oldPosition = 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.activePointer = this.mousePointer;
this.currentPointers = 0; this.currentPointers = 0;
this.hitCanvas = document.createElement('canvas'); this.hitCanvas = document.createElement('canvas');
this.hitCanvas.width = 1; this.hitCanvas.width = 1;
this.hitCanvas.height = 1; this.hitCanvas.height = 1;
this.hitContext = this.hitCanvas.getContext('2d'); this.hitContext = this.hitCanvas.getContext('2d');
this.mouse.start(); 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. * 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. * If you need more then use this to create a new one, up to a maximum of 10.
* @method Phaser.Input#addPointer * @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"); console.warn("You can only have 10 Pointer objects");
return null; return null;
@@ -441,7 +428,7 @@ Phaser.Input.prototype = {
}, },
/** /**
* Updates the Input Manager. Called by the core Game loop. * Updates the Input Manager. Called by the core Game loop.
* @method Phaser.Input#update * @method Phaser.Input#update
* @protected * @protected
@@ -475,14 +462,14 @@ Phaser.Input.prototype = {
this._pollCounter = 0; this._pollCounter = 0;
}, },
/** /**
* Reset all of the Pointers and Input states * Reset all of the Pointers and Input states
* @method Phaser.Input#reset * @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. * @param {boolean} hard - A soft reset (hard = false) won't reset any Signals that might be bound. A hard reset will.
*/ */
reset: function (hard) { reset: function (hard) {
if (this.game.isBooted == false) if (this.game.isBooted === false)
{ {
return; return;
} }
@@ -503,7 +490,7 @@ Phaser.Input.prototype = {
this.currentPointers = 0; this.currentPointers = 0;
this.game.stage.canvas.style.cursor = "default"; this.game.stage.canvas.style.cursor = "default";
if (hard == true) if (hard === true)
{ {
this.onDown.dispose(); this.onDown.dispose();
this.onUp.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. * 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 * @method Phaser.Input#startPointer
* @param {Any} event - The event data from the Touch event. * @param {Any} event - The event data from the Touch event.
@@ -547,11 +534,11 @@ Phaser.Input.prototype = {
return null; return null;
} }
if (this.pointer1.active == false) if (this.pointer1.active === false)
{ {
return this.pointer1.start(event); return this.pointer1.start(event);
} }
else if (this.pointer2.active == false) else if (this.pointer2.active === false)
{ {
return this.pointer2.start(event); return this.pointer2.start(event);
} }
@@ -559,7 +546,7 @@ Phaser.Input.prototype = {
{ {
for (var i = 3; i <= 10; i++) 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); 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. * 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 * @method Phaser.Input#updatePointer
* @param {Any} event - The event data from the Touch event. * @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. * Stops the matching Pointer object, passing in the event data.
* @method Phaser.Input#stopPointer * @method Phaser.Input#stopPointer
* @param {Any} event - The event data from the Touch event. * @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 * Get the next Pointer object whos active property matches the given state
* @method Phaser.Input#getPointer * @method Phaser.Input#getPointer
* @param {boolean} state - The state the Pointer should be in (false for inactive, true for active). * @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. * Get the Pointer object whos identified property matches the given identifier value.
* @method Phaser.Input#getPointerFromIdentifier * @method Phaser.Input#getPointerFromIdentifier
* @param {number} identifier - The Pointer.identifier value to search for. * @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", { Object.defineProperty(Phaser.Input.prototype, "worldX", {
get: function () { 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", { Object.defineProperty(Phaser.Input.prototype, "worldY", {
get: function () { get: function () {
return this.game.camera.view.y + this.y; return this.game.camera.view.y + this.y;
} }
}); });
+246 -247
View File
@@ -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 * @class Phaser.InputHandler
* @classdesc Description.
* @constructor * @constructor
* @param {Phaser.Sprite} game - Description. * @param {Phaser.Sprite} sprite - The Sprite object to which this Input Handler belongs.
*/ */
Phaser.InputHandler = function (sprite) { Phaser.InputHandler = function (sprite) {
/** /**
* @property {Phaser.Sprite} sprite - Description. * @property {Phaser.Sprite} sprite - The Sprite object to which this Input Handler belongs.
*/ */
this.sprite = sprite; this.sprite = sprite;
/** /**
* @property {Phaser.Game} game - A reference to the currently running game. * @property {Phaser.Game} game - A reference to the currently running game.
*/ */
this.game = sprite.game; this.game = sprite.game;
/** /**
* @property {boolean} enabled - Description. * @property {boolean} enabled - If enabled the Input Handler will process input requests and monitor pointer activity.
* @default * @default
*/ */
this.enabled = false; this.enabled = false;
// Linked list references /**
/** * @property {Description} parent - Description.
* @property {Description} parent - Description. * @default
* @default */
*/ // this.parent = null;
this.parent = null;
/** /**
* @property {Description} next - Description. * @property {Description} next - Linked List
* @default * @default
*/ */
this.next = null; // this.next = null;
/** /**
* @property {Description} prev - Description. * @property {Description} prev - Description.
* @default * @default
*/ */
this.prev = null; // this.prev = null;
/** /**
* @property {Description} last - Description. * @property {Description} last - Description.
* @default * @default
*/ */
this.last = this; // this.last = this;
/** /**
* @property {Description} first - Description. * @property {Description} first - Description.
* @default * @default
*/ */
this.first = this; // this.first = this;
/** /**
* @property {number} priorityID - The PriorityID controls which Sprite receives an Input event first if they should overlap. * @property {number} priorityID - The PriorityID controls which Sprite receives an Input event first if they should overlap.
* @default * @default
*/ */
this.priorityID = 0; this.priorityID = 0;
/** /**
* @property {boolean} useHandCursor - Description. * @property {boolean} useHandCursor - On a desktop browser you can set the 'hand' cursor to appear when moving over the Sprite.
* @default * @default
*/ */
this.useHandCursor = false; this.useHandCursor = false;
/** /**
* @property {boolean} isDragged - Description. * @property {boolean} isDragged - true if the Sprite is being currently dragged.
* @default * @default
*/ */
this.isDragged = false; this.isDragged = false;
/** /**
* @property {boolean} allowHorizontalDrag - Description. * @property {boolean} allowHorizontalDrag - Controls if the Sprite is allowed to be dragged horizontally.
* @default * @default
*/ */
this.allowHorizontalDrag = true; this.allowHorizontalDrag = true;
/** /**
* @property {boolean} allowVerticalDrag - Description. * @property {boolean} allowVerticalDrag - Controls if the Sprite is allowed to be dragged vertically.
* @default * @default
*/ */
this.allowVerticalDrag = true; this.allowVerticalDrag = true;
/** /**
* @property {boolean} bringToTop - Description. * @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 * @default
*/ */
this.bringToTop = false; this.bringToTop = false;
/** /**
* @property {Description} snapOffset - Description. * @property {Phaser.Point} snapOffset - A Point object that contains by how far the Sprite snap is offset.
* @default * @default
*/ */
this.snapOffset = null; this.snapOffset = null;
/** /**
* @property {boolean} snapOnDrag - Description. * @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 * @default
*/ */
this.snapOnDrag = false; this.snapOnDrag = false;
/** /**
* @property {boolean} snapOnRelease - Description. * @property {boolean} snapOnRelease - When the Sprite is dragged this controls if the Sprite will be snapped on release.
* @default * @default
*/ */
this.snapOnRelease = false; this.snapOnRelease = false;
/** /**
* @property {number} snapX - Description. * @property {number} snapX - When a Sprite has snapping enabled this holds the width of the snap grid.
* @default * @default
*/ */
this.snapX = 0; this.snapX = 0;
/** /**
* @property {number} snapY - Description. * @property {number} snapY - When a Sprite has snapping enabled this holds the height of the snap grid.
* @default * @default
*/ */
this.snapY = 0; this.snapY = 0;
/** /**
* @property {number} pixelPerfect - Should we use pixel perfect hit detection? Warning: expensive. Only enable if you really need it! * @property {number} pixelPerfect - Should we use pixel perfect hit detection? Warning: expensive. Only enable if you really need it!
* @default * @default
*/ */
this.pixelPerfect = false; this.pixelPerfect = false;
/** /**
@@ -145,13 +143,13 @@ Phaser.InputHandler = function (sprite) {
this.draggable = false; 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 * @default
*/ */
this.boundsRect = null; 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 * @default
*/ */
this.boundsSprite = null; this.boundsSprite = null;
@@ -168,7 +166,7 @@ Phaser.InputHandler = function (sprite) {
* @property {Phaser.Point} _tempPoint - Description. * @property {Phaser.Point} _tempPoint - Description.
* @private * @private
*/ */
this._tempPoint = new Phaser.Point; this._tempPoint = new Phaser.Point();
this._pointerData = []; this._pointerData = [];
@@ -192,23 +190,23 @@ Phaser.InputHandler = function (sprite) {
Phaser.InputHandler.prototype = { Phaser.InputHandler.prototype = {
/** /**
* Description. * 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 * @method Phaser.InputHandler#start
* @param {number} priority - Description. * @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 - Description. * @param {boolean} useHandCursor - If true the Sprite will show the hand cursor on mouse-over (doesn't apply to mobile browsers)
* @return {Phaser.Sprite} Description. * @return {Phaser.Sprite} The Sprite object to which the Input Handler is bound.
*/ */
start: function (priority, useHandCursor) { start: function (priority, useHandCursor) {
priority = priority || 0; priority = priority || 0;
if (typeof useHandCursor == 'undefined') { useHandCursor = false; } if (typeof useHandCursor == 'undefined') { useHandCursor = false; }
// Turning on // Turning on
if (this.enabled == false) if (this.enabled === false)
{ {
// Register, etc // Register, etc
this.game.input.interactiveItems.add(this); this.game.input.interactiveItems.add(this);
this.useHandCursor = useHandCursor; this.useHandCursor = useHandCursor;
this.priorityID = priority; this.priorityID = priority;
@@ -231,29 +229,29 @@ Phaser.InputHandler.prototype = {
}; };
} }
this.snapOffset = new Phaser.Point; this.snapOffset = new Phaser.Point();
this.enabled = true; this.enabled = true;
// Create the signals the Input component will emit // Create the signals the Input component will emit
if (this.sprite.events && this.sprite.events.onInputOver == null) if (this.sprite.events && this.sprite.events.onInputOver == null)
{ {
this.sprite.events.onInputOver = new Phaser.Signal; this.sprite.events.onInputOver = new Phaser.Signal();
this.sprite.events.onInputOut = new Phaser.Signal; this.sprite.events.onInputOut = new Phaser.Signal();
this.sprite.events.onInputDown = new Phaser.Signal; this.sprite.events.onInputDown = new Phaser.Signal();
this.sprite.events.onInputUp = new Phaser.Signal; this.sprite.events.onInputUp = new Phaser.Signal();
this.sprite.events.onDragStart = new Phaser.Signal; this.sprite.events.onDragStart = new Phaser.Signal();
this.sprite.events.onDragStop = new Phaser.Signal; this.sprite.events.onDragStop = new Phaser.Signal();
} }
} }
return this.sprite; return this.sprite;
}, },
/** /**
* Description. * Resets the Input Handler and disables it.
* @method Phaser.InputHandler#reset * @method Phaser.InputHandler#reset
*/ */
reset: function () { reset: function () {
this.enabled = false; this.enabled = false;
@@ -278,14 +276,14 @@ Phaser.InputHandler.prototype = {
} }
}, },
/** /**
* Description. * Stops the Input Handler from running.
* @method Phaser.InputHandler#stop * @method Phaser.InputHandler#stop
*/ */
stop: function () { stop: function () {
// Turning off // Turning off
if (this.enabled == false) if (this.enabled === false)
{ {
return; return;
} }
@@ -293,15 +291,15 @@ Phaser.InputHandler.prototype = {
{ {
// De-register, etc // De-register, etc
this.enabled = false; this.enabled = false;
this.game.input.interactiveItems.remove(this); this.game.input.interactiveItems.remove(this);
} }
}, },
/** /**
* Clean up memory. * Clean up memory.
* @method Phaser.InputHandler#destroy * @method Phaser.InputHandler#destroy
*/ */
destroy: function () { destroy: function () {
if (this.enabled) if (this.enabled)
@@ -310,99 +308,99 @@ Phaser.InputHandler.prototype = {
this.game.input.interactiveItems.remove(this); 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. * 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. * This value is only set when the pointer is over this Sprite.
* @method Phaser.InputHandler#pointerX * @method Phaser.InputHandler#pointerX
* @param {Pointer} pointer * @param {Phaser.Pointer} pointer
* @return {number} The x coordinate of the Input pointer. * @return {number} The x coordinate of the Input pointer.
*/ */
pointerX: function (pointer) { pointerX: function (pointer) {
pointer = pointer || 0; pointer = pointer || 0;
return this._pointerData[pointer].x; return this._pointerData[pointer].x;
}, },
/** /**
* The y coordinate of the Input pointer, relative to the top-left of the parent Sprite * 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. * This value is only set when the pointer is over this Sprite.
* @method Phaser.InputHandler#pointerY * @method Phaser.InputHandler#pointerY
* @param {Pointer} pointer * @param {Phaser.Pointer} pointer
* @return {number} The y coordinate of the Input pointer. * @return {number} The y coordinate of the Input pointer.
*/ */
pointerY: function (pointer) { pointerY: function (pointer) {
pointer = pointer || 0; pointer = pointer || 0;
return this._pointerData[pointer].y; return this._pointerData[pointer].y;
}, },
/** /**
* If the Pointer is touching the touchscreen, or the mouse button is held down, isDown is set to true. * If the Pointer is touching the touchscreen, or the mouse button is held down, isDown is set to true.
* @method Phaser.InputHandler#pointerDown * @method Phaser.InputHandler#pointerDown
* @param {Pointer} pointer * @param {Phaser.Pointer} pointer
* @return {boolean} * @return {boolean}
*/ */
pointerDown: function (pointer) { pointerDown: function (pointer) {
pointer = pointer || 0; pointer = pointer || 0;
return this._pointerData[pointer].isDown; return this._pointerData[pointer].isDown;
}, },
/** /**
* If the Pointer is not touching the touchscreen, or the mouse button is up, isUp is set to true * If the Pointer is not touching the touchscreen, or the mouse button is up, isUp is set to true
* @method Phaser.InputHandler#pointerUp * @method Phaser.InputHandler#pointerUp
* @param {Pointer} pointer * @param {Phaser.Pointer} pointer
* @return {boolean} * @return {boolean}
*/ */
pointerUp: function (pointer) { pointerUp: function (pointer) {
pointer = pointer || 0; pointer = pointer || 0;
return this._pointerData[pointer].isUp; return this._pointerData[pointer].isUp;
}, },
/** /**
* A timestamp representing when the Pointer first touched the touchscreen. * A timestamp representing when the Pointer first touched the touchscreen.
* @method Phaser.InputHandler#pointerTimeDown * @method Phaser.InputHandler#pointerTimeDown
* @param {Pointer} pointer * @param {Phaser.Pointer} pointer
* @return {number} * @return {number}
*/ */
pointerTimeDown: function (pointer) { pointerTimeDown: function (pointer) {
pointer = pointer || 0; pointer = pointer || 0;
return this._pointerData[pointer].timeDown; return this._pointerData[pointer].timeDown;
}, },
/** /**
* A timestamp representing when the Pointer left the touchscreen. * A timestamp representing when the Pointer left the touchscreen.
* @method Phaser.InputHandler#pointerTimeUp * @method Phaser.InputHandler#pointerTimeUp
* @param {Pointer} pointer * @param {Phaser.Pointer} pointer
* @return {number} * @return {number}
*/ */
pointerTimeUp: function (pointer) { pointerTimeUp: function (pointer) {
pointer = pointer || 0; pointer = pointer || 0;
return this._pointerData[pointer].timeUp; return this._pointerData[pointer].timeUp;
}, },
/** /**
* Is the Pointer over this Sprite? * Is the Pointer over this Sprite?
* @method Phaser.InputHandler#pointerOver * @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. * @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? * Is the Pointer outside of this Sprite?
* @method Phaser.InputHandler#pointerOut * @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. * @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. * @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) if (this.enabled)
{ {
@@ -462,52 +460,52 @@ Phaser.InputHandler.prototype = {
}, },
/** /**
* A timestamp representing when the Pointer first touched the touchscreen. * A timestamp representing when the Pointer first touched the touchscreen.
* @method Phaser.InputHandler#pointerTimeOver * @method Phaser.InputHandler#pointerTimeOver
* @param {Pointer} pointer * @param {Phaser.Pointer} pointer
* @return {number} * @return {number}
*/ */
pointerTimeOver: function (pointer) { pointerTimeOver: function (pointer) {
pointer = pointer || 0; pointer = pointer || 0;
return this._pointerData[pointer].timeOver; return this._pointerData[pointer].timeOver;
}, },
/** /**
* A timestamp representing when the Pointer left the touchscreen. * A timestamp representing when the Pointer left the touchscreen.
* @method Phaser.InputHandler#pointerTimeOut * @method Phaser.InputHandler#pointerTimeOut
* @param {Pointer} pointer * @param {Phaser.Pointer} pointer
* @return {number} * @return {number}
*/ */
pointerTimeOut: function (pointer) { pointerTimeOut: function (pointer) {
pointer = pointer || 0; pointer = pointer || 0;
return this._pointerData[pointer].timeOut; return this._pointerData[pointer].timeOut;
}, },
/** /**
* Is this sprite being dragged by the mouse or not? * Is this sprite being dragged by the mouse or not?
* @method Phaser.InputHandler#pointerTimeOut * @method Phaser.InputHandler#pointerTimeOut
* @param {Pointer} pointer * @param {Phaser.Pointer} pointer
* @return {number} * @return {number}
*/ */
pointerDragged: function (pointer) { pointerDragged: function (pointer) {
pointer = pointer || 0; pointer = pointer || 0;
return this._pointerData[pointer].isDragged; return this._pointerData[pointer].isDragged;
}, },
/** /**
* Checks if the given pointer is over this Sprite. * Checks if the given pointer is over this Sprite.
* @method Phaser.InputHandler#checkPointerOver * @method Phaser.InputHandler#checkPointerOver
* @param {Pointer} pointer * @param {Phaser.Pointer} pointer
* @return {boolean} * @return {boolean}
*/ */
checkPointerOver: function (pointer) { 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. * 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. * It compares the alpha value of the pixel and if >= InputHandler.pixelPerfectAlpha it returns true.
* @method Phaser.InputHandler#checkPixel * @method Phaser.InputHandler#checkPixel
@@ -565,14 +563,14 @@ Phaser.InputHandler.prototype = {
}, },
/** /**
* Update. * Update.
* @method Phaser.InputHandler#update * @method Phaser.InputHandler#update
* @param {Pointer} pointer * @param {Phaser.Pointer} pointer
*/ */
update: function (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); this._pointerOutHandler(pointer);
return false; return false;
@@ -582,7 +580,7 @@ Phaser.InputHandler.prototype = {
{ {
return this.updateDrag(pointer); return this.updateDrag(pointer);
} }
else if (this._pointerData[pointer.id].isOver == true) else if (this._pointerData[pointer.id].isOver === true)
{ {
if (this.checkPointerOver(pointer)) if (this.checkPointerOver(pointer))
{ {
@@ -598,15 +596,15 @@ Phaser.InputHandler.prototype = {
} }
}, },
/** /**
* Description. * Internal method handling the pointer over event.
* @method Phaser.InputHandler#_pointerOverHandler * @method Phaser.InputHandler#_pointerOverHandler
* @private * @private
* @param {Pointer} pointer * @param {Phaser.Pointer} pointer
*/ */
_pointerOverHandler: function (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].isOver = true;
this._pointerData[pointer.id].isOut = false; 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].x = pointer.x - this.sprite.x;
this._pointerData[pointer.id].y = pointer.y - this.sprite.y; 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"; this.game.stage.canvas.style.cursor = "pointer";
} }
@@ -623,19 +621,19 @@ Phaser.InputHandler.prototype = {
} }
}, },
/** /**
* Description. * Internal method handling the pointer out event.
* @method Phaser.InputHandler#_pointerOutHandler * @method Phaser.InputHandler#_pointerOutHandler
* @private * @private
* @param {Pointer} pointer * @param {Phaser.Pointer} pointer
*/ */
_pointerOutHandler: function (pointer) { _pointerOutHandler: function (pointer) {
this._pointerData[pointer.id].isOver = false; this._pointerData[pointer.id].isOver = false;
this._pointerData[pointer.id].isOut = true; this._pointerData[pointer.id].isOut = true;
this._pointerData[pointer.id].timeOut = this.game.time.now; 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"; this.game.stage.canvas.style.cursor = "default";
} }
@@ -647,15 +645,15 @@ Phaser.InputHandler.prototype = {
}, },
/** /**
* Description. * Internal method handling the touched event.
* @method Phaser.InputHandler#_touchedHandler * @method Phaser.InputHandler#_touchedHandler
* @private * @private
* @param {Pointer} pointer * @param {Phaser.Pointer} pointer
*/ */
_touchedHandler: function (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].isDown = true;
this._pointerData[pointer.id].isUp = false; this._pointerData[pointer.id].isUp = false;
@@ -663,7 +661,7 @@ Phaser.InputHandler.prototype = {
this.sprite.events.onInputDown.dispatch(this.sprite, pointer); this.sprite.events.onInputDown.dispatch(this.sprite, pointer);
// Start drag // Start drag
if (this.draggable && this.isDragged == false) if (this.draggable && this.isDragged === false)
{ {
this.startDrag(pointer); this.startDrag(pointer);
} }
@@ -671,7 +669,7 @@ Phaser.InputHandler.prototype = {
if (this.bringToTop) if (this.bringToTop)
{ {
this.sprite.bringToTop(); this.sprite.bringToTop();
} }
} }
// Consume the event? // Consume the event?
@@ -679,12 +677,12 @@ Phaser.InputHandler.prototype = {
}, },
/** /**
* Description. * Internal method handling the pointer released event.
* @method Phaser.InputHandler#_releasedHandler * @method Phaser.InputHandler#_releasedHandler
* @private * @private
* @param {Pointer} pointer * @param {Phaser.Pointer} pointer
*/ */
_releasedHandler: function (pointer) { _releasedHandler: function (pointer) {
// If was previously touched by this Pointer, check if still is AND still over this item // 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. * Updates the Pointer drag on this Sprite.
* @method Phaser.InputHandler#updateDrag * @method Phaser.InputHandler#updateDrag
* @param {Pointer} pointer * @param {Phaser.Pointer} pointer
* @return {boolean} * @return {boolean}
*/ */
updateDrag: function (pointer) { 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) * Returns true if the pointer has entered the Sprite within the specified delay time (defaults to 500ms, half a second)
* @method Phaser.InputHandler#justOver * @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. * @param {number} delay - The time below which the pointer is considered as just over.
* @return {boolean} * @return {boolean}
*/ */
justOver: function (pointer, delay) { justOver: function (pointer, delay) {
pointer = pointer || 0; pointer = pointer || 0;
delay = delay || 500; delay = delay || 500;
return (this._pointerData[pointer].isOver && this.overDuration(pointer) < delay); 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) * Returns true if the pointer has left the Sprite within the specified delay time (defaults to 500ms, half a second)
* @method Phaser.InputHandler#justOut * @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. * @param {number} delay - The time below which the pointer is considered as just out.
* @return {boolean} * @return {boolean}
*/ */
justOut: function (pointer, delay) { justOut: function (pointer, delay) {
pointer = pointer || 0; pointer = pointer || 0;
delay = delay || 500; delay = delay || 500;
return (this._pointerData[pointer].isOut && (this.game.time.now - this._pointerData[pointer].timeOut < delay)); 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) * Returns true if the pointer has entered the Sprite within the specified delay time (defaults to 500ms, half a second)
* @method Phaser.InputHandler#justPressed * @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. * @param {number} delay - The time below which the pointer is considered as just over.
* @return {boolean} * @return {boolean}
*/ */
justPressed: function (pointer, delay) { justPressed: function (pointer, delay) {
pointer = pointer || 0; pointer = pointer || 0;
delay = delay || 500; delay = delay || 500;
return (this._pointerData[pointer].isDown && this.downDuration(pointer) < delay); 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) * Returns true if the pointer has left the Sprite within the specified delay time (defaults to 500ms, half a second)
* @method Phaser.InputHandler#justReleased * @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. * @param {number} delay - The time below which the pointer is considered as just out.
* @return {boolean} * @return {boolean}
*/ */
justReleased: function (pointer, delay) { justReleased: function (pointer, delay) {
pointer = pointer || 0; pointer = pointer || 0;
delay = delay || 500; delay = delay || 500;
return (this._pointerData[pointer].isUp && (this.game.time.now - this._pointerData[pointer].timeUp < delay)); 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. * If the pointer is currently over this Sprite this returns how long it has been there for in milliseconds.
* @method Phaser.InputHandler#overDuration * @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. * @return {number} The number of milliseconds the pointer has been over the Sprite, or -1 if not over.
*/ */
overDuration: function (pointer) { overDuration: function (pointer) {
pointer = pointer || 0; pointer = pointer || 0;
if (this._pointerData[pointer].isOver) 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. * If the pointer is currently over this Sprite this returns how long it has been there for in milliseconds.
* @method Phaser.InputHandler#downDuration * @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. * @return {number} The number of milliseconds the pointer has been pressed down on the Sprite, or -1 if not over.
*/ */
downDuration: function (pointer) { downDuration: function (pointer) {
pointer = pointer || 0; pointer = pointer || 0;
if (this._pointerData[pointer].isDown) 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 * Make this Sprite draggable by the mouse. You can also optionally set mouseStartDragCallback and mouseStopDragCallback
* @method Phaser.InputHandler#enableDrag * @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 {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 bringToTop If true the Sprite will be bought to the top of the rendering list in its current Group. * @param {boolean} [bringToTop=false] - 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 {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 alphaThreshold If using pixel perfect collision this specifies the alpha level from 0 to 255 above which a collision is processed (default 255) * @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 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 {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 boundsSprite If you want to restrict the drag of this sprite to within the bounding box of another sprite, pass it here * @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) { enableDrag: function (lockCenter, bringToTop, pixelPerfect, alphaThreshold, boundsRect, boundsSprite) {
if (typeof lockCenter == 'undefined') { lockCenter = false; } if (typeof lockCenter == 'undefined') { lockCenter = false; }
if (typeof bringToTop == 'undefined') { bringToTop = false; } if (typeof bringToTop == 'undefined') { bringToTop = false; }
if (typeof pixelPerfect == 'undefined') { pixelPerfect = false; } if (typeof pixelPerfect == 'undefined') { pixelPerfect = false; }
if (typeof alphaThreshold == 'undefined') { alphaThreshold = 255; }
alphaThreshold = alphaThreshold || 255; if (typeof boundsRect == 'undefined') { boundsRect = null; }
boundsRect = boundsRect || null; if (typeof boundsSprite == 'undefined') { boundsSprite = null; }
boundsSprite = boundsSprite || null;
this._dragPoint = new Phaser.Point(); this._dragPoint = new Phaser.Point();
this.draggable = true; 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. * 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 * @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. * Called by Pointer when drag starts on this Sprite. Should not usually be called directly.
* @method Phaser.InputHandler#startDrag * @method Phaser.InputHandler#startDrag
* @param {Phaser.Pointer} pointer
*/ */
startDrag: function (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. * Called by Pointer when drag is stopped on this Sprite. Should not usually be called directly.
* @method Phaser.InputHandler#stopDrag * @method Phaser.InputHandler#stopDrag
* @param {Phaser.Pointer} pointer
*/ */
stopDrag: function (pointer) { stopDrag: function (pointer) {
@@ -976,37 +975,37 @@ Phaser.InputHandler.prototype = {
this.sprite.events.onDragStop.dispatch(this.sprite, pointer); this.sprite.events.onDragStop.dispatch(this.sprite, pointer);
this.sprite.events.onInputUp.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); 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! * 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 * @method Phaser.InputHandler#setDragLock
* @param allowHorizontal To enable the sprite to be dragged horizontally set to true, otherwise false * @param {boolean} [allowHorizontal=true] - 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} [allowVertical=true] - To enable the sprite to be dragged vertically set to true, otherwise false.
*/ */
setDragLock: function (allowHorizontal, allowVertical) { setDragLock: function (allowHorizontal, allowVertical) {
if (typeof allowHorizontal == 'undefined') { allowHorizontal = true; } if (typeof allowHorizontal == 'undefined') { allowHorizontal = true; }
if (typeof allowVertical == 'undefined') { allowVertical = true; } if (typeof allowVertical == 'undefined') { allowVertical = true; }
this.allowHorizontalDrag = allowHorizontal; this.allowHorizontalDrag = allowHorizontal;
this.allowVerticalDrag = allowVertical; this.allowVerticalDrag = allowVertical;
}, },
/** /**
* Make this Sprite snap to the given grid either during drag or when it's released. * 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. * For example 16x16 as the snapX and snapY would make the sprite snap to every 16 pixels.
* @method Phaser.InputHandler#enableSnap * @method Phaser.InputHandler#enableSnap
* @param snapX The width of the grid cell in pixels * @param {number} snapX - The width of the grid cell to snap to.
* @param snapY The height of the grid cell in pixels * @param {number} snapY - The height of the grid cell to snap to.
* @param onDrag If true the sprite will snap to the grid while being dragged * @param {boolean} [onDrag=true] - 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 {boolean} [onRelease=false] - If true the sprite will snap to the grid when released.
*/ */
enableSnap: function (snapX, snapY, onDrag, onRelease) { 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. * Stops the sprite from snapping to a grid during drag or release.
* @method Phaser.InputHandler#disableSnap * @method Phaser.InputHandler#disableSnap
*/ */
@@ -1031,7 +1030,7 @@ Phaser.InputHandler.prototype = {
}, },
/** /**
* Bounds Rect check for the sprite drag * Bounds Rect check for the sprite drag
* @method Phaser.InputHandler#checkBoundsRect * @method Phaser.InputHandler#checkBoundsRect
*/ */
@@ -1057,7 +1056,7 @@ Phaser.InputHandler.prototype = {
}, },
/** /**
* Parent Sprite Bounds check for the sprite drag. * Parent Sprite Bounds check for the sprite drag.
* @method Phaser.InputHandler#checkBoundsSprite * @method Phaser.InputHandler#checkBoundsSprite
*/ */
+69 -69
View File
@@ -13,87 +13,87 @@
*/ */
Phaser.Key = function (game, keycode) { Phaser.Key = function (game, keycode) {
/** /**
* @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; this.game = game;
/** /**
* @property {boolean} isDown - The "down" state of the key. * @property {boolean} isDown - The "down" state of the key.
* @default * @default
*/ */
this.isDown = false; this.isDown = false;
/** /**
* @property {boolean} isUp - The "up" state of the key. * @property {boolean} isUp - The "up" state of the key.
* @default * @default
*/ */
this.isUp = false; this.isUp = false;
/** /**
* @property {boolean} altKey - The down state of the ALT key, if pressed at the same time as this key. * @property {boolean} altKey - The down state of the ALT key, if pressed at the same time as this key.
* @default * @default
*/ */
this.altKey = false; this.altKey = false;
/** /**
* @property {boolean} ctrlKey - The down state of the CTRL key, if pressed at the same time as this key. * @property {boolean} ctrlKey - The down state of the CTRL key, if pressed at the same time as this key.
* @default * @default
*/ */
this.ctrlKey = false; this.ctrlKey = false;
/** /**
* @property {boolean} shiftKey - The down state of the SHIFT key, if pressed at the same time as this key. * @property {boolean} shiftKey - The down state of the SHIFT key, if pressed at the same time as this key.
* @default * @default
*/ */
this.shiftKey = false; this.shiftKey = false;
/** /**
* @property {number} timeDown - The timestamp when the key was last pressed down. * @property {number} timeDown - The timestamp when the key was last pressed down.
* @default * @default
*/ */
this.timeDown = 0; 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 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. * 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. * @property {number} duration - The number of milliseconds this key has been held down for.
* @default * @default
*/ */
this.duration = 0; this.duration = 0;
/** /**
* @property {number} timeUp - The timestamp when the key was last released. * @property {number} timeUp - The timestamp when the key was last released.
* @default * @default
*/ */
this.timeUp = 0; this.timeUp = 0;
/** /**
* @property {number} repeats - If a key is held down this holds down the number of times the key has 'repeated'. * @property {number} repeats - If a key is held down this holds down the number of times the key has 'repeated'.
* @default * @default
*/ */
this.repeats = 0; this.repeats = 0;
/** /**
* @property {number} keyCode - The keycode of this key. * @property {number} keyCode - The keycode of this key.
*/ */
this.keyCode = keycode; 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(); 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(); this.onUp = new Phaser.Signal();
}; };
Phaser.Key.prototype = { Phaser.Key.prototype = {
/** /**
* Called automatically by Phaser.Keyboard. * Called automatically by Phaser.Keyboard.
* @method Phaser.Key#processKeyDown * @method Phaser.Key#processKeyDown
* @param {KeyboardEvent} event. * @param {KeyboardEvent} event.
@@ -124,7 +124,7 @@ Phaser.Key.prototype = {
}, },
/** /**
* Called automatically by Phaser.Keyboard. * Called automatically by Phaser.Keyboard.
* @method Phaser.Key#processKeyUp * @method Phaser.Key#processKeyUp
* @param {KeyboardEvent} event. * @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 * @method Phaser.Key#justPressed
* @param {number} [duration=250] - The duration below which the key is considered as being just pressed. * @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. * @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 * @method Phaser.Key#justPressed
* @param {number} [duration=250] - The duration below which the key is considered as being just released. * @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. * @return {boolean} True if the key is just released otherwise false.
@@ -164,7 +164,7 @@ Phaser.Key.prototype = {
if (typeof duration === "undefined") { duration = 250; } 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));
} }
+38 -39
View File
@@ -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 * @class Phaser.Keyboard
* @classdesc A Keyboard object Description.
* @constructor * @constructor
* @param {Phaser.Game} game - A reference to the currently running game. * @param {Phaser.Game} game - A reference to the currently running game.
*/ */
Phaser.Keyboard = function (game) { Phaser.Keyboard = function (game) {
/** /**
* @property {Phaser.Game} game - Local reference to game. * @property {Phaser.Game} game - Local reference to game.
*/ */
this.game = game; this.game = game;
/** /**
* @property {Description} _keys - Description. * @property {object} _keys - The object the key values are stored in.
* @private * @private
*/ */
this._keys = {}; this._keys = {};
/** /**
* @property {Description} _hotkeys - Description. * @property {object} _hotkeys - The object the hot keys are stored in.
* @private * @private
*/ */
this._hotkeys = {}; this._hotkeys = {};
/** /**
* @property {Description} _capture - Description. * @property {object} _capture - The object the key capture values are stored in.
* @private * @private
*/ */
this._capture = {}; this._capture = {};
/** /**
@@ -72,7 +71,7 @@ Phaser.Keyboard = function (game) {
* @property {function} onUpCallback - This callback is invoked every time a key is released. * @property {function} onUpCallback - This callback is invoked every time a key is released.
*/ */
this.onUpCallback = null; this.onUpCallback = null;
}; };
Phaser.Keyboard.prototype = { Phaser.Keyboard.prototype = {
@@ -134,10 +133,10 @@ Phaser.Keyboard.prototype = {
*/ */
createCursorKeys: function () { createCursorKeys: function () {
return { return {
up: this.addKey(Phaser.Keyboard.UP), up: this.addKey(Phaser.Keyboard.UP),
down: this.addKey(Phaser.Keyboard.DOWN), down: this.addKey(Phaser.Keyboard.DOWN),
left: this.addKey(Phaser.Keyboard.LEFT), left: this.addKey(Phaser.Keyboard.LEFT),
right: this.addKey(Phaser.Keyboard.RIGHT) 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. * 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. * 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. * 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. * Removes an existing key capture.
* @method Phaser.Keyboard#removeKeyCapture * @method Phaser.Keyboard#removeKeyCapture
* @param {number} keycode * @param {number} keycode
*/ */
removeKeyCapture: function (keycode) { removeKeyCapture: function (keycode) {
@@ -212,9 +211,9 @@ Phaser.Keyboard.prototype = {
}, },
/** /**
* Clear all set key captures. * Clear all set key captures.
* @method Phaser.Keyboard#clearCaptures * @method Phaser.Keyboard#clearCaptures
*/ */
clearCaptures: function () { clearCaptures: function () {
@@ -222,12 +221,12 @@ Phaser.Keyboard.prototype = {
}, },
/** /**
* Process the keydown event. * Process the keydown event.
* @method Phaser.Keyboard#processKeyDown * @method Phaser.Keyboard#processKeyDown
* @param {KeyboardEvent} event * @param {KeyboardEvent} event
* @protected * @protected
*/ */
processKeyDown: function (event) { processKeyDown: function (event) {
if (this.game.input.disabled || this.disabled) if (this.game.input.disabled || this.disabled)
@@ -278,9 +277,9 @@ Phaser.Keyboard.prototype = {
}, },
/** /**
* Process the keyup event. * Process the keyup event.
* @method Phaser.Keyboard#processKeyUp * @method Phaser.Keyboard#processKeyUp
* @param {KeyboardEvent} event * @param {KeyboardEvent} event
* @protected * @protected
*/ */
@@ -324,9 +323,9 @@ Phaser.Keyboard.prototype = {
}, },
/** /**
* Reset the "isDown" state of all keys. * Reset the "isDown" state of all keys.
* @method Phaser.Keyboard#reset * @method Phaser.Keyboard#reset
*/ */
reset: function () { reset: function () {
@@ -390,7 +389,7 @@ Phaser.Keyboard.prototype = {
return this._keys[keycode].isDown; return this._keys[keycode].isDown;
} }
return false; return false;
} }
+33 -48
View File
@@ -16,33 +16,15 @@
*/ */
Phaser.MSPointer = function (game) { Phaser.MSPointer = function (game) {
/** /**
* @property {Phaser.Game} game - Local reference to game. * @property {Phaser.Game} game - A reference to the currently running game.
*/ */
this.game = game; this.game = game;
/** /**
* @property {Phaser.Game} callbackContext - Description. * @property {Object} callbackContext - The context under which callbacks are called (defaults to game).
*/ */
this.callbackContext = this.game; 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;
/** /**
* You can disable all Input by setting disabled = true. While set all new input related events will be ignored. * 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; this.disabled = false;
/** /**
* Description. * @property {function} _onMSPointerDown - Internal function to handle MSPointer events.
* @property {Description} _onMSPointerDown
* @private * @private
* @default
*/ */
this._onMSPointerDown = null; this._onMSPointerDown = null;
/** /**
* Description. * @property {function} _onMSPointerMove - Internal function to handle MSPointer events.
* @property {Description} _onMSPointerMove
* @private * @private
* @default
*/ */
this._onMSPointerMove = null; this._onMSPointerMove = null;
/** /**
* Description. * @property {function} _onMSPointerUp - Internal function to handle MSPointer events.
* @property {Description} _onMSPointerUp
* @private * @private
* @default
*/ */
this._onMSPointerUp = null; this._onMSPointerUp = null;
@@ -78,7 +54,7 @@ Phaser.MSPointer = function (game) {
Phaser.MSPointer.prototype = { Phaser.MSPointer.prototype = {
/** /**
* Starts the event listeners running. * Starts the event listeners running.
* @method Phaser.MSPointer#start * @method Phaser.MSPointer#start
*/ */
@@ -86,7 +62,7 @@ Phaser.MSPointer.prototype = {
var _this = this; var _this = this;
if (this.game.device.mspointer == true) if (this.game.device.mspointer === true)
{ {
this._onMSPointerDown = function (event) { this._onMSPointerDown = function (event) {
return _this.onPointerDown(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('MSPointerMove', this._onMSPointerMove, false);
this.game.renderer.view.addEventListener('MSPointerUp', this._onMSPointerUp, 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-content-zooming'] = 'none';
this.game.renderer.view.style['-ms-touch-action'] = '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 * @method Phaser.MSPointer#onPointerDown
* @param {Any} event * @param {PointerEvent} event
**/ */
onPointerDown: function (event) { onPointerDown: function (event) {
if (this.game.input.disabled || this.disabled) 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 * @method Phaser.MSPointer#onPointerMove
* @param {Any} event * @param {PointerEvent } event
**/ */
onPointerMove: function (event) { onPointerMove: function (event) {
if (this.game.input.disabled || this.disabled) 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 * @method Phaser.MSPointer#onPointerUp
* @param {Any} event * @param {PointerEvent} event
**/ */
onPointerUp: function (event) { onPointerUp: function (event) {
if (this.game.input.disabled || this.disabled) if (this.game.input.disabled || this.disabled)
@@ -168,7 +149,7 @@ Phaser.MSPointer.prototype = {
}, },
/** /**
* Stop the event listeners. * Stop the event listeners.
* @method Phaser.MSPointer#stop * @method Phaser.MSPointer#stop
*/ */
@@ -178,6 +159,10 @@ Phaser.MSPointer.prototype = {
this.game.stage.canvas.removeEventListener('MSPointerMove', this._onMSPointerMove); this.game.stage.canvas.removeEventListener('MSPointerMove', this._onMSPointerMove);
this.game.stage.canvas.removeEventListener('MSPointerUp', this._onMSPointerUp); 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);
} }
}; };
+66 -73
View File
@@ -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 * @class Phaser.Mouse
* @classdesc The Mouse class
* @constructor * @constructor
* @param {Phaser.Game} game - A reference to the currently running game. * @param {Phaser.Game} game - A reference to the currently running game.
*/ */
Phaser.Mouse = function (game) { Phaser.Mouse = function (game) {
/** /**
* @property {Phaser.Game} game - Local reference to game. * @property {Phaser.Game} game - A reference to the currently running game.
*/ */
this.game = game; this.game = game;
/** /**
* @property {Object} callbackContext - Description. * @property {Object} callbackContext - The context under which callbacks are called.
*/ */
this.callbackContext = this.game; this.callbackContext = this.game;
/** /**
* @property {function} mouseDownCallback - Description. * @property {function} mouseDownCallback - A callback that can be fired when the mouse is pressed down.
* @default */
*/ this.mouseDownCallback = null;
this.mouseDownCallback = null;
/**
/** * @property {function} mouseMoveCallback - A callback that can be fired when the mouse is moved while pressed down.
* @property {function} mouseMoveCallback - Description. */
* @default this.mouseMoveCallback = null;
*/
this.mouseMoveCallback = null; /**
* @property {function} mouseUpCallback - A callback that can be fired when the mouse is released from a pressed down state.
/** */
* @property {function} mouseUpCallback - Description. this.mouseUpCallback = null;
* @default
*/
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. * @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; 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. * @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 * @default
*/ */
this.button = -1; 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 - You can disable all Input by setting disabled = true. While set all new input related events will be ignored.
* @property {boolean} disabled
* @default * @default
*/ */
this.disabled = false; this.disabled = false;
/** /**
* If the mouse has been Pointer Locked successfully this will be set to true. * @property {boolean} locked - If the mouse has been Pointer Locked successfully this will be set to true.
* @property {boolean} locked
* @default * @default
*/ */
this.locked = false; this.locked = false;
/** /**
* This event is dispatched when the browser enters or leaves pointer lock state. * @property {Phaser.Signal} pointerLock - This event is dispatched when the browser enters or leaves pointer lock state.
* @property {Phaser.Signal} pointerLock
* @default * @default
*/ */
this.pointerLock = new Phaser.Signal; this.pointerLock = new Phaser.Signal();
/** /**
* The browser mouse event. * @property {MouseEvent} event - The browser mouse event.
* @property {MouseEvent} event
*/ */
this.event; this.event = null;
/** /**
* @property {function} _onMouseDown * @property {function} _onMouseDown - Internal event handler reference.
* @private * @private
*/ */
this._onMouseDown; this._onMouseDown = null;
/** /**
* @property {function} _onMouseMove * @property {function} _onMouseMove - Internal event handler reference.
* @private * @private
*/ */
this._onMouseMove; this._onMouseMove = null;
/** /**
* @property {function} _onMouseUp * @property {function} _onMouseUp - Internal event handler reference.
* @private * @private
*/ */
this._onMouseUp; this._onMouseUp = null;
}; };
@@ -105,6 +97,7 @@ Phaser.Mouse = function (game) {
* @type {number} * @type {number}
*/ */
Phaser.Mouse.NO_BUTTON = -1; Phaser.Mouse.NO_BUTTON = -1;
/** /**
* @constant * @constant
* @type {number} * @type {number}
@@ -125,7 +118,7 @@ Phaser.Mouse.RIGHT_BUTTON = 2;
Phaser.Mouse.prototype = { Phaser.Mouse.prototype = {
/** /**
* Starts the event listeners running. * Starts the event listeners running.
* @method Phaser.Mouse#start * @method Phaser.Mouse#start
*/ */
@@ -133,7 +126,7 @@ Phaser.Mouse.prototype = {
var _this = this; 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 ... // Android stock browser fires mouse events even if you preventDefault on the touchStart, so ...
return; return;
@@ -161,10 +154,10 @@ Phaser.Mouse.prototype = {
}, },
/** /**
* The internal method that handles the mouse down event from the browser. * The internal method that handles the mouse down event from the browser.
* @method Phaser.Mouse#onMouseDown * @method Phaser.Mouse#onMouseDown
* @param {MouseEvent} event * @param {MouseEvent} event - The native event from the browser. This gets stored in Mouse.event.
*/ */
onMouseDown: function (event) { onMouseDown: function (event) {
@@ -193,10 +186,10 @@ Phaser.Mouse.prototype = {
}, },
/** /**
* The internal method that handles the mouse move event from the browser. * The internal method that handles the mouse move event from the browser.
* @method Phaser.Mouse#onMouseMove * @method Phaser.Mouse#onMouseMove
* @param {MouseEvent} event * @param {MouseEvent} event - The native event from the browser. This gets stored in Mouse.event.
*/ */
onMouseMove: function (event) { onMouseMove: function (event) {
@@ -223,10 +216,10 @@ Phaser.Mouse.prototype = {
}, },
/** /**
* The internal method that handles the mouse up event from the browser. * The internal method that handles the mouse up event from the browser.
* @method Phaser.Mouse#onMouseUp * @method Phaser.Mouse#onMouseUp
* @param {MouseEvent} event * @param {MouseEvent} event - The native event from the browser. This gets stored in Mouse.event.
*/ */
onMouseUp: function (event) { onMouseUp: function (event) {
@@ -237,7 +230,7 @@ Phaser.Mouse.prototype = {
event.preventDefault(); event.preventDefault();
} }
this.button = Phaser.Mouse.NO_BUTTON; this.button = Phaser.Mouse.NO_BUTTON;
if (this.mouseUpCallback) 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. * 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. * 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'. * 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 () { requestPointerLock: function () {
@@ -284,10 +277,10 @@ Phaser.Mouse.prototype = {
}, },
/** /**
* Internal pointerLockChange handler. * Internal pointerLockChange handler.
* @method Phaser.Mouse#pointerLockChange * @method Phaser.Mouse#pointerLockChange
* @param {MouseEvent} event * @param {pointerlockchange} event - The native event from the browser. This gets stored in Mouse.event.
*/ */
pointerLockChange: function (event) { pointerLockChange: function (event) {
@@ -297,20 +290,20 @@ Phaser.Mouse.prototype = {
{ {
// Pointer was successfully locked // Pointer was successfully locked
this.locked = true; this.locked = true;
this.pointerLock.dispatch(true); this.pointerLock.dispatch(true, event);
} }
else else
{ {
// Pointer was unlocked // Pointer was unlocked
this.locked = false; this.locked = false;
this.pointerLock.dispatch(false); this.pointerLock.dispatch(false, event);
} }
}, },
/** /**
* Internal release pointer lock handler. * Internal release pointer lock handler.
* @method Phaser.Mouse#releasePointerLock * @method Phaser.Mouse#releasePointerLock
*/ */
releasePointerLock: function () { releasePointerLock: function () {
@@ -324,7 +317,7 @@ Phaser.Mouse.prototype = {
}, },
/** /**
* Stop the event listeners. * Stop the event listeners.
* @method Phaser.Mouse#stop * @method Phaser.Mouse#stop
*/ */
+70 -100
View File
@@ -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. * @classdesc A Pointer object is used by the Mouse, Touch and MSPoint managers and represents a single finger on the touch screen.
* @constructor * @constructor
* @param {Phaser.Game} game - A reference to the currently running game. * @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) { 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; 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; this.id = id;
/** /**
* Local private variable to store the status of dispatching a hold event. * @property {boolean} _holdSent - Local private variable to store the status of dispatching a hold event.
* @property {boolean} _holdSent
* @private * @private
* @default * @default
*/ */
this._holdSent = false; this._holdSent = false;
/** /**
* Local private variable storing the short-term history of pointer movements. * @property {array} _history - Local private variable storing the short-term history of pointer movements.
* @property {array} _history
* @private * @private
*/ */
this._history = []; this._history = [];
/** /**
* Local private variable storing the time at which the next history drop should occur * @property {number} _lastDrop - Local private variable storing the time at which the next history drop should occur.
* @property {number} _lastDrop
* @private * @private
* @default * @default
*/ */
this._nextDrop = 0; this._nextDrop = 0;
/** /**
* Monitor events outside of a state reset loop. * @property {boolean} _stateReset - Monitor events outside of a state reset loop.
* @property {boolean} _stateReset * @private
* @private * @default
* @default */
*/
this._stateReset = false; this._stateReset = false;
/** /**
* Description. * @property {boolean} withinGame - true if the Pointer is within the game area, otherwise false.
* @property {boolean} withinGame
*/ */
this.withinGame = false; this.withinGame = false;
/** /**
* The horizontal coordinate of point relative to the viewport in pixels, excluding any scroll offset. * @property {number} clientX - The horizontal coordinate of point relative to the viewport in pixels, excluding any scroll offset.
* @property {number} clientX
* @default * @default
*/ */
this.clientX = -1; this.clientX = -1;
/** /**
* The vertical coordinate of point relative to the viewport in pixels, excluding any scroll offset. * @property {number} clientY - The vertical coordinate of point relative to the viewport in pixels, excluding any scroll offset.
* @property {number} clientY
* @default * @default
*/ */
this.clientY = -1; this.clientY = -1;
/** /**
* The horizontal coordinate of point relative to the viewport in pixels, including any scroll offset. * @property {number} pageX - The horizontal coordinate of point relative to the viewport in pixels, including any scroll offset.
* @property {number} pageX
* @default * @default
*/ */
this.pageX = -1; this.pageX = -1;
/** /**
* The vertical coordinate of point relative to the viewport in pixels, including any scroll offset. * @property {number} pageY - The vertical coordinate of point relative to the viewport in pixels, including any scroll offset.
* @property {number} pageY
* @default * @default
*/ */
this.pageY = -1; this.pageY = -1;
/** /**
* The horizontal coordinate of point relative to the screen in pixels. * @property {number} screenX - The horizontal coordinate of point relative to the screen in pixels.
* @property {number} screenX
* @default * @default
*/ */
this.screenX = -1; this.screenX = -1;
/** /**
* The vertical coordinate of point relative to the screen in pixels. * @property {number} screenY - The vertical coordinate of point relative to the screen in pixels.
* @property {number} screenY
* @default * @default
*/ */
this.screenY = -1; 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 - The horizontal coordinate of point relative to the game element. This value is automatically scaled based on game size.
* @property {number} x
* @default * @default
*/ */
this.x = -1; 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 - The vertical coordinate of point relative to the game element. This value is automatically scaled based on game size.
* @property {number} y
* @default * @default
*/ */
this.y = -1; this.y = -1;
/** /**
* If the Pointer is a mouse this is true, otherwise false. * @property {boolean} isMouse - If the Pointer is a mouse this is true, otherwise false.
* @property {boolean} isMouse * @default
* @type {boolean}
*/ */
this.isMouse = false; 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 - If the Pointer is touching the touchscreen, or the mouse button is held down, isDown is set to true.
* @property {boolean} isDown
* @default * @default
*/ */
this.isDown = false; 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 - If the Pointer is not touching the touchscreen, or the mouse button is up, isUp is set to true.
* @property {boolean} isUp
* @default * @default
*/ */
this.isUp = true; this.isUp = true;
/** /**
* A timestamp representing when the Pointer first touched the touchscreen. * @property {number} timeDown - A timestamp representing when the Pointer first touched the touchscreen.
* @property {number} timeDown
* @default * @default
*/ */
this.timeDown = 0; this.timeDown = 0;
/** /**
* A timestamp representing when the Pointer left the touchscreen. * @property {number} timeUp - A timestamp representing when the Pointer left the touchscreen.
* @property {number} timeUp
* @default * @default
*/ */
this.timeUp = 0; this.timeUp = 0;
/** /**
* A timestamp representing when the Pointer was last tapped or clicked. * @property {number} previousTapTime - A timestamp representing when the Pointer was last tapped or clicked.
* @property {number} previousTapTime
* @default * @default
*/ */
this.previousTapTime = 0; this.previousTapTime = 0;
/** /**
* The total number of times this Pointer has been touched to the touchscreen. * @property {number} totalTouches - The total number of times this Pointer has been touched to the touchscreen.
* @property {number} totalTouches
* @default * @default
*/ */
this.totalTouches = 0; this.totalTouches = 0;
/** /**
* The number of miliseconds since the last click. * @property {number} msSinceLastClick - The number of miliseconds since the last click.
* @property {number} msSinceLastClick
* @default * @default
*/ */
this.msSinceLastClick = Number.MAX_VALUE; this.msSinceLastClick = Number.MAX_VALUE;
/** /**
* The Game Object this Pointer is currently over / touching / dragging. * @property {any} targetObject - The Game Object this Pointer is currently over / touching / dragging.
* @property {Any} targetObject
* @default * @default
*/ */
this.targetObject = null; this.targetObject = null;
/** /**
* An active pointer is one that is currently pressed down on the display. A Mouse is always active. * @property {boolean} active - An active pointer is one that is currently pressed down on the display. A Mouse is always active.
* @property {boolean} active
* @default * @default
*/ */
this.active = false; this.active = false;
/** /**
* A Phaser.Point object containing the current x/y values of the pointer on the display. * @property {Phaser.Point} position - A Phaser.Point object containing the current x/y values of the pointer on the display.
* @property {Phaser.Point} position
*/ */
this.position = new Phaser.Point(); 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 - 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
*/ */
this.positionDown = new Phaser.Point(); this.positionDown = new Phaser.Point();
@@ -207,7 +182,7 @@ Phaser.Pointer = function (game, id) {
*/ */
this.circle = new Phaser.Circle(0, 0, 44); this.circle = new Phaser.Circle(0, 0, 44);
if (id == 0) if (id === 0)
{ {
this.isMouse = true; this.isMouse = true;
} }
@@ -216,7 +191,7 @@ Phaser.Pointer = function (game, id) {
Phaser.Pointer.prototype = { Phaser.Pointer.prototype = {
/** /**
* Called when the Pointer is pressed onto the touchscreen. * Called when the Pointer is pressed onto the touchscreen.
* @method Phaser.Pointer#start * @method Phaser.Pointer#start
* @param {Any} event * @param {Any} event
@@ -232,7 +207,7 @@ Phaser.Pointer.prototype = {
} }
// Fix to stop rogue browser plugins from blocking the visibility state event // 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; this.game.paused = false;
return this; return this;
@@ -255,7 +230,7 @@ Phaser.Pointer.prototype = {
// x and y are the old values here? // x and y are the old values here?
this.positionDown.setTo(this.x, this.y); 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.x = this.x;
this.game.input.y = this.y; this.game.input.y = this.y;
@@ -267,7 +242,7 @@ Phaser.Pointer.prototype = {
this._stateReset = false; this._stateReset = false;
this.totalTouches++; this.totalTouches++;
if (this.isMouse == false) if (this.isMouse === false)
{ {
this.game.input.currentPointers++; this.game.input.currentPointers++;
} }
@@ -281,17 +256,17 @@ Phaser.Pointer.prototype = {
}, },
/** /**
* Description. * Called internall by the Input Manager.
* @method Phaser.Pointer#update * @method Phaser.Pointer#update
*/ */
update: function () { update: function () {
if (this.active) 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); 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 * @method Phaser.Pointer#move
* @param {Any} event * @param {MouseEvent|PointerEvent|TouchEvent} event - The event passed up from the input handler.
*/ */
move: function (event) { move: function (event) {
@@ -351,7 +326,7 @@ Phaser.Pointer.prototype = {
this.circle.x = this.x; this.circle.x = this.x;
this.circle.y = this.y; 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.activePointer = this;
this.game.input.x = this.x; this.game.input.x = this.x;
@@ -368,9 +343,9 @@ Phaser.Pointer.prototype = {
} }
// Easy out if we're dragging something and it still exists // 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; this.targetObject = null;
} }
@@ -388,7 +363,7 @@ Phaser.Pointer.prototype = {
{ {
var currentNode = this.game.input.interactiveItems.next; 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 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)) 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 // Same target as before, so update it
// console.log("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; this.targetObject = null;
} }
@@ -455,10 +430,10 @@ Phaser.Pointer.prototype = {
}, },
/** /**
* Called when the Pointer leaves the target area. * Called when the Pointer leaves the target area.
* @method Phaser.Pointer#leave * @method Phaser.Pointer#leave
* @param {Any} event * @param {MouseEvent|PointerEvent|TouchEvent} event - The event passed up from the input handler.
*/ */
leave: function (event) { leave: function (event) {
@@ -467,10 +442,10 @@ Phaser.Pointer.prototype = {
}, },
/** /**
* Called when the Pointer leaves the touchscreen. * Called when the Pointer leaves the touchscreen.
* @method Phaser.Pointer#stop * @method Phaser.Pointer#stop
* @param {Any} event * @param {MouseEvent|PointerEvent|TouchEvent} event - The event passed up from the input handler.
*/ */
stop: function (event) { stop: function (event) {
@@ -482,7 +457,7 @@ Phaser.Pointer.prototype = {
this.timeUp = this.game.time.now; 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); this.game.input.onUp.dispatch(this, event);
@@ -515,7 +490,7 @@ Phaser.Pointer.prototype = {
this.isDown = false; this.isDown = false;
this.isUp = true; this.isUp = true;
if (this.isMouse == false) if (this.isMouse === false)
{ {
this.game.input.currentPointers--; this.game.input.currentPointers--;
} }
@@ -524,7 +499,7 @@ Phaser.Pointer.prototype = {
{ {
var currentNode = this.game.input.interactiveItems.next; var currentNode = this.game.input.interactiveItems.next;
do do
{ {
if (currentNode) 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. * 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 * @method Phaser.Pointer#justPressed
* @param {number} [duration] * @param {number} [duration] - The time to check against. If none given it will use InputManager.justPressedRate.
* @return {boolean} * @return {boolean} true if the Pointer was pressed down within the duration given.
*/ */
justPressed: function (duration) { 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. * 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 * @method Phaser.Pointer#justReleased
* @param {number} [duration] * @param {number} [duration] - The time to check against. If none given it will use InputManager.justReleasedRate.
* @return {boolean} * @return {boolean} true if the Pointer was released within the duration given.
*/ */
justReleased: function (duration) { justReleased: function (duration) {
@@ -574,13 +553,13 @@ Phaser.Pointer.prototype = {
}, },
/** /**
* Resets the Pointer properties. Called by InputManager.reset when you perform a State change. * Resets the Pointer properties. Called by InputManager.reset when you perform a State change.
* @method Phaser.Pointer#reset * @method Phaser.Pointer#reset
*/ */
reset: function () { reset: function () {
if (this.isMouse == false) if (this.isMouse === false)
{ {
this.active = false; this.active = false;
} }
@@ -600,15 +579,6 @@ Phaser.Pointer.prototype = {
this.targetObject = null; 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 () { 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 () { get: function () {
return this.game.world.camera.y + this.y; return this.game.world.camera.y + this.y;
} }
+75 -27
View File
@@ -15,70 +15,102 @@
Phaser.Touch = function (game) { 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; this.game = game;
/** /**
* You can disable all Input by setting disabled = true. While set all new input related events will be ignored. * @property {boolean} disabled - You can disable all Touch events by setting disabled = true. While set all new touch events will be ignored.
* @method Phaser.Touch#disabled
* @return {boolean} * @return {boolean}
*/ */
this.disabled = false; this.disabled = false;
/** /**
* @property {Phaser.Game} callbackContext - Description. * @property {Object} callbackContext - The context under which callbacks are called.
*/ */
this.callbackContext = this.game; this.callbackContext = this.game;
/** /**
* @property {Phaser.Game} touchStartCallback - Description. * @property {function} touchStartCallback - A callback that can be fired on a touchStart event.
* @default
*/ */
this.touchStartCallback = null; this.touchStartCallback = null;
/** /**
* @property {Phaser.Game} touchMoveCallback - Description. * @property {function} touchMoveCallback - A callback that can be fired on a touchMove event.
* @default
*/ */
this.touchMoveCallback = null; this.touchMoveCallback = null;
/** /**
* @property {Phaser.Game} touchEndCallback - Description. * @property {function} touchEndCallback - A callback that can be fired on a touchEnd event.
* @default
*/ */
this.touchEndCallback = null; this.touchEndCallback = null;
/** /**
* @property {Phaser.Game} touchEnterCallback - Description. * @property {function} touchEnterCallback - A callback that can be fired on a touchEnter event.
* @default
*/ */
this.touchEnterCallback = null; this.touchEnterCallback = null;
/** /**
* @property {Phaser.Game} touchLeaveCallback - Description. * @property {function} touchLeaveCallback - A callback that can be fired on a touchLeave event.
* @default
*/ */
this.touchLeaveCallback = null; this.touchLeaveCallback = null;
/** /**
* @property {Description} touchCancelCallback - Description. * @property {function} touchCancelCallback - A callback that can be fired on a touchCancel event.
* @default
*/ */
this.touchCancelCallback = null; this.touchCancelCallback = null;
/** /**
* @property {boolean} preventDefault - Description. * @property {boolean} preventDefault - If true the TouchEvent will have prevent.default called on it.
* @default * @default
*/ */
this.preventDefault = true; this.preventDefault = true;
/**
* @property {TouchEvent} event - The browser touch event.
*/
this.event = null;
/**
* @property {function} _onTouchStart - Internal event handler reference.
* @private
*/
this._onTouchStart = null; this._onTouchStart = null;
/**
* @property {function} _onTouchMove - Internal event handler reference.
* @private
*/
this._onTouchMove = null; this._onTouchMove = null;
/**
* @property {function} _onTouchEnd - Internal event handler reference.
* @private
*/
this._onTouchEnd = null; this._onTouchEnd = null;
/**
* @property {function} _onTouchEnter - Internal event handler reference.
* @private
*/
this._onTouchEnter = null; this._onTouchEnter = null;
/**
* @property {function} _onTouchLeave - Internal event handler reference.
* @private
*/
this._onTouchLeave = null; this._onTouchLeave = null;
/**
* @property {function} _onTouchCancel - Internal event handler reference.
* @private
*/
this._onTouchCancel = null; this._onTouchCancel = null;
/**
* @property {function} _onTouchMove - Internal event handler reference.
* @private
*/
this._onTouchMove = null; 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 * @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) { onTouchStart: function (event) {
this.event = event;
if (this.touchStartCallback) if (this.touchStartCallback)
{ {
this.touchStartCallback.call(this.callbackContext, event); 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). * 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. * Occurs for example on iOS when you put down 4 fingers and the app selector UI appears.
* @method Phaser.Touch#onTouchCancel * @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) { onTouchCancel: function (event) {
this.event = event;
if (this.touchCancelCallback) if (this.touchCancelCallback)
{ {
this.touchCancelCallback.call(this.callbackContext, event); 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. * 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. * Doesn't appear to be supported by most browsers on a canvas element yet.
* @method Phaser.Touch#onTouchEnter * @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) { onTouchEnter: function (event) {
this.event = event;
if (this.touchEnterCallback) if (this.touchEnterCallback)
{ {
this.touchEnterCallback.call(this.callbackContext, event); this.touchEnterCallback.call(this.callbackContext, event);
@@ -230,10 +268,12 @@ Phaser.Touch.prototype = {
event.preventDefault(); event.preventDefault();
} }
/*
for (var i = 0; i < event.changedTouches.length; i++) for (var i = 0; i < event.changedTouches.length; i++)
{ {
//console.log('touch enter'); //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. * 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. * Doesn't appear to be supported by most browsers on a canvas element yet.
* @method Phaser.Touch#onTouchLeave * @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) { onTouchLeave: function (event) {
this.event = event;
if (this.touchLeaveCallback) if (this.touchLeaveCallback)
{ {
this.touchLeaveCallback.call(this.callbackContext, event); this.touchLeaveCallback.call(this.callbackContext, event);
@@ -255,20 +297,24 @@ Phaser.Touch.prototype = {
event.preventDefault(); event.preventDefault();
} }
/*
for (var i = 0; i < event.changedTouches.length; i++) for (var i = 0; i < event.changedTouches.length; i++)
{ {
//console.log('touch leave'); //console.log('touch leave');
} }
*/
}, },
/** /**
* Description. * The handler for the touchmove events.
* @method Phaser.Touch#onTouchMove * @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) { onTouchMove: function (event) {
this.event = event;
if (this.touchMoveCallback) if (this.touchMoveCallback)
{ {
this.touchMoveCallback.call(this.callbackContext, event); this.touchMoveCallback.call(this.callbackContext, event);
@@ -287,12 +333,14 @@ Phaser.Touch.prototype = {
}, },
/** /**
* Description. * The handler for the touchend events.
* @method Phaser.Touch#onTouchEnd * @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) { onTouchEnd: function (event) {
this.event = event;
if (this.touchEndCallback) if (this.touchEndCallback)
{ {
this.touchEndCallback.call(this.callbackContext, event); this.touchEndCallback.call(this.callbackContext, event);
+2 -2
View File
@@ -588,7 +588,7 @@ Phaser.Cache.prototype = {
*/ */
getFrame: function (key) { 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; return this._images[key].frame;
} }
@@ -692,7 +692,7 @@ Phaser.Cache.prototype = {
*/ */
isSoundReady: function (key) { 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);
}, },
+4 -4
View File
@@ -149,7 +149,7 @@ Phaser.Loader.prototype = {
this.preloadSprite = { sprite: sprite, direction: direction, width: sprite.width, height: sprite.height, crop: null }; this.preloadSprite = { sprite: sprite, direction: direction, width: sprite.width, height: sprite.height, crop: null };
if (direction == 0) if (direction === 0)
{ {
// Horizontal crop // Horizontal crop
this.preloadSprite.crop = new Phaser.Rectangle(0, 0, 1, sprite.height); 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 (typeof overwrite === "undefined") { overwrite = false; }
if (overwrite || this.checkKeyExists(key) == false) if (overwrite || this.checkKeyExists(key) === false)
{ {
this.addToFileList('image', key, url); this.addToFileList('image', key, url);
} }
@@ -268,7 +268,7 @@ Phaser.Loader.prototype = {
if (typeof overwrite === "undefined") { overwrite = false; } if (typeof overwrite === "undefined") { overwrite = false; }
if (overwrite || this.checkKeyExists(key) == false) if (overwrite || this.checkKeyExists(key) === false)
{ {
this.addToFileList('text', key, url); this.addToFileList('text', key, url);
} }
@@ -1085,7 +1085,7 @@ Phaser.Loader.prototype = {
if (this.preloadSprite !== null) 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); this.preloadSprite.crop.width = Math.floor((this.preloadSprite.width / 100) * this.progress);
} }
+7 -7
View File
@@ -134,7 +134,7 @@ Phaser.Math = {
if (typeof start === "undefined") { start = 0; } if (typeof start === "undefined") { start = 0; }
if (gap == 0) { if (gap === 0) {
return input; return input;
} }
@@ -160,7 +160,7 @@ Phaser.Math = {
if (typeof start === "undefined") { start = 0; } if (typeof start === "undefined") { start = 0; }
if (gap == 0) { if (gap === 0) {
return input; return input;
} }
@@ -186,7 +186,7 @@ Phaser.Math = {
if (typeof start === "undefined") { start = 0; } if (typeof start === "undefined") { start = 0; }
if (gap == 0) { if (gap === 0) {
return input; return input;
} }
@@ -238,7 +238,7 @@ Phaser.Math = {
* e.g. * e.g.
* 2000/7 ~= 285.714285714285714285714 ~= (bin)100011101.1011011011011011 * 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,2) == 300
* roundTo(2000/7,1) == 290 * roundTo(2000/7,1) == 290
* roundTo(2000/7,0) == 286 * roundTo(2000/7,0) == 286
@@ -844,7 +844,7 @@ Phaser.Math = {
var l = length; var l = length;
if ((l == 0) || (l > objects.length - startIndex)) if ((l === 0) || (l > objects.length - startIndex))
{ {
l = objects.length - startIndex; l = objects.length - startIndex;
} }
@@ -972,7 +972,7 @@ Phaser.Math = {
* @param {number} x2 * @param {number} x2
* @param {number} y2 * @param {number} y2
* @return {number} The distance between this Point object and the destination Point object. * @return {number} The distance between this Point object and the destination Point object.
**/ */
distance: function (x1, y1, x2, y2) { distance: function (x1, y1, x2, y2) {
var dx = x1 - x2; var dx = x1 - x2;
@@ -991,7 +991,7 @@ Phaser.Math = {
* @param {number} x2 * @param {number} x2
* @param {number} y2 * @param {number} y2
* @return {number} The distance between this Point object and the destination Point object. * @return {number} The distance between this Point object and the destination Point object.
**/ */
distanceRounded: function (x1, y1, x2, y2) { distanceRounded: function (x1, y1, x2, y2) {
return Math.round(Phaser.Math.distance(x1, y1, x2, y2)); return Math.round(Phaser.Math.distance(x1, y1, x2, y2));
+1 -1
View File
@@ -136,7 +136,7 @@ Phaser.Particles.Arcade.Emitter = function (game, x, y, maxParticles) {
this.angularDrag = 0; 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 * @property {boolean} frequency
* @default * @default
*/ */
@@ -104,7 +104,7 @@ GridBroadphase.prototype.getCollisionPairs = function(world){
} }
} else if(si instanceof Plane){ } else if(si instanceof Plane){
// Put in all bins for now // Put in all bins for now
if(bi.angle == 0){ if(bi.angle === 0){
var y = bi.position[1]; var y = bi.position[1];
for(var j=0; j!==Nbins && ymin+binsizeY*(j-1)<y; j++){ for(var j=0; j!==Nbins && ymin+binsizeY*(j-1)<y; j++){
for(var k=0; k<nx; k++){ for(var k=0; k<nx; k++){
+4 -4
View File
@@ -194,7 +194,7 @@
i++; i++;
} }
} }
if(iscs.length == 0) return [p.slice(0)]; if(iscs.length === 0) return [p.slice(0)];
var comp = function(u,v) {return PolyK._P.dist(a,u) - PolyK._P.dist(a,v); } var comp = function(u,v) {return PolyK._P.dist(a,u) - PolyK._P.dist(a,v); }
iscs.sort(comp); iscs.sort(comp);
@@ -226,7 +226,7 @@
ps = PolyK._getPoints(ps, ind1, ind0); ps = PolyK._getPoints(ps, ind1, ind0);
i0.flag = i1.flag = false; i0.flag = i1.flag = false;
iscs.splice(0,2); iscs.splice(0,2);
if(iscs.length == 0) pgs.push(ps); if(iscs.length === 0) pgs.push(ps);
} }
else { dir++; iscs.reverse(); } else { dir++; iscs.reverse(); }
if(dir>1) break; if(dir>1) break;
@@ -402,7 +402,7 @@
var day = (a1.y-a2.y), dby = (b1.y-b2.y); var day = (a1.y-a2.y), dby = (b1.y-b2.y);
var Den = dax*dby - day*dbx; 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 A = (a1.x * a2.y - a1.y * a2.x);
var B = (b1.x * b2.y - b1.y * b2.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 day = (a1.y-a2.y), dby = (b1.y-b2.y);
var Den = dax*dby - day*dbx; 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 A = (a1.x * a2.y - a1.y * a2.x);
var B = (b1.x * b2.y - b1.y * b2.x); var B = (b1.x * b2.y - b1.y * b2.x);
+1 -1
View File
@@ -167,7 +167,7 @@ function Body(options){
* var kinematicBody = new Body(); * var kinematicBody = new Body();
* kinematicBody.motionState = Body.KINEMATIC; * 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 * Bounding circle radius
+23 -23
View File
@@ -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); 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; return;
} }
@@ -448,12 +448,12 @@ Phaser.Physics.Arcade.prototype = {
*/ */
collideGroupVsTilemapLayer: function (group, tilemapLayer, collideCallback, processCallback, callbackContext) { collideGroupVsTilemapLayer: function (group, tilemapLayer, collideCallback, processCallback, callbackContext) {
if (group.length == 0) if (group.length === 0)
{ {
return; return;
} }
if (group.length == 0) if (group.length === 0)
{ {
return; return;
} }
@@ -521,7 +521,7 @@ Phaser.Physics.Arcade.prototype = {
*/ */
collideSpriteVsGroup: function (sprite, group, collideCallback, processCallback, callbackContext) { collideSpriteVsGroup: function (sprite, group, collideCallback, processCallback, callbackContext) {
if (group.length == 0) if (group.length === 0)
{ {
return; return;
} }
@@ -563,7 +563,7 @@ Phaser.Physics.Arcade.prototype = {
*/ */
collideGroupVsGroup: function (group1, group2, collideCallback, processCallback, callbackContext) { collideGroupVsGroup: function (group1, group2, collideCallback, processCallback, callbackContext) {
if (group1.length == 0 || group2.length == 0) if (group1.length === 0 || group2.length === 0)
{ {
return; return;
} }
@@ -620,7 +620,7 @@ Phaser.Physics.Arcade.prototype = {
{ {
this._maxOverlap = body1.deltaAbsX() + body2.deltaAbsX() + this.OVERLAP_BIAS; 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 // They overlap but neither of them are moving
body1.embedded = true; body1.embedded = true;
@@ -631,7 +631,7 @@ Phaser.Physics.Arcade.prototype = {
// Body1 is moving right and/or Body2 is moving left // Body1 is moving right and/or Body2 is moving left
this._overlap = body1.x + body1.width - body2.x; 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; this._overlap = 0;
} }
@@ -646,7 +646,7 @@ Phaser.Physics.Arcade.prototype = {
// Body1 is moving left and/or Body2 is moving right // Body1 is moving left and/or Body2 is moving right
this._overlap = body1.x - body2.width - body2.x; 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; this._overlap = 0;
} }
@@ -728,7 +728,7 @@ Phaser.Physics.Arcade.prototype = {
{ {
this._maxOverlap = body1.deltaAbsY() + body2.deltaAbsY() + this.OVERLAP_BIAS; 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 // They overlap but neither of them are moving
body1.embedded = true; body1.embedded = true;
@@ -739,7 +739,7 @@ Phaser.Physics.Arcade.prototype = {
// Body1 is moving down and/or Body2 is moving up // Body1 is moving down and/or Body2 is moving up
this._overlap = body1.y + body1.height - body2.y; 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; this._overlap = 0;
} }
@@ -754,7 +754,7 @@ Phaser.Physics.Arcade.prototype = {
// Body1 is moving up and/or Body2 is moving down // Body1 is moving up and/or Body2 is moving down
this._overlap = body1.y - body2.height - body2.y; 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; this._overlap = 0;
} }
@@ -852,7 +852,7 @@ Phaser.Physics.Arcade.prototype = {
separateTileX: function (body, tile, separate) { separateTileX: function (body, tile, separate) {
// Can't separate two immovable objects (tiles are always immovable) // 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; return false;
} }
@@ -867,8 +867,8 @@ Phaser.Physics.Arcade.prototype = {
// Moving left // Moving left
this._overlap = tile.right - body.hullX.x; this._overlap = tile.right - body.hullX.x;
// if ((this._overlap > this._maxOverlap) || 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) if (body.allowCollision.left === false || tile.tile.collideRight === false)
{ {
this._overlap = 0; this._overlap = 0;
} }
@@ -882,8 +882,8 @@ Phaser.Physics.Arcade.prototype = {
// Moving right // Moving right
this._overlap = body.hullX.right - tile.x; this._overlap = body.hullX.right - tile.x;
// if ((this._overlap > this._maxOverlap) || 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) if (body.allowCollision.right === false || tile.tile.collideLeft === false)
{ {
this._overlap = 0; this._overlap = 0;
} }
@@ -907,7 +907,7 @@ Phaser.Physics.Arcade.prototype = {
body.x = body.x - this._overlap; body.x = body.x - this._overlap;
} }
if (body.bounce.x == 0) if (body.bounce.x === 0)
{ {
body.velocity.x = 0; body.velocity.x = 0;
} }
@@ -938,7 +938,7 @@ Phaser.Physics.Arcade.prototype = {
separateTileY: function (body, tile, separate) { separateTileY: function (body, tile, separate) {
// Can't separate two immovable objects (tiles are always immovable) // 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; return false;
} }
@@ -953,8 +953,8 @@ Phaser.Physics.Arcade.prototype = {
// Moving up // Moving up
this._overlap = tile.bottom - body.hullY.y; this._overlap = tile.bottom - body.hullY.y;
// if ((this._overlap > this._maxOverlap) || 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) if (body.allowCollision.up === false || tile.tile.collideDown === false)
{ {
this._overlap = 0; this._overlap = 0;
} }
@@ -968,8 +968,8 @@ Phaser.Physics.Arcade.prototype = {
// Moving down // Moving down
this._overlap = body.hullY.bottom - tile.y; this._overlap = body.hullY.bottom - tile.y;
// if ((this._overlap > this._maxOverlap) || 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) if (body.allowCollision.down === false || tile.tile.collideUp === false)
{ {
this._overlap = 0; this._overlap = 0;
} }
@@ -993,7 +993,7 @@ Phaser.Physics.Arcade.prototype = {
body.y = body.y - this._overlap; body.y = body.y - this._overlap;
} }
if (body.bounce.y == 0) if (body.bounce.y === 0)
{ {
body.velocity.y = 0; body.velocity.y = 0;
} }
+5 -5
View File
@@ -380,7 +380,7 @@ Phaser.Physics.Arcade.Body.prototype = {
this.updateHulls(); 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.quadTreeIDs = [];
this.quadTreeIndex = -1; 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. * 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 * @method bottom
* @return {number} * @return {number}
**/ */
get: function () { get: function () {
return this.y + this.height; 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. * 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 * @method bottom
* @param {number} value * @param {number} value
**/ */
set: function (value) { set: function (value) {
if (value <= this.y) if (value <= this.y)
@@ -618,7 +618,7 @@ Object.defineProperty(Phaser.Physics.Arcade.Body.prototype, "right", {
* However it does affect the width property. * However it does affect the width property.
* @method right * @method right
* @return {number} * @return {number}
**/ */
get: function () { get: function () {
return this.x + this.width; return this.x + this.width;
}, },
@@ -628,7 +628,7 @@ Object.defineProperty(Phaser.Physics.Arcade.Body.prototype, "right", {
* However it does affect the width property. * However it does affect the width property.
* @method right * @method right
* @param {number} value * @param {number} value
**/ */
set: function (value) { set: function (value) {
if (value <= this.x) if (value <= this.x)
+1 -1
View File
@@ -166,7 +166,7 @@ PIXI.DisplayObjectContainer.prototype.addChildAt = function(child, index)
updateLast = updateLast.parent; updateLast = updateLast.parent;
} }
} }
else if(index == 0) else if(index === 0)
{ {
previousObject = this; previousObject = this;
} }
+6 -6
View File
@@ -296,7 +296,7 @@ spine.Animation.prototype = {
spine.binarySearch = function (values, target, step) { spine.binarySearch = function (values, target, step) {
var low = 0; var low = 0;
var high = Math.floor(values.length / step) - 2; var high = Math.floor(values.length / step) - 2;
if (high == 0) return step; if (high === 0) return step;
var current = high >>> 1; var current = high >>> 1;
while (true) { while (true) {
if (values[(current + 1) * step] <= target) if (values[(current + 1) * step] <= target)
@@ -368,7 +368,7 @@ spine.Curves.prototype = {
var lastY = y - dfy; var lastY = y - dfy;
return lastY + (y - lastY) * (percent - lastX) / (x - lastX); return lastY + (y - lastY) * (percent - lastX) / (x - lastX);
} }
if (i == 0) break; if (i === 0) break;
i--; i--;
dfx += ddfx; dfx += ddfx;
dfy += ddfy; dfy += ddfy;
@@ -711,7 +711,7 @@ spine.Skeleton.prototype = {
}, },
/** @return May return null. */ /** @return May return null. */
getRootBone: function () { getRootBone: function () {
return this.bones.length == 0 ? null : this.bones[0]; return this.bones.length === 0 ? null : this.bones[0];
}, },
/** @return May be null. */ /** @return May be null. */
findBone: function (boneName) { findBone: function (boneName) {
@@ -983,7 +983,7 @@ spine.AnimationState.prototype = {
entry.loop = loop; entry.loop = loop;
if (!delay || delay <= 0) { 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) if (previousAnimation != null)
delay = previousAnimation.duration - this.data.getMix(previousAnimation, animation) + (delay || 0); delay = previousAnimation.duration - this.data.getMix(previousAnimation, animation) + (delay || 0);
else else
@@ -1232,7 +1232,7 @@ spine.Atlas = function (atlasText, textureLoader) {
var line = reader.readLine(); var line = reader.readLine();
if (line == null) break; if (line == null) break;
line = reader.trim(line); line = reader.trim(line);
if (line.length == 0) if (line.length === 0)
page = null; page = null;
else if (!page) { else if (!page) {
page = new spine.AtlasPage(); page = new spine.AtlasPage();
@@ -1421,7 +1421,7 @@ spine.AtlasReader.prototype = {
for (; i < 3; i++) { for (; i < 3; i++) {
var comma = line.indexOf(",", lastMatch); var comma = line.indexOf(",", lastMatch);
if (comma == -1) { if (comma == -1) {
if (i == 0) throw "Invalid line: " + line; if (i === 0) throw "Invalid line: " + line;
break; break;
} }
tuple[i] = this.trim(line.substr(lastMatch, comma - lastMatch)); tuple[i] = this.trim(line.substr(lastMatch, comma - lastMatch));
+4 -4
View File
@@ -29,25 +29,25 @@ PIXI.CrossHatchFilter = function()
" gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);", " gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);",
" ", " ",
" if (lum < 1.00) {", " 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);", " gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);",
" }", " }",
" }", " }",
" ", " ",
" if (lum < 0.75) {", " 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);", " gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);",
" }", " }",
" }", " }",
" ", " ",
" if (lum < 0.50) {", " 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);", " gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);",
" }", " }",
" }", " }",
" ", " ",
" if (lum < 0.3) {", " 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);", " gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);",
" }", " }",
" }", " }",
+1 -1
View File
@@ -113,7 +113,7 @@ PIXI.AssetLoader.prototype.onAssetLoaded = function()
this.dispatchEvent({type: "onProgress", content: this}); this.dispatchEvent({type: "onProgress", content: this});
if(this.onProgress) this.onProgress(); if(this.onProgress) this.onProgress();
if(this.loadCount == 0) if(this.loadCount === 0)
{ {
this.dispatchEvent({type: "onComplete", content: this}); this.dispatchEvent({type: "onComplete", content: this});
if(this.onComplete) this.onComplete(); if(this.onComplete) this.onComplete();
+5 -5
View File
@@ -75,7 +75,7 @@ PIXI.Graphics.prototype.constructor = PIXI.Graphics;
*/ */
PIXI.Graphics.prototype.lineStyle = function(lineWidth, color, alpha) 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.lineWidth = lineWidth || 0;
this.lineColor = color || 0; this.lineColor = color || 0;
@@ -96,7 +96,7 @@ PIXI.Graphics.prototype.lineStyle = function(lineWidth, color, alpha)
*/ */
PIXI.Graphics.prototype.moveTo = function(x, y) 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, 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}; 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 ) 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, this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha,
fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, 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) 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, this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha,
fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, 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) 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, this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha,
fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling,
+3 -3
View File
@@ -9,7 +9,7 @@ PIXI._batchs = [];
*/ */
PIXI._getBatch = function(gl) PIXI._getBatch = function(gl)
{ {
if(PIXI._batchs.length == 0) if(PIXI._batchs.length === 0)
{ {
return new PIXI.WebGLBatch(gl); return new PIXI.WebGLBatch(gl);
} }
@@ -189,7 +189,7 @@ PIXI.WebGLBatch.prototype.remove = function(sprite)
{ {
this.size--; this.size--;
if(this.size == 0) if(this.size === 0)
{ {
sprite.batch = null; sprite.batch = null;
sprite.__prev = null; sprite.__prev = null;
@@ -522,7 +522,7 @@ PIXI.WebGLBatch.prototype.render = function(start, end)
this.dirty = false; this.dirty = false;
} }
if (this.size == 0)return; if (this.size === 0)return;
this.update(); this.update();
var gl = this.gl; var gl = this.gl;
+1 -1
View File
@@ -280,7 +280,7 @@ PIXI.WebGLGraphics.buildLine = function(graphicsData, webGLData)
var wrap = true; var wrap = true;
var points = graphicsData.points; 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 the line width is an odd number add 0.5 to align to a whole pixel
if(graphicsData.lineWidth%2) if(graphicsData.lineWidth%2)
+2 -2
View File
@@ -775,7 +775,7 @@ PIXI.WebGLRenderGroup.prototype.removeObject = function(displayObject)
// ok so.. check to see if you adjacent batchs should be joined. // ok so.. check to see if you adjacent batchs should be joined.
// TODO may optimise? // 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! // wha - eva! just get of the empty batch!
this.batchs.splice(index, 1); this.batchs.splice(index, 1);
@@ -848,7 +848,7 @@ PIXI.WebGLRenderGroup.prototype.initTilingSprite = function(sprite)
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, sprite._indexBuffer); gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, sprite._indexBuffer);
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, sprite.indices, gl.STATIC_DRAW); 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) if(sprite.texture.baseTexture._glTexture)
{ {
+1 -1
View File
@@ -111,7 +111,7 @@ PIXI.WebGLRenderer.prototype.constructor = PIXI.WebGLRenderer;
*/ */
PIXI.WebGLRenderer.getBatch = function() PIXI.WebGLRenderer.getBatch = function()
{ {
if(PIXI._batchs.length == 0) if(PIXI._batchs.length === 0)
{ {
return new PIXI.WebGLBatch(PIXI.WebGLRenderer.gl); return new PIXI.WebGLBatch(PIXI.WebGLRenderer.gl);
} }
+4 -4
View File
@@ -432,7 +432,7 @@ Phaser.Sound.prototype = {
// console.log(this.name + ' play ' + marker + ' position ' + position + ' volume ' + volume + ' loop ' + loop, 'force', forceRestart); // 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 // Use Restart instead
return; return;
@@ -517,7 +517,7 @@ Phaser.Sound.prototype = {
this._sound.connect(this.gainNode); this._sound.connect(this.gainNode);
this.totalDuration = this._sound.buffer.duration; this.totalDuration = this._sound.buffer.duration;
if (this.duration == 0) if (this.duration === 0)
{ {
// console.log('duration reset'); // console.log('duration reset');
this.duration = this.totalDuration; this.duration = this.totalDuration;
@@ -552,7 +552,7 @@ Phaser.Sound.prototype = {
{ {
this.pendingPlayback = true; 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); 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 doesn't become available until you call play(), wonderful ...
this.totalDuration = this._sound.duration; this.totalDuration = this._sound.duration;
if (this.duration == 0) if (this.duration === 0)
{ {
this.duration = this.totalDuration; this.duration = this.totalDuration;
this.durationMS = this.totalDuration * 1000; this.durationMS = this.totalDuration * 1000;
+6 -6
View File
@@ -101,7 +101,7 @@ Phaser.SoundManager.prototype = {
*/ */
boot: function () { 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; this.channels = 1;
} }
@@ -123,7 +123,7 @@ Phaser.SoundManager.prototype = {
if (window['PhaserGlobal']) if (window['PhaserGlobal'])
{ {
// Check to see if all audio playback is disabled (i.e. handled by a 3rd party class) // 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.usingWebAudio = false;
this.noAudio = true; 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) // 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.usingWebAudio = false;
this.usingAudioTag = true; this.usingAudioTag = true;
@@ -183,13 +183,13 @@ Phaser.SoundManager.prototype = {
*/ */
unlock: function () { unlock: function () {
if (this.touchLocked == false) if (this.touchLocked === false)
{ {
return; return;
} }
// Global override (mostly for Audio Tag testing) // 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? // Create an Audio tag?
this.touchLocked = false; this.touchLocked = false;
@@ -404,7 +404,7 @@ Object.defineProperty(Phaser.SoundManager.prototype, "mute", {
} }
else else
{ {
if (this._muted == false) if (this._muted === false)
{ {
return; return;
} }
+11 -11
View File
@@ -348,7 +348,7 @@ Phaser.StageScaleMode.prototype = {
if (typeof orientationImage !== 'undefined') if (typeof orientationImage !== 'undefined')
{ {
if (orientationImage == null || this.game.cache.checkImageKey(orientationImage) == false) if (orientationImage == null || this.game.cache.checkImageKey(orientationImage) === false)
{ {
orientationImage = '__default'; orientationImage = '__default';
} }
@@ -411,7 +411,7 @@ Phaser.StageScaleMode.prototype = {
this.incorrectOrientation = true; this.incorrectOrientation = true;
this.enterIncorrectOrientation.dispatch(); this.enterIncorrectOrientation.dispatch();
if (this.orientationSprite && this.orientationSprite.visible == false) if (this.orientationSprite && this.orientationSprite.visible === false)
{ {
this.orientationSprite.visible = true; this.orientationSprite.visible = true;
this.game.world.visible = false; this.game.world.visible = false;
@@ -488,9 +488,9 @@ Phaser.StageScaleMode.prototype = {
refresh: function () { refresh: function () {
// We can't do anything about the status bars in iPads, web apps or desktops // 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); window.scrollTo(0, 1);
} }
@@ -526,9 +526,9 @@ Phaser.StageScaleMode.prototype = {
force = false; 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); window.scrollTo(0, 1);
} }
@@ -545,7 +545,7 @@ Phaser.StageScaleMode.prototype = {
// Set minimum height of content to new window height // Set minimum height of content to new window height
document.documentElement['style'].minHeight = window.innerHeight + 'px'; document.documentElement['style'].minHeight = window.innerHeight + 'px';
if (this.incorrectOrientation == true) if (this.incorrectOrientation === true)
{ {
this.setMaximum(); this.setMaximum();
} }
@@ -571,7 +571,7 @@ Phaser.StageScaleMode.prototype = {
*/ */
setSize: function () { setSize: function () {
if (this.incorrectOrientation == false) if (this.incorrectOrientation === false)
{ {
if (this.maxWidth && this.width > this.maxWidth) if (this.maxWidth && this.width > this.maxWidth)
{ {
@@ -601,7 +601,7 @@ Phaser.StageScaleMode.prototype = {
if (this.pageAlignHorizontally) 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.margin.x = Math.round((window.innerWidth - this.width) / 2);
this.game.canvas.style.marginLeft = this.margin.x + 'px'; this.game.canvas.style.marginLeft = this.margin.x + 'px';
@@ -615,7 +615,7 @@ Phaser.StageScaleMode.prototype = {
if (this.pageAlignVertically) 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.margin.y = Math.round((window.innerHeight - this.height) / 2);
this.game.canvas.style.marginTop = this.margin.y + 'px'; 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", { Object.defineProperty(Phaser.StageScaleMode.prototype, "isPortrait", {
get: function () { get: function () {
return this.orientation == 0 || this.orientation == 180; return this.orientation === 0 || this.orientation == 180;
} }
}); });
+2 -2
View File
@@ -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. * 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 * @method bottom
* @return {number} * @return {number}
**/ */
get: function () { get: function () {
return this.y + this.height; return this.y + this.height;
} }
@@ -205,7 +205,7 @@ Object.defineProperty(Phaser.Tile.prototype, "right", {
* However it does affect the width property. * However it does affect the width property.
* @method right * @method right
* @return {number} * @return {number}
**/ */
get: function () { get: function () {
return this.x + this.width; return this.x + this.width;
} }
+1 -1
View File
@@ -433,7 +433,7 @@ Phaser.TilemapLayer.prototype.getTiles = function (x, y, width, height, collides
sx = _tile.width * this.scale.x; sx = _tile.width * this.scale.x;
sy = _tile.height * this.scale.y; 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 // convert tile coordinates back to camera space for return
var _wx = this._unfixX( wx*sx ) / tileWidth; var _wx = this._unfixX( wx*sx ) / tileWidth;
+3 -3
View File
@@ -34,7 +34,7 @@ Phaser.TilemapParser = {
} }
// Zero or smaller than tile sizes? // 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"); console.warn("Phaser.TilemapParser.tileSet: width/height zero or width/height < given tileWidth/tileHeight");
return null; return null;
@@ -103,7 +103,7 @@ Phaser.TilemapParser = {
output[i][c] = parseInt(column[c]); output[i][c] = parseInt(column[c]);
} }
if (width == 0) if (width === 0)
{ {
width = column.length; width = column.length;
} }
@@ -155,7 +155,7 @@ Phaser.TilemapParser = {
for (var t = 0; t < json.layers[i].data.length; t++) for (var t = 0; t < json.layers[i].data.length; t++)
{ {
if (c == 0) if (c === 0)
{ {
row = []; row = [];
} }
+1 -1
View File
@@ -98,7 +98,7 @@ Phaser.Timer.prototype = {
for (var i = 0, len = this.events.length; i < len; i++) 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].dispatched = true;
// this.events[i].callback.apply(this.events[i].callbackContext, this.events[i].args); // this.events[i].callback.apply(this.events[i].callbackContext, this.events[i].args);
+1 -1
View File
@@ -326,7 +326,7 @@ Phaser.Utils.Debug.prototype = {
upColor = upColor || 'rgba(255,0,0,0.5)'; upColor = upColor || 'rgba(255,0,0,0.5)';
color = color || 'rgb(255,255,255)'; color = color || 'rgb(255,255,255)';
if (hideIfUp == true && pointer.isUp == true) if (hideIfUp === true && pointer.isUp === true)
{ {
return; return;
} }