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

View file

@ -35,7 +35,7 @@
"eqnull" : true, // Tolerate use of `== null`.
"evil" : false, // Tolerate use of `eval`.
"expr" : false, // Tolerate `ExpressionStatement` as Programs.
"forin" : true, // Tolerate `for in` loops without `hasOwnPrototype`.
"forin" : false, // Tolerate `for in` loops without `hasOwnPrototype`.
"freeze" : true, // Prohibits overwriting prototypes of native objects such as Array and Date.
"funcscope" : true, // This option suppresses warnings about declaring variables inside of control structures while accessing them later from the outside.
"immed" : false, // Require immediate invocations to be wrapped in parens e.g. `( function(){}() );`
@ -69,7 +69,7 @@
"noempty" : true, // Prohibit use of empty blocks.
"nonew" : true, // Prohibit use of constructors for side-effects.
"plusplus" : false, // Prohibit use of `++` & `--`.
"quotmark" : true, // This option enforces the consistency of quotation marks used throughout your code.
"quotmark" : false, // This option enforces the consistency of quotation marks used throughout your code.
"sub" : true, // Tolerate all forms of subscript notation besides dot notation e.g. `dict['key']` instead of `dict.key`.
"trailing" : true // Prohibit trailing whitespaces.
}

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: Skip preupdate/update for PIXI hierarchies in which an ancestor doesn't exist (thanks cocoademon)
* Updated: Loader.audio can now accept either an array of URL strings or a single URL string (thanks crazysam + kevinthompson)
* Updated: MSPointer updated to support IE11 by dropping the prefix from the event listeners.
You can view the complete Change Log for all previous versions at https://github.com/photonstorm/phaser/changelog.md

View file

@ -53,7 +53,7 @@ PIXI.CanvasRenderer.prototype.renderDisplayObject = function(displayObject)
continue;
}
if (!displayObject.renderable || displayObject.alpha == 0)
if (!displayObject.renderable || displayObject.alpha === 0)
{
displayObject = displayObject._iNext;
continue;

View file

@ -17,49 +17,49 @@ Phaser.AnimationManager = function (sprite) {
/**
* @property {Phaser.Sprite} sprite - A reference to the parent Sprite that owns this AnimationManager.
*/
this.sprite = sprite;
this.sprite = sprite;
/**
* @property {Phaser.Game} game - A reference to the currently running Game.
*/
this.game = sprite.game;
this.game = sprite.game;
/**
* @property {Phaser.Frame} currentFrame - The currently displayed Frame of animation, if any.
* @default
*/
this.currentFrame = null;
/**
* @property {boolean} updateIfVisible - Should the animation data continue to update even if the Sprite.visible is set to false.
* @default
*/
this.updateIfVisible = true;
/**
* @property {Phaser.Frame} currentFrame - The currently displayed Frame of animation, if any.
* @default
*/
this.currentFrame = null;
/**
* @property {boolean} updateIfVisible - Should the animation data continue to update even if the Sprite.visible is set to false.
* @default
*/
this.updateIfVisible = true;
/**
* @property {boolean} isLoaded - Set to true once animation data has been loaded.
* @default
*/
this.isLoaded = false;
/**
* @property {boolean} isLoaded - Set to true once animation data has been loaded.
* @default
*/
this.isLoaded = false;
/**
* @property {Phaser.FrameData} _frameData - A temp. var for holding the currently playing Animations FrameData.
* @private
* @default
*/
this._frameData = null;
/**
* @property {Phaser.FrameData} _frameData - A temp. var for holding the currently playing Animations FrameData.
* @private
* @default
*/
this._frameData = null;
/**
* @property {object} _anims - An internal object that stores all of the Animation instances.
* @private
*/
this._anims = {};
/**
* @property {object} _anims - An internal object that stores all of the Animation instances.
* @private
*/
this._anims = {};
/**
* @property {object} _outputFrames - An internal object to help avoid gc.
* @private
*/
this._outputFrames = [];
/**
* @property {object} _outputFrames - An internal object to help avoid gc.
* @private
*/
this._outputFrames = [];
};
@ -73,226 +73,226 @@ Phaser.AnimationManager.prototype = {
* @private
* @param {Phaser.FrameData} frameData - The FrameData set to load.
*/
loadFrameData: function (frameData) {
loadFrameData: function (frameData) {
this._frameData = frameData;
this.frame = 0;
this.isLoaded = true;
this._frameData = frameData;
this.frame = 0;
this.isLoaded = true;
},
},
/**
* Adds a new animation under the given key. Optionally set the frames, frame rate and loop.
* Animations added in this way are played back with the play function.
*
/**
* Adds a new animation under the given key. Optionally set the frames, frame rate and loop.
* Animations added in this way are played back with the play function.
*
* @method Phaser.AnimationManager#add
* @param {string} name - The unique (within this Sprite) name for the animation, i.e. "run", "fire", "walk".
* @param {Array} [frames=null] - An array of numbers/strings that correspond to the frames to add to this animation and in which order. e.g. [1, 2, 3] or ['run0', 'run1', run2]). If null then all frames will be used.
* @param {number} [frameRate=60] - The speed at which the animation should play. The speed is given in frames per second.
* @param {boolean} [loop=false] - Whether or not the animation is looped or just plays once.
* @param {boolean} [useNumericIndex=true] - Are the given frames using numeric indexes (default) or strings?
* @return {Phaser.Animation} The Animation object that was created.
*/
add: function (name, frames, frameRate, loop, useNumericIndex) {
* @param {string} name - The unique (within this Sprite) name for the animation, i.e. "run", "fire", "walk".
* @param {Array} [frames=null] - An array of numbers/strings that correspond to the frames to add to this animation and in which order. e.g. [1, 2, 3] or ['run0', 'run1', run2]). If null then all frames will be used.
* @param {number} [frameRate=60] - The speed at which the animation should play. The speed is given in frames per second.
* @param {boolean} [loop=false] - Whether or not the animation is looped or just plays once.
* @param {boolean} [useNumericIndex=true] - Are the given frames using numeric indexes (default) or strings?
* @return {Phaser.Animation} The Animation object that was created.
*/
add: function (name, frames, frameRate, loop, useNumericIndex) {
if (this._frameData == null)
{
console.warn('No FrameData available for Phaser.Animation ' + name);
return;
}
if (this._frameData == null)
{
console.warn('No FrameData available for Phaser.Animation ' + name);
return;
}
frameRate = frameRate || 60;
frameRate = frameRate || 60;
if (typeof loop === 'undefined') { loop = false; }
if (typeof loop === 'undefined') { loop = false; }
// If they didn't set the useNumericIndex then let's at least try and guess it
if (typeof useNumericIndex === 'undefined')
{
if (frames && typeof frames[0] === 'number')
{
useNumericIndex = true;
}
else
{
useNumericIndex = false;
}
}
// If they didn't set the useNumericIndex then let's at least try and guess it
if (typeof useNumericIndex === 'undefined')
{
if (frames && typeof frames[0] === 'number')
{
useNumericIndex = true;
}
else
{
useNumericIndex = false;
}
}
// Create the signals the AnimationManager will emit
if (this.sprite.events.onAnimationStart == null)
{
this.sprite.events.onAnimationStart = new Phaser.Signal();
this.sprite.events.onAnimationComplete = new Phaser.Signal();
this.sprite.events.onAnimationLoop = new Phaser.Signal();
}
// Create the signals the AnimationManager will emit
if (this.sprite.events.onAnimationStart == null)
{
this.sprite.events.onAnimationStart = new Phaser.Signal();
this.sprite.events.onAnimationComplete = new Phaser.Signal();
this.sprite.events.onAnimationLoop = new Phaser.Signal();
}
this._outputFrames.length = 0;
this._outputFrames.length = 0;
this._frameData.getFrameIndexes(frames, useNumericIndex, this._outputFrames);
this._frameData.getFrameIndexes(frames, useNumericIndex, this._outputFrames);
this._anims[name] = new Phaser.Animation(this.game, this.sprite, name, this._frameData, this._outputFrames, frameRate, loop);
this.currentAnim = this._anims[name];
this.currentFrame = this.currentAnim.currentFrame;
this.sprite.setTexture(PIXI.TextureCache[this.currentFrame.uuid]);
this._anims[name] = new Phaser.Animation(this.game, this.sprite, name, this._frameData, this._outputFrames, frameRate, loop);
this.currentAnim = this._anims[name];
this.currentFrame = this.currentAnim.currentFrame;
this.sprite.setTexture(PIXI.TextureCache[this.currentFrame.uuid]);
return this._anims[name];
return this._anims[name];
},
},
/**
* Check whether the frames in the given array are valid and exist.
*
/**
* Check whether the frames in the given array are valid and exist.
*
* @method Phaser.AnimationManager#validateFrames
* @param {Array} frames - An array of frames to be validated.
* @param {boolean} [useNumericIndex=true] - Validate the frames based on their numeric index (true) or string index (false)
* @return {boolean} True if all given Frames are valid, otherwise false.
*/
validateFrames: function (frames, useNumericIndex) {
* @param {Array} frames - An array of frames to be validated.
* @param {boolean} [useNumericIndex=true] - Validate the frames based on their numeric index (true) or string index (false)
* @return {boolean} True if all given Frames are valid, otherwise false.
*/
validateFrames: function (frames, useNumericIndex) {
if (typeof useNumericIndex == 'undefined') { useNumericIndex = true; }
if (typeof useNumericIndex == 'undefined') { useNumericIndex = true; }
for (var i = 0; i < frames.length; i++)
{
if (useNumericIndex == true)
{
if (frames[i] > this._frameData.total)
{
return false;
}
}
else
{
if (this._frameData.checkFrameName(frames[i]) == false)
{
return false;
}
}
}
for (var i = 0; i < frames.length; i++)
{
if (useNumericIndex === true)
{
if (frames[i] > this._frameData.total)
{
return false;
}
}
else
{
if (this._frameData.checkFrameName(frames[i]) === false)
{
return false;
}
}
}
return true;
return true;
},
},
/**
* Play an animation based on the given key. The animation should previously have been added via sprite.animations.add()
* If the requested animation is already playing this request will be ignored. If you need to reset an already running animation do so directly on the Animation object itself.
*
* @method Phaser.AnimationManager#play
* @param {string} name - The name of the animation to be played, e.g. "fire", "walk", "jump".
/**
* Play an animation based on the given key. The animation should previously have been added via sprite.animations.add()
* If the requested animation is already playing this request will be ignored. If you need to reset an already running animation do so directly on the Animation object itself.
*
* @method Phaser.AnimationManager#play
* @param {string} name - The name of the animation to be played, e.g. "fire", "walk", "jump".
* @param {number} [frameRate=null] - The framerate to play the animation at. The speed is given in frames per second. If not provided the previously set frameRate of the Animation is used.
* @param {boolean} [loop=false] - Should the animation be looped after playback. If not provided the previously set loop value of the Animation is used.
* @param {boolean} [killOnComplete=false] - If set to true when the animation completes (only happens if loop=false) the parent Sprite will be killed.
* @return {Phaser.Animation} A reference to playing Animation instance.
*/
play: function (name, frameRate, loop, killOnComplete) {
*/
play: function (name, frameRate, loop, killOnComplete) {
if (this._anims[name])
{
if (this.currentAnim == this._anims[name])
{
if (this.currentAnim.isPlaying == false)
{
this.currentAnim.paused = false;
return this.currentAnim.play(frameRate, loop, killOnComplete);
}
}
else
{
this.currentAnim = this._anims[name];
this.currentAnim.paused = false;
return this.currentAnim.play(frameRate, loop, killOnComplete);
}
}
if (this._anims[name])
{
if (this.currentAnim == this._anims[name])
{
if (this.currentAnim.isPlaying === false)
{
this.currentAnim.paused = false;
return this.currentAnim.play(frameRate, loop, killOnComplete);
}
}
else
{
this.currentAnim = this._anims[name];
this.currentAnim.paused = false;
return this.currentAnim.play(frameRate, loop, killOnComplete);
}
}
},
},
/**
* Stop playback of an animation. If a name is given that specific animation is stopped, otherwise the current animation is stopped.
* The currentAnim property of the AnimationManager is automatically set to the animation given.
*
* @method Phaser.AnimationManager#stop
* @param {string} [name=null] - The name of the animation to be stopped, e.g. "fire". If none is given the currently running animation is stopped.
* @param {boolean} [resetFrame=false] - When the animation is stopped should the currentFrame be set to the first frame of the animation (true) or paused on the last frame displayed (false)
*/
stop: function (name, resetFrame) {
/**
* Stop playback of an animation. If a name is given that specific animation is stopped, otherwise the current animation is stopped.
* The currentAnim property of the AnimationManager is automatically set to the animation given.
*
* @method Phaser.AnimationManager#stop
* @param {string} [name=null] - The name of the animation to be stopped, e.g. "fire". If none is given the currently running animation is stopped.
* @param {boolean} [resetFrame=false] - When the animation is stopped should the currentFrame be set to the first frame of the animation (true) or paused on the last frame displayed (false)
*/
stop: function (name, resetFrame) {
if (typeof resetFrame == 'undefined') { resetFrame = false; }
if (typeof resetFrame == 'undefined') { resetFrame = false; }
if (typeof name == 'string')
{
if (this._anims[name])
{
this.currentAnim = this._anims[name];
this.currentAnim.stop(resetFrame);
}
}
else
{
if (this.currentAnim)
{
this.currentAnim.stop(resetFrame);
}
}
if (typeof name == 'string')
{
if (this._anims[name])
{
this.currentAnim = this._anims[name];
this.currentAnim.stop(resetFrame);
}
}
else
{
if (this.currentAnim)
{
this.currentAnim.stop(resetFrame);
}
}
},
},
/**
* The main update function is called by the Sprites update loop. It's responsible for updating animation frames and firing related events.
*
* @method Phaser.AnimationManager#update
* @protected
/**
* The main update function is called by the Sprites update loop. It's responsible for updating animation frames and firing related events.
*
* @method Phaser.AnimationManager#update
* @protected
* @return {boolean} True if a new animation frame has been set, otherwise false.
*/
update: function () {
*/
update: function () {
if (this.updateIfVisible && this.sprite.visible == false)
{
return false;
}
if (this.updateIfVisible && this.sprite.visible === false)
{
return false;
}
if (this.currentAnim && this.currentAnim.update() == true)
{
this.currentFrame = this.currentAnim.currentFrame;
this.sprite.currentFrame = this.currentFrame;
return true;
}
if (this.currentAnim && this.currentAnim.update() === true)
{
this.currentFrame = this.currentAnim.currentFrame;
this.sprite.currentFrame = this.currentFrame;
return true;
}
return false;
return false;
},
},
/**
* Returns an animation that was previously added by name.
*
* @method Phaser.AnimationManager#getAnimation
* @param {string} name - The name of the animation to be returned, e.g. "fire".
/**
* Returns an animation that was previously added by name.
*
* @method Phaser.AnimationManager#getAnimation
* @param {string} name - The name of the animation to be returned, e.g. "fire".
* @return {Phaser.Animation|boolean} The Animation instance, if found, otherwise false.
*/
getAnimation: function (name) {
*/
getAnimation: function (name) {
if (typeof name == 'string')
{
if (this._anims[name])
{
return this._anims[name];
}
}
if (typeof name == 'string')
{
if (this._anims[name])
{
return this._anims[name];
}
}
return false;
return false;
},
},
/**
* Refreshes the current frame data back to the parent Sprite and also resets the texture data.
*
* @method Phaser.AnimationManager#refreshFrame
*/
refreshFrame: function () {
refreshFrame: function () {
this.sprite.currentFrame = this.currentFrame;
this.sprite.setTexture(PIXI.TextureCache[this.currentFrame.uuid]);
this.sprite.setTexture(PIXI.TextureCache[this.currentFrame.uuid]);
},
},
/**
* Destroys all references this AnimationManager contains. Sets the _anims to a new object and nulls the current animation.
@ -316,7 +316,7 @@ Phaser.AnimationManager.prototype = {
* @property {Phaser.FrameData} frameData - The current animations FrameData.
* @readonly
*/
Object.defineProperty(Phaser.AnimationManager.prototype, "frameData", {
Object.defineProperty(Phaser.AnimationManager.prototype, 'frameData', {
get: function () {
return this._frameData;
@ -329,7 +329,7 @@ Object.defineProperty(Phaser.AnimationManager.prototype, "frameData", {
* @property {number} frameTotal - The total number of frames in the currently loaded FrameData, or -1 if no FrameData is loaded.
* @readonly
*/
Object.defineProperty(Phaser.AnimationManager.prototype, "frameTotal", {
Object.defineProperty(Phaser.AnimationManager.prototype, 'frameTotal', {
get: function () {
@ -349,7 +349,7 @@ Object.defineProperty(Phaser.AnimationManager.prototype, "frameTotal", {
* @name Phaser.AnimationManager#paused
* @property {boolean} paused - Gets and sets the paused state of the current animation.
*/
Object.defineProperty(Phaser.AnimationManager.prototype, "paused", {
Object.defineProperty(Phaser.AnimationManager.prototype, 'paused', {
get: function () {
@ -369,15 +369,15 @@ Object.defineProperty(Phaser.AnimationManager.prototype, "paused", {
* @name Phaser.AnimationManager#frame
* @property {number} frame - Gets or sets the current frame index and updates the Texture Cache for display.
*/
Object.defineProperty(Phaser.AnimationManager.prototype, "frame", {
Object.defineProperty(Phaser.AnimationManager.prototype, 'frame', {
get: function () {
if (this.currentFrame)
{
return this._frameIndex;
}
if (this.currentFrame)
{
return this._frameIndex;
}
},
set: function (value) {
@ -387,7 +387,7 @@ Object.defineProperty(Phaser.AnimationManager.prototype, "frame", {
this.currentFrame = this._frameData.getFrame(value);
this._frameIndex = value;
this.sprite.currentFrame = this.currentFrame;
this.sprite.setTexture(PIXI.TextureCache[this.currentFrame.uuid]);
this.sprite.setTexture(PIXI.TextureCache[this.currentFrame.uuid]);
}
}
@ -398,14 +398,14 @@ Object.defineProperty(Phaser.AnimationManager.prototype, "frame", {
* @name Phaser.AnimationManager#frameName
* @property {string} frameName - Gets or sets the current frame name and updates the Texture Cache for display.
*/
Object.defineProperty(Phaser.AnimationManager.prototype, "frameName", {
Object.defineProperty(Phaser.AnimationManager.prototype, 'frameName', {
get: function () {
if (this.currentFrame)
{
return this.currentFrame.name;
}
if (this.currentFrame)
{
return this.currentFrame.name;
}
},
@ -416,11 +416,11 @@ Object.defineProperty(Phaser.AnimationManager.prototype, "frameName", {
this.currentFrame = this._frameData.getFrameByName(value);
this._frameIndex = this.currentFrame.index;
this.sprite.currentFrame = this.currentFrame;
this.sprite.setTexture(PIXI.TextureCache[this.currentFrame.uuid]);
this.sprite.setTexture(PIXI.TextureCache[this.currentFrame.uuid]);
}
else
{
console.warn("Cannot set frameName: " + value);
console.warn('Cannot set frameName: ' + value);
}
}

View file

@ -55,7 +55,7 @@ Phaser.AnimationParser = {
}
// Zero or smaller than frame sizes?
if (width == 0 || height == 0 || width < frameWidth || height < frameHeight || total === 0)
if (width === 0 || height === 0 || width < frameWidth || height < frameHeight || total === 0)
{
console.warn("Phaser.AnimationParser.spriteSheet: width/height zero or width/height < given frameWidth/frameHeight");
return null;
@ -124,13 +124,13 @@ Phaser.AnimationParser = {
newFrame = data.addFrame(new Phaser.Frame(
i,
frames[i].frame.x,
frames[i].frame.y,
frames[i].frame.w,
frames[i].frame.h,
frames[i].filename,
frames[i].frame.x,
frames[i].frame.y,
frames[i].frame.w,
frames[i].frame.h,
frames[i].filename,
uuid
));
));
PIXI.TextureCache[uuid] = new PIXI.Texture(PIXI.BaseTextureCache[cacheKey], {
x: frames[i].frame.x,
@ -142,12 +142,12 @@ Phaser.AnimationParser = {
if (frames[i].trimmed)
{
newFrame.setTrim(
frames[i].trimmed,
frames[i].sourceSize.w,
frames[i].sourceSize.h,
frames[i].spriteSourceSize.x,
frames[i].spriteSourceSize.y,
frames[i].spriteSourceSize.w,
frames[i].trimmed,
frames[i].sourceSize.w,
frames[i].sourceSize.h,
frames[i].spriteSourceSize.x,
frames[i].spriteSourceSize.y,
frames[i].spriteSourceSize.w,
frames[i].spriteSourceSize.h
);
@ -196,10 +196,10 @@ Phaser.AnimationParser = {
newFrame = data.addFrame(new Phaser.Frame(
i,
frames[key].frame.x,
frames[key].frame.y,
frames[key].frame.w,
frames[key].frame.h,
frames[key].frame.x,
frames[key].frame.y,
frames[key].frame.w,
frames[key].frame.h,
key,
uuid
));
@ -214,12 +214,12 @@ Phaser.AnimationParser = {
if (frames[key].trimmed)
{
newFrame.setTrim(
frames[key].trimmed,
frames[key].sourceSize.w,
frames[key].sourceSize.h,
frames[key].spriteSourceSize.x,
frames[key].spriteSourceSize.y,
frames[key].spriteSourceSize.w,
frames[key].trimmed,
frames[key].sourceSize.w,
frames[key].sourceSize.h,
frames[key].spriteSourceSize.x,
frames[key].spriteSourceSize.y,
frames[key].spriteSourceSize.w,
frames[key].spriteSourceSize.h
);
@ -261,6 +261,7 @@ Phaser.AnimationParser = {
var newFrame;
var uuid;
var name;
var frame;
var x;
var y;
@ -278,20 +279,20 @@ Phaser.AnimationParser = {
frame = frames[i].attributes;
name = frame.name.nodeValue;
x = parseInt(frame.x.nodeValue);
y = parseInt(frame.y.nodeValue);
width = parseInt(frame.width.nodeValue);
height = parseInt(frame.height.nodeValue);
x = parseInt(frame.x.nodeValue, 10);
y = parseInt(frame.y.nodeValue, 10);
width = parseInt(frame.width.nodeValue, 10);
height = parseInt(frame.height.nodeValue, 10);
frameX = null;
frameY = null;
if (frame.frameX)
{
frameX = Math.abs(parseInt(frame.frameX.nodeValue));
frameY = Math.abs(parseInt(frame.frameY.nodeValue));
frameWidth = parseInt(frame.frameWidth.nodeValue);
frameHeight = parseInt(frame.frameHeight.nodeValue);
frameX = Math.abs(parseInt(frame.frameX.nodeValue, 10));
frameY = Math.abs(parseInt(frame.frameY.nodeValue, 10));
frameWidth = parseInt(frame.frameWidth.nodeValue, 10);
frameHeight = parseInt(frame.frameHeight.nodeValue, 10);
}
newFrame = data.addFrame(new Phaser.Frame(i, x, y, width, height, name, uuid));

View file

@ -19,124 +19,124 @@
*/
Phaser.Frame = function (index, x, y, width, height, name, uuid) {
/**
* @property {number} index - The index of this Frame within the FrameData set it is being added to.
*/
this.index = index;
/**
* @property {number} x - X position within the image to cut from.
*/
this.x = x;
/**
* @property {number} index - The index of this Frame within the FrameData set it is being added to.
*/
this.index = index;
/**
* @property {number} x - X position within the image to cut from.
*/
this.x = x;
/**
* @property {number} y - Y position within the image to cut from.
*/
this.y = y;
/**
* @property {number} y - Y position within the image to cut from.
*/
this.y = y;
/**
* @property {number} width - Width of the frame.
*/
this.width = width;
/**
* @property {number} width - Width of the frame.
*/
this.width = width;
/**
* @property {number} height - Height of the frame.
*/
this.height = height;
/**
* @property {number} height - Height of the frame.
*/
this.height = height;
/**
* @property {string} name - Useful for Texture Atlas files (is set to the filename value).
*/
this.name = name;
/**
* @property {string} name - Useful for Texture Atlas files (is set to the filename value).
*/
this.name = name;
/**
* @property {string} uuid - A link to the PIXI.TextureCache entry.
*/
this.uuid = uuid;
/**
* @property {string} uuid - A link to the PIXI.TextureCache entry.
*/
this.uuid = uuid;
/**
* @property {number} centerX - Center X position within the image to cut from.
*/
/**
* @property {number} centerX - Center X position within the image to cut from.
*/
this.centerX = Math.floor(width / 2);
/**
* @property {number} centerY - Center Y position within the image to cut from.
*/
/**
* @property {number} centerY - Center Y position within the image to cut from.
*/
this.centerY = Math.floor(height / 2);
/**
* @property {number} distance - The distance from the top left to the bottom-right of this Frame.
*/
this.distance = Phaser.Math.distance(0, 0, width, height);
/**
* @property {number} distance - The distance from the top left to the bottom-right of this Frame.
*/
this.distance = Phaser.Math.distance(0, 0, width, height);
/**
* @property {boolean} rotated - Rotated? (not yet implemented)
* @default
*/
this.rotated = false;
/**
* @property {boolean} rotated - Rotated? (not yet implemented)
* @default
*/
this.rotated = false;
/**
* @property {string} rotationDirection - Either 'cw' or 'ccw', rotation is always 90 degrees.
* @default 'cw'
*/
this.rotationDirection = 'cw';
/**
* @property {string} rotationDirection - Either 'cw' or 'ccw', rotation is always 90 degrees.
* @default 'cw'
*/
this.rotationDirection = 'cw';
/**
* @property {boolean} trimmed - Was it trimmed when packed?
* @default
*/
this.trimmed = false;
/**
* @property {boolean} trimmed - Was it trimmed when packed?
* @default
*/
this.trimmed = false;
/**
* @property {number} sourceSizeW - Width of the original sprite.
*/
/**
* @property {number} sourceSizeW - Width of the original sprite.
*/
this.sourceSizeW = width;
/**
* @property {number} sourceSizeH - Height of the original sprite.
*/
/**
* @property {number} sourceSizeH - Height of the original sprite.
*/
this.sourceSizeH = height;
/**
* @property {number} spriteSourceSizeX - X position of the trimmed sprite inside original sprite.
* @default
*/
this.spriteSourceSizeX = 0;
/**
* @property {number} spriteSourceSizeX - X position of the trimmed sprite inside original sprite.
* @default
*/
this.spriteSourceSizeX = 0;
/**
* @property {number} spriteSourceSizeY - Y position of the trimmed sprite inside original sprite.
* @default
*/
this.spriteSourceSizeY = 0;
/**
* @property {number} spriteSourceSizeY - Y position of the trimmed sprite inside original sprite.
* @default
*/
this.spriteSourceSizeY = 0;
/**
* @property {number} spriteSourceSizeW - Width of the trimmed sprite.
* @default
*/
this.spriteSourceSizeW = 0;
/**
* @property {number} spriteSourceSizeW - Width of the trimmed sprite.
* @default
*/
this.spriteSourceSizeW = 0;
/**
* @property {number} spriteSourceSizeH - Height of the trimmed sprite.
* @default
*/
this.spriteSourceSizeH = 0;
/**
* @property {number} spriteSourceSizeH - Height of the trimmed sprite.
* @default
*/
this.spriteSourceSizeH = 0;
};
Phaser.Frame.prototype = {
/**
* If the frame was trimmed when added to the Texture Atlas this records the trim and source data.
*
* @method Phaser.Frame#setTrim
* @param {boolean} trimmed - If this frame was trimmed or not.
* @param {number} actualWidth - The width of the frame before being trimmed.
* @param {number} actualHeight - The height of the frame before being trimmed.
* @param {number} destX - The destination X position of the trimmed frame for display.
* @param {number} destY - The destination Y position of the trimmed frame for display.
* @param {number} destWidth - The destination width of the trimmed frame for display.
* @param {number} destHeight - The destination height of the trimmed frame for display.
*/
/**
* If the frame was trimmed when added to the Texture Atlas this records the trim and source data.
*
* @method Phaser.Frame#setTrim
* @param {boolean} trimmed - If this frame was trimmed or not.
* @param {number} actualWidth - The width of the frame before being trimmed.
* @param {number} actualHeight - The height of the frame before being trimmed.
* @param {number} destX - The destination X position of the trimmed frame for display.
* @param {number} destY - The destination Y position of the trimmed frame for display.
* @param {number} destWidth - The destination width of the trimmed frame for display.
* @param {number} destHeight - The destination height of the trimmed frame for display.
*/
setTrim: function (trimmed, actualWidth, actualHeight, destX, destY, destWidth, destHeight) {
this.trimmed = trimmed;
@ -147,8 +147,8 @@ Phaser.Frame.prototype = {
this.height = actualHeight;
this.sourceSizeW = actualWidth;
this.sourceSizeH = actualHeight;
this.centerX = Math.floor(actualWidth / 2);
this.centerY = Math.floor(actualHeight / 2);
this.centerX = Math.floor(actualWidth / 2);
this.centerY = Math.floor(actualHeight / 2);
this.spriteSourceSizeX = destX;
this.spriteSourceSizeY = destY;
this.spriteSourceSizeW = destWidth;

View file

@ -12,17 +12,17 @@
*/
Phaser.FrameData = function () {
/**
* @property {Array} _frames - Local array of frames.
* @private
*/
/**
* @property {Array} _frames - Local array of frames.
* @private
*/
this._frames = [];
/**
* @property {Array} _frameNames - Local array of frame names for name to index conversions.
* @private
*/
/**
* @property {Array} _frameNames - Local array of frame names for name to index conversions.
* @private
*/
this._frameNames = [];
};
@ -51,13 +51,13 @@ Phaser.FrameData.prototype = {
},
/**
* Get a Frame by its numerical index.
/**
* Get a Frame by its numerical index.
*
* @method Phaser.FrameData#getFrame
* @param {number} index - The index of the frame you want to get.
* @return {Phaser.Frame} The frame, if found.
*/
* @param {number} index - The index of the frame you want to get.
* @return {Phaser.Frame} The frame, if found.
*/
getFrame: function (index) {
if (this._frames.length > index)
@ -105,15 +105,15 @@ Phaser.FrameData.prototype = {
},
/**
* Returns a range of frames based on the given start and end frame indexes and returns them in an Array.
/**
* Returns a range of frames based on the given start and end frame indexes and returns them in an Array.
*
* @method Phaser.FrameData#getFrameRange
* @param {number} start - The starting frame index.
* @param {number} end - The ending frame index.
* @param {Array} [output] - If given the results will be appended to the end of this array otherwise a new array will be created.
* @return {Array} An array of Frames between the start and end index values, or an empty array if none were found.
*/
* @param {number} end - The ending frame index.
* @param {Array} [output] - If given the results will be appended to the end of this array otherwise a new array will be created.
* @return {Array} An array of Frames between the start and end index values, or an empty array if none were found.
*/
getFrameRange: function (start, end, output) {
if (typeof output === "undefined") { output = []; }
@ -127,8 +127,8 @@ Phaser.FrameData.prototype = {
},
/**
* Returns all of the Frames in this FrameData set where the frame index is found in the input array.
/**
* Returns all of the Frames in this FrameData set where the frame index is found in the input array.
* The frames are returned in the output array, or if none is provided in a new Array object.
*
* @method Phaser.FrameData#getFrames
@ -136,13 +136,13 @@ Phaser.FrameData.prototype = {
* @param {boolean} [useNumericIndex=true] - Are the given frames using numeric indexes (default) or strings? (false)
* @param {Array} [output] - If given the results will be appended to the end of this array otherwise a new array will be created.
* @return {Array} An array of all Frames in this FrameData set matching the given names or IDs.
*/
*/
getFrames: function (frames, useNumericIndex, output) {
if (typeof useNumericIndex === "undefined") { useNumericIndex = true; }
if (typeof output === "undefined") { output = []; }
if (typeof frames === "undefined" || frames.length == 0)
if (typeof frames === "undefined" || frames.length === 0)
{
// No input array, so we loop through all frames
for (var i = 0; i < this._frames.length; i++)
@ -189,7 +189,7 @@ Phaser.FrameData.prototype = {
if (typeof useNumericIndex === "undefined") { useNumericIndex = true; }
if (typeof output === "undefined") { output = []; }
if (typeof frames === "undefined" || frames.length == 0)
if (typeof frames === "undefined" || frames.length === 0)
{
// No frames array, so we loop through all frames
for (var i = 0, len = this._frames.length; i < len; i++)

View file

@ -19,35 +19,35 @@
*/
Phaser.Camera = function (game, id, x, y, width, height) {
/**
* @property {Phaser.Game} game - A reference to the currently running Game.
*/
this.game = game;
/**
* @property {Phaser.Game} game - A reference to the currently running Game.
*/
this.game = game;
/**
* @property {Phaser.World} world - A reference to the game world.
*/
this.world = game.world;
/**
* @property {Phaser.World} world - A reference to the game world.
*/
this.world = game.world;
/**
* @property {number} id - Reserved for future multiple camera set-ups.
* @default
*/
this.id = 0;
/**
* @property {number} id - Reserved for future multiple camera set-ups.
* @default
*/
this.id = 0;
/**
* Camera view.
* The view into the world we wish to render (by default the game dimensions).
/**
* Camera view.
* The view into the world we wish to render (by default the game dimensions).
* The x/y values are in world coordinates, not screen coordinates, the width/height is how many pixels to render.
* Objects outside of this view are not rendered (unless set to ignore the Camera, i.e. UI?).
* @property {Phaser.Rectangle} view
*/
* @property {Phaser.Rectangle} view
*/
this.view = new Phaser.Rectangle(x, y, width, height);
/**
* @property {Phaser.Rectangle} screenView - Used by Sprites to work out Camera culling.
*/
this.screenView = new Phaser.Rectangle(x, y, width, height);
* @property {Phaser.Rectangle} screenView - Used by Sprites to work out Camera culling.
*/
this.screenView = new Phaser.Rectangle(x, y, width, height);
/**
* The Camera is bound to this Rectangle and cannot move outside of it. By default it is enabled and set to the size of the World.
@ -58,36 +58,36 @@ Phaser.Camera = function (game, id, x, y, width, height) {
this.bounds = new Phaser.Rectangle(x, y, width, height);
/**
* @property {Phaser.Rectangle} deadzone - Moving inside this Rectangle will not cause camera moving.
*/
* @property {Phaser.Rectangle} deadzone - Moving inside this Rectangle will not cause camera moving.
*/
this.deadzone = null;
/**
* @property {boolean} visible - Whether this camera is visible or not.
* @default
*/
/**
* @property {boolean} visible - Whether this camera is visible or not.
* @default
*/
this.visible = true;
/**
* @property {boolean} atLimit - Whether this camera is flush with the World Bounds or not.
/**
* @property {boolean} atLimit - Whether this camera is flush with the World Bounds or not.
*/
this.atLimit = { x: false, y: false };
/**
* @property {Phaser.Sprite} target - If the camera is tracking a Sprite, this is a reference to it, otherwise null.
/**
* @property {Phaser.Sprite} target - If the camera is tracking a Sprite, this is a reference to it, otherwise null.
* @default
*/
this.target = null;
/**
* @property {number} edge - Edge property.
/**
* @property {number} edge - Edge property.
* @private
* @default
*/
this._edge = 0;
this.displayObject = null;
};
/**
@ -116,7 +116,7 @@ Phaser.Camera.FOLLOW_TOPDOWN_TIGHT = 3;
Phaser.Camera.prototype = {
/**
/**
* Tells this camera which sprite to follow.
* @method Phaser.Camera#follow
* @param {Phaser.Sprite} target - The object you want the camera to track. Set to null to not follow anything.
@ -149,6 +149,9 @@ Phaser.Camera.prototype = {
break;
case Phaser.Camera.FOLLOW_LOCKON:
this.deadzone = null;
break;
default:
this.deadzone = null;
break;
@ -167,7 +170,7 @@ Phaser.Camera.prototype = {
},
/**
/**
* Move the camera focus on a location instantly.
* @method Phaser.Camera#focusOnXY
* @param {number} x - X position.
@ -179,7 +182,7 @@ Phaser.Camera.prototype = {
},
/**
/**
* Update focusing and scrolling.
* @method Phaser.Camera#update
*/
@ -348,7 +351,7 @@ Object.defineProperty(Phaser.Camera.prototype, "x", {
* @property {number} y - Gets or sets the cameras y position.
*/
Object.defineProperty(Phaser.Camera.prototype, "y", {
get: function () {
return this.view.y;
},

View file

@ -16,9 +16,9 @@
*/
Phaser.Filter = function (game, uniforms, fragmentSrc) {
/**
* @property {Phaser.Game} game - A reference to the currently running game.
*/
/**
* @property {Phaser.Game} game - A reference to the currently running game.
*/
this.game = game;
/**
@ -86,7 +86,7 @@ Phaser.Filter.prototype = {
this.uniforms.mouse.y = pointer.y;
}
this.uniforms.time.value = this.game.time.totalElapsedSeconds();
this.uniforms.time.value = this.game.time.totalElapsedSeconds();
},

View file

@ -24,380 +24,380 @@
*/
Phaser.Game = function (width, height, renderer, parent, state, transparent, antialias) {
width = width || 800;
height = height || 600;
renderer = renderer || Phaser.AUTO;
parent = parent || '';
state = state || null;
width = width || 800;
height = height || 600;
renderer = renderer || Phaser.AUTO;
parent = parent || '';
state = state || null;
if (typeof transparent == 'undefined') { transparent = false; }
if (typeof antialias == 'undefined') { antialias = true; }
if (typeof transparent == 'undefined') { transparent = false; }
if (typeof antialias == 'undefined') { antialias = true; }
/**
* @property {number} id - Phaser Game ID (for when Pixi supports multiple instances).
*/
this.id = Phaser.GAMES.push(this) - 1;
/**
* @property {number} id - Phaser Game ID (for when Pixi supports multiple instances).
*/
this.id = Phaser.GAMES.push(this) - 1;
/**
* @property {HTMLElement} parent - The Games DOM parent.
*/
this.parent = parent;
/**
* @property {HTMLElement} parent - The Games DOM parent.
*/
this.parent = parent;
// Do some more intelligent size parsing here, so they can set "100%" for example, maybe pass the scale mode in here too?
// Do some more intelligent size parsing here, so they can set "100%" for example, maybe pass the scale mode in here too?
/**
* @property {number} width - The Game width (in pixels).
*/
this.width = width;
/**
* @property {number} width - The Game width (in pixels).
*/
this.width = width;
/**
* @property {number} height - The Game height (in pixels).
*/
this.height = height;
/**
* @property {number} height - The Game height (in pixels).
*/
this.height = height;
/**
* @property {boolean} transparent - Use a transparent canvas background or not.
*/
this.transparent = transparent;
/**
* @property {boolean} transparent - Use a transparent canvas background or not.
*/
this.transparent = transparent;
/**
* @property {boolean} antialias - Anti-alias graphics (in WebGL this helps with edges, in Canvas2D it retains pixel-art quality).
*/
this.antialias = antialias;
/**
* @property {boolean} antialias - Anti-alias graphics (in WebGL this helps with edges, in Canvas2D it retains pixel-art quality).
*/
this.antialias = antialias;
/**
* @property {number} renderer - The Pixi Renderer
* @default
*/
this.renderer = null;
/**
* @property {number} renderer - The Pixi Renderer
* @default
*/
this.renderer = null;
/**
* @property {number} state - The StateManager.
*/
this.state = new Phaser.StateManager(this, state);
/**
* @property {number} state - The StateManager.
*/
this.state = new Phaser.StateManager(this, state);
/**
* @property {boolean} _paused - Is game paused?
* @private
* @default
*/
this._paused = false;
/**
* @property {boolean} _paused - Is game paused?
* @private
* @default
*/
this._paused = false;
/**
* @property {number} renderType - The Renderer this Phaser.Game will use. Either Phaser.RENDERER_AUTO, Phaser.RENDERER_CANVAS or Phaser.RENDERER_WEBGL.
*/
this.renderType = renderer;
/**
* @property {number} renderType - The Renderer this Phaser.Game will use. Either Phaser.RENDERER_AUTO, Phaser.RENDERER_CANVAS or Phaser.RENDERER_WEBGL.
*/
this.renderType = renderer;
/**
* @property {boolean} _loadComplete - Whether load complete loading or not.
* @private
* @default
*/
this._loadComplete = false;
/**
* @property {boolean} _loadComplete - Whether load complete loading or not.
* @private
* @default
*/
this._loadComplete = false;
/**
* @property {boolean} isBooted - Whether the game engine is booted, aka available.
* @default
*/
this.isBooted = false;
/**
* @property {boolean} isBooted - Whether the game engine is booted, aka available.
* @default
*/
this.isBooted = false;
/**
* @property {boolean} id -Is game running or paused?
* @default
*/
this.isRunning = false;
/**
* @property {boolean} id -Is game running or paused?
* @default
*/
this.isRunning = false;
/**
* @property {Phaser.RequestAnimationFrame} raf - Automatically handles the core game loop via requestAnimationFrame or setTimeout
* @default
*/
this.raf = null;
/**
* @property {Phaser.RequestAnimationFrame} raf - Automatically handles the core game loop via requestAnimationFrame or setTimeout
* @default
*/
this.raf = null;
/**
* @property {Phaser.GameObjectFactory} add - Reference to the GameObject Factory.
* @default
*/
/**
* @property {Phaser.GameObjectFactory} add - Reference to the GameObject Factory.
* @default
*/
this.add = null;
/**
* @property {Phaser.Cache} cache - Reference to the assets cache.
* @default
*/
* @property {Phaser.Cache} cache - Reference to the assets cache.
* @default
*/
this.cache = null;
/**
* @property {Phaser.Input} input - Reference to the input manager
* @default
*/
* @property {Phaser.Input} input - Reference to the input manager
* @default
*/
this.input = null;
/**
* @property {Phaser.Loader} load - Reference to the assets loader.
* @default
*/
* @property {Phaser.Loader} load - Reference to the assets loader.
* @default
*/
this.load = null;
/**
* @property {Phaser.Math} math - Reference to the math helper.
* @default
*/
* @property {Phaser.Math} math - Reference to the math helper.
* @default
*/
this.math = null;
/**
* @property {Phaser.Net} net - Reference to the network class.
* @default
*/
* @property {Phaser.Net} net - Reference to the network class.
* @default
*/
this.net = null;
/**
* @property {Phaser.SoundManager} sound - Reference to the sound manager.
* @default
*/
* @property {Phaser.SoundManager} sound - Reference to the sound manager.
* @default
*/
this.sound = null;
/**
* @property {Phaser.Stage} stage - Reference to the stage.
* @default
*/
* @property {Phaser.Stage} stage - Reference to the stage.
* @default
*/
this.stage = null;
/**
* @property {Phaser.TimeManager} time - Reference to game clock.
* @default
*/
* @property {Phaser.TimeManager} time - Reference to game clock.
* @default
*/
this.time = null;
/**
* @property {Phaser.TweenManager} tweens - Reference to the tween manager.
* @default
*/
* @property {Phaser.TweenManager} tweens - Reference to the tween manager.
* @default
*/
this.tweens = null;
/**
* @property {Phaser.World} world - Reference to the world.
* @default
*/
* @property {Phaser.World} world - Reference to the world.
* @default
*/
this.world = null;
/**
* @property {Phaser.Physics.PhysicsManager} physics - Reference to the physics manager.
* @default
*/
* @property {Phaser.Physics.PhysicsManager} physics - Reference to the physics manager.
* @default
*/
this.physics = null;
/**
* @property {Phaser.RandomDataGenerator} rnd - Instance of repeatable random data generator helper.
* @default
*/
* @property {Phaser.RandomDataGenerator} rnd - Instance of repeatable random data generator helper.
* @default
*/
this.rnd = null;
/**
* @property {Phaser.Device} device - Contains device information and capabilities.
* @default
*/
* @property {Phaser.Device} device - Contains device information and capabilities.
* @default
*/
this.device = null;
/**
* @property {Phaser.Physics.PhysicsManager} camera - A handy reference to world.camera.
* @default
*/
this.camera = null;
* @property {Phaser.Physics.PhysicsManager} camera - A handy reference to world.camera.
* @default
*/
this.camera = null;
/**
* @property {HTMLCanvasElement} canvas - A handy reference to renderer.view.
* @default
*/
this.canvas = null;
/**
* @property {Context} context - A handy reference to renderer.context (only set for CANVAS games)
* @default
*/
this.context = null;
/**
* @property {HTMLCanvasElement} canvas - A handy reference to renderer.view.
* @default
*/
this.canvas = null;
/**
* @property {Phaser.Utils.Debug} debug - A set of useful debug utilitie.
* @default
*/
this.debug = null;
* @property {Context} context - A handy reference to renderer.context (only set for CANVAS games)
* @default
*/
this.context = null;
/**
* @property {Phaser.Particles} particles - The Particle Manager.
* @default
*/
this.particles = null;
/**
* @property {Phaser.Utils.Debug} debug - A set of useful debug utilitie.
* @default
*/
this.debug = null;
var _this = this;
/**
* @property {Phaser.Particles} particles - The Particle Manager.
* @default
*/
this.particles = null;
var _this = this;
this._onBoot = function () {
return _this.boot();
}
if (document.readyState === 'complete' || document.readyState === 'interactive')
{
window.setTimeout(this._onBoot, 0);
}
else
{
document.addEventListener('DOMContentLoaded', this._onBoot, false);
window.addEventListener('load', this._onBoot, false);
}
if (document.readyState === 'complete' || document.readyState === 'interactive')
{
window.setTimeout(this._onBoot, 0);
}
else
{
document.addEventListener('DOMContentLoaded', this._onBoot, false);
window.addEventListener('load', this._onBoot, false);
}
return this;
return this;
};
Phaser.Game.prototype = {
/**
* Initialize engine sub modules and start the game.
*
* @method Phaser.Game#boot
* @protected
*/
boot: function () {
/**
* Initialize engine sub modules and start the game.
*
* @method Phaser.Game#boot
* @protected
*/
boot: function () {
if (this.isBooted)
{
return;
}
if (this.isBooted)
{
return;
}
if (!document.body)
{
window.setTimeout(this._onBoot, 20);
}
else
{
document.removeEventListener('DOMContentLoaded', this._onBoot);
window.removeEventListener('load', this._onBoot);
if (!document.body)
{
window.setTimeout(this._onBoot, 20);
}
else
{
document.removeEventListener('DOMContentLoaded', this._onBoot);
window.removeEventListener('load', this._onBoot);
this.onPause = new Phaser.Signal;
this.onResume = new Phaser.Signal;
this.onPause = new Phaser.Signal();
this.onResume = new Phaser.Signal();
this.isBooted = true;
this.isBooted = true;
this.device = new Phaser.Device();
this.math = Phaser.Math;
this.rnd = new Phaser.RandomDataGenerator([(Date.now() * Math.random()).toString()]);
this.device = new Phaser.Device();
this.math = Phaser.Math;
this.rnd = new Phaser.RandomDataGenerator([(Date.now() * Math.random()).toString()]);
this.stage = new Phaser.Stage(this, this.width, this.height);
this.stage = new Phaser.Stage(this, this.width, this.height);
this.setUpRenderer();
this.setUpRenderer();
this.world = new Phaser.World(this);
this.add = new Phaser.GameObjectFactory(this);
this.cache = new Phaser.Cache(this);
this.load = new Phaser.Loader(this);
this.time = new Phaser.Time(this);
this.tweens = new Phaser.TweenManager(this);
this.input = new Phaser.Input(this);
this.sound = new Phaser.SoundManager(this);
this.physics = new Phaser.Physics.Arcade(this);
this.particles = new Phaser.Particles(this);
this.plugins = new Phaser.PluginManager(this, this);
this.net = new Phaser.Net(this);
this.debug = new Phaser.Utils.Debug(this);
this.world = new Phaser.World(this);
this.add = new Phaser.GameObjectFactory(this);
this.cache = new Phaser.Cache(this);
this.load = new Phaser.Loader(this);
this.time = new Phaser.Time(this);
this.tweens = new Phaser.TweenManager(this);
this.input = new Phaser.Input(this);
this.sound = new Phaser.SoundManager(this);
this.physics = new Phaser.Physics.Arcade(this);
this.particles = new Phaser.Particles(this);
this.plugins = new Phaser.PluginManager(this, this);
this.net = new Phaser.Net(this);
this.debug = new Phaser.Utils.Debug(this);
this.stage.boot();
this.world.boot();
this.input.boot();
this.sound.boot();
this.state.boot();
this.stage.boot();
this.world.boot();
this.input.boot();
this.sound.boot();
this.state.boot();
this.load.onLoadComplete.add(this.loadComplete, this);
this.load.onLoadComplete.add(this.loadComplete, this);
this.showDebugHeader();
this.showDebugHeader();
this.isRunning = true;
this.isRunning = true;
this._loadComplete = false;
this.raf = new Phaser.RequestAnimationFrame(this);
this.raf.start();
this.raf = new Phaser.RequestAnimationFrame(this);
this.raf.start();
}
}
},
},
/**
/**
* Displays a Phaser version debug header in the console.
*
* @method Phaser.Game#showDebugHeader
* @protected
*/
showDebugHeader: function () {
showDebugHeader: function () {
var v = Phaser.DEV_VERSION;
var r = 'Canvas';
var a = 'HTML Audio';
var v = Phaser.DEV_VERSION;
var r = 'Canvas';
var a = 'HTML Audio';
if (this.renderType == Phaser.WEBGL)
{
r = 'WebGL';
}
if (this.renderType == Phaser.WEBGL)
{
r = 'WebGL';
}
if (this.device.webAudio)
{
a = 'WebAudio';
}
if (this.device.webAudio)
{
a = 'WebAudio';
}
if (this.device.chrome)
{
var args = [
'%c %c %c Phaser v' + v + ' - Renderer: ' + r + ' - Audio: ' + a + ' %c %c ',
'background: #00bff3',
'background: #0072bc',
'color: #ffffff; background: #003471',
'background: #0072bc',
'background: #00bff3'
];
if (this.device.chrome)
{
var args = [
'%c %c %c Phaser v' + v + ' - Renderer: ' + r + ' - Audio: ' + a + ' %c %c ',
'background: #00bff3',
'background: #0072bc',
'color: #ffffff; background: #003471',
'background: #0072bc',
'background: #00bff3'
];
console.log.apply(console, args);
}
else
{
console.log('Phaser v' + v + ' - Renderer: ' + r + ' - Audio: ' + a);
}
console.log.apply(console, args);
}
else
{
console.log('Phaser v' + v + ' - Renderer: ' + r + ' - Audio: ' + a);
}
},
},
/**
* Checks if the device is capable of using the requested renderer and sets it up or an alternative if not.
*
* @method Phaser.Game#setUpRenderer
* @protected
*/
setUpRenderer: function () {
/**
* Checks if the device is capable of using the requested renderer and sets it up or an alternative if not.
*
* @method Phaser.Game#setUpRenderer
* @protected
*/
setUpRenderer: function () {
if (this.renderType === Phaser.CANVAS || (this.renderType === Phaser.AUTO && this.device.webGL == false))
{
if (this.device.canvas)
{
this.renderType = Phaser.CANVAS;
this.renderer = new PIXI.CanvasRenderer(this.width, this.height, this.stage.canvas, this.transparent);
Phaser.Canvas.setSmoothingEnabled(this.renderer.context, this.antialias);
this.canvas = this.renderer.view;
this.context = this.renderer.context;
}
else
{
throw new Error('Phaser.Game - cannot create Canvas or WebGL context, aborting.');
}
}
else
{
// They requested WebGL, and their browser supports it
this.renderType = Phaser.WEBGL;
this.renderer = new PIXI.WebGLRenderer(this.width, this.height, this.stage.canvas, this.transparent, this.antialias);
this.canvas = this.renderer.view;
this.context = null;
}
if (this.renderType === Phaser.CANVAS || (this.renderType === Phaser.AUTO && this.device.webGL === false))
{
if (this.device.canvas)
{
this.renderType = Phaser.CANVAS;
this.renderer = new PIXI.CanvasRenderer(this.width, this.height, this.stage.canvas, this.transparent);
Phaser.Canvas.setSmoothingEnabled(this.renderer.context, this.antialias);
this.canvas = this.renderer.view;
this.context = this.renderer.context;
}
else
{
throw new Error('Phaser.Game - cannot create Canvas or WebGL context, aborting.');
}
}
else
{
// They requested WebGL, and their browser supports it
this.renderType = Phaser.WEBGL;
this.renderer = new PIXI.WebGLRenderer(this.width, this.height, this.stage.canvas, this.transparent, this.antialias);
this.canvas = this.renderer.view;
this.context = null;
}
Phaser.Canvas.addToDOM(this.renderer.view, this.parent, true);
Phaser.Canvas.setTouchAction(this.renderer.view);
},
},
/**
/**
* Called when the load has finished, after preload was run.
*
* @method Phaser.Game#loadComplete
@ -411,61 +411,61 @@ Phaser.Game.prototype = {
},
/**
/**
* The core game loop.
*
* @method Phaser.Game#update
* @protected
* @param {number} time - The current time as provided by RequestAnimationFrame.
* @param {number} time - The current time as provided by RequestAnimationFrame.
*/
update: function (time) {
update: function (time) {
this.time.update(time);
this.time.update(time);
if (this._paused)
{
this.renderer.render(this.stage._stage);
this.plugins.render();
this.state.render();
}
else
{
this.plugins.preUpdate();
this.physics.preUpdate();
if (this._paused)
{
this.renderer.render(this.stage._stage);
this.plugins.render();
this.state.render();
}
else
{
this.plugins.preUpdate();
this.physics.preUpdate();
this.stage.update();
this.input.update();
this.tweens.update();
this.sound.update();
this.world.update();
this.particles.update();
this.state.update();
this.plugins.update();
this.stage.update();
this.input.update();
this.tweens.update();
this.sound.update();
this.world.update();
this.particles.update();
this.state.update();
this.plugins.update();
this.world.postUpdate();
this.world.postUpdate();
this.plugins.postUpdate();
this.renderer.render(this.stage._stage);
this.plugins.render();
this.state.render();
this.renderer.render(this.stage._stage);
this.plugins.render();
this.state.render();
this.plugins.postRender();
}
this.plugins.postRender();
}
},
},
/**
/**
* Nuke the entire game from orbit
*
* @method Phaser.Game#destroy
*/
destroy: function () {
this.raf.stop();
this.raf.stop();
this.input.destroy();
this.input.destroy();
this.state.destroy();
this.state.destroy();
this.state = null;
this.cache = null;
@ -495,22 +495,22 @@ Object.defineProperty(Phaser.Game.prototype, "paused", {
set: function (value) {
if (value === true)
{
if (this._paused == false)
{
this._paused = true;
this.onPause.dispatch(this);
}
}
else
{
if (this._paused)
{
this._paused = false;
this.onResume.dispatch(this);
}
}
if (value === true)
{
if (this._paused === false)
{
this._paused = true;
this.onPause.dispatch(this);
}
}
else
{
if (this._paused)
{
this._paused = false;
this.onResume.dispatch(this);
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -13,141 +13,141 @@
Phaser.LinkedList = function () {
/**
* @property {object} next - Next element in the list.
* @default
*/
* @property {object} next - Next element in the list.
* @default
*/
this.next = null;
/**
* @property {object} prev - Previous element in the list.
* @default
*/
* @property {object} prev - Previous element in the list.
* @default
*/
this.prev = null;
/**
* @property {object} first - First element in the list.
* @default
*/
* @property {object} first - First element in the list.
* @default
*/
this.first = null;
/**
* @property {object} last - Last element in the list.
* @default
*/
* @property {object} last - Last element in the list.
* @default
*/
this.last = null;
/**
* @property {object} game - Number of elements in the list.
* @default
*/
* @property {object} game - Number of elements in the list.
* @default
*/
this.total = 0;
};
Phaser.LinkedList.prototype = {
/**
/**
* Adds a new element to this linked list.
*
* @method Phaser.LinkedList#add
* @param {object} child - The element to add to this list. Can be a Phaser.Sprite or any other object you need to quickly iterate through.
* @return {object} The child that was added.
*
* @method Phaser.LinkedList#add
* @param {object} child - The element to add to this list. Can be a Phaser.Sprite or any other object you need to quickly iterate through.
* @return {object} The child that was added.
*/
add: function (child) {
// If the list is empty
if (this.total == 0 && this.first == null && this.last == null)
{
this.first = child;
this.last = child;
this.next = child;
child.prev = this;
this.total++;
return child;
}
// If the list is empty
if (this.total === 0 && this.first == null && this.last == null)
{
this.first = child;
this.last = child;
this.next = child;
child.prev = this;
this.total++;
return child;
}
// Get gets appended to the end of the list, regardless of anything, and it won't have any children of its own (non-nested list)
this.last.next = child;
// Get gets appended to the end of the list, regardless of anything, and it won't have any children of its own (non-nested list)
this.last.next = child;
child.prev = this.last;
child.prev = this.last;
this.last = child;
this.last = child;
this.total++;
this.total++;
return child;
return child;
},
/**
/**
* Removes the given element from this linked list if it exists.
*
* @method Phaser.LinkedList#remove
* @param {object} child - The child to be removed from the list.
*
* @method Phaser.LinkedList#remove
* @param {object} child - The child to be removed from the list.
*/
remove: function (child) {
if (child == this.first)
{
// It was 'first', make 'first' point to first.next
this.first = this.first.next;
}
else if (child == this.last)
{
// It was 'last', make 'last' point to last.prev
this.last = this.last.prev;
}
if (child == this.first)
{
// It was 'first', make 'first' point to first.next
this.first = this.first.next;
}
else if (child == this.last)
{
// It was 'last', make 'last' point to last.prev
this.last = this.last.prev;
}
if (child.prev)
{
// make child.prev.next point to childs.next instead of child
child.prev.next = child.next;
}
if (child.prev)
{
// make child.prev.next point to childs.next instead of child
child.prev.next = child.next;
}
if (child.next)
{
// make child.next.prev point to child.prev instead of child
child.next.prev = child.prev;
}
if (child.next)
{
// make child.next.prev point to child.prev instead of child
child.next.prev = child.prev;
}
child.next = child.prev = null;
child.next = child.prev = null;
if (this.first == null )
{
this.last = null;
}
if (this.first == null )
{
this.last = null;
}
this.total--;
this.total--;
},
/**
/**
* Calls a function on all members of this list, using the member as the context for the callback.
* The function must exist on the member.
*
* @method Phaser.LinkedList#callAll
* @param {function} callback - The function to call.
*
* @method Phaser.LinkedList#callAll
* @param {function} callback - The function to call.
*/
callAll: function (callback) {
if (!this.first || !this.last)
{
return;
}
if (!this.first || !this.last)
{
return;
}
var entity = this.first;
do
{
if (entity && entity[callback])
{
entity[callback].call(entity);
}
var entity = this.first;
do
{
if (entity && entity[callback])
{
entity[callback].call(entity);
}
entity = entity.next;
entity = entity.next;
}
while(entity != this.last.next)
}
while(entity != this.last.next)
}

View file

@ -17,38 +17,38 @@ Phaser.Plugin = function (game, parent) {
if (typeof parent === 'undefined') { parent = null; }
/**
* @property {Phaser.Game} game - A reference to the currently running game.
*/
/**
* @property {Phaser.Game} game - A reference to the currently running game.
*/
this.game = game;
/**
* @property {Any} parent - The parent of this plugin. If added to the PluginManager the parent will be set to that, otherwise it will be null.
*/
* @property {Any} parent - The parent of this plugin. If added to the PluginManager the parent will be set to that, otherwise it will be null.
*/
this.parent = parent;
/**
* @property {boolean} active - A Plugin with active=true has its preUpdate and update methods called by the parent, otherwise they are skipped.
* @default
*/
* @property {boolean} active - A Plugin with active=true has its preUpdate and update methods called by the parent, otherwise they are skipped.
* @default
*/
this.active = false;
/**
* @property {boolean} visible - A Plugin with visible=true has its render and postRender methods called by the parent, otherwise they are skipped.
* @default
*/
* @property {boolean} visible - A Plugin with visible=true has its render and postRender methods called by the parent, otherwise they are skipped.
* @default
*/
this.visible = false;
/**
* @property {boolean} hasPreUpdate - A flag to indicate if this plugin has a preUpdate method.
* @default
*/
* @property {boolean} hasPreUpdate - A flag to indicate if this plugin has a preUpdate method.
* @default
*/
this.hasPreUpdate = false;
/**
* @property {boolean} hasUpdate - A flag to indicate if this plugin has an update method.
* @default
*/
* @property {boolean} hasUpdate - A flag to indicate if this plugin has an update method.
* @default
*/
this.hasUpdate = false;
/**
@ -58,15 +58,15 @@ Phaser.Plugin = function (game, parent) {
this.hasPostUpdate = false;
/**
* @property {boolean} hasRender - A flag to indicate if this plugin has a render method.
* @default
*/
* @property {boolean} hasRender - A flag to indicate if this plugin has a render method.
* @default
*/
this.hasRender = false;
/**
* @property {boolean} hasPostRender - A flag to indicate if this plugin has a postRender method.
* @default
*/
* @property {boolean} hasPostRender - A flag to indicate if this plugin has a postRender method.
* @default
*/
this.hasPostRender = false;
};

View file

@ -1,3 +1,5 @@
/* jshint newcap: false */
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2013 Photon Storm Ltd.
@ -5,7 +7,7 @@
*/
/**
* Description.
* The Plugin Manager is responsible for the loading, running and unloading of Phaser Plugins.
*
* @class Phaser.PluginManager
* @classdesc Phaser - PluginManager
@ -15,27 +17,27 @@
*/
Phaser.PluginManager = function(game, parent) {
/**
* @property {Phaser.Game} game - A reference to the currently running game.
*/
/**
* @property {Phaser.Game} game - A reference to the currently running game.
*/
this.game = game;
/**
* @property {Description} _parent - Description.
* @private
*/
* @property {Description} _parent - Description.
* @private
*/
this._parent = parent;
/**
* @property {array} plugins - Description.
*/
* @property {array} plugins - Description.
*/
this.plugins = [];
/**
* @property {array} _pluginsLength - Description.
* @private
* @default
*/
* @property {array} _pluginsLength - Description.
* @private
* @default
*/
this._pluginsLength = 0;
};
@ -131,7 +133,7 @@ Phaser.PluginManager.prototype = {
*/
remove: function (plugin) {
if (this._pluginsLength == 0)
if (this._pluginsLength === 0)
{
return;
}
@ -170,7 +172,7 @@ Phaser.PluginManager.prototype = {
*/
preUpdate: function () {
if (this._pluginsLength == 0)
if (this._pluginsLength === 0)
{
return;
}
@ -193,7 +195,7 @@ Phaser.PluginManager.prototype = {
*/
update: function () {
if (this._pluginsLength == 0)
if (this._pluginsLength === 0)
{
return;
}
@ -217,7 +219,7 @@ Phaser.PluginManager.prototype = {
*/
postUpdate: function () {
if (this._pluginsLength == 0)
if (this._pluginsLength === 0)
{
return;
}
@ -240,7 +242,7 @@ Phaser.PluginManager.prototype = {
*/
render: function () {
if (this._pluginsLength == 0)
if (this._pluginsLength === 0)
{
return;
}
@ -263,7 +265,7 @@ Phaser.PluginManager.prototype = {
*/
postRender: function () {
if (this._pluginsLength == 0)
if (this._pluginsLength === 0)
{
return;
}

View file

@ -12,286 +12,291 @@
*/
Phaser.Signal = function () {
/**
* @property {Array.<Phaser.SignalBinding>} _bindings - Description.
* @private
*/
this._bindings = [];
/**
* @property {Description} _prevParams - Description.
* @private
*/
this._prevParams = null;
/**
* @property {Array.<Phaser.SignalBinding>} _bindings - Description.
* @private
*/
this._bindings = [];
/**
* @property {Description} _prevParams - Description.
* @private
*/
this._prevParams = null;
// enforce dispatch to aways work on same context (#47)
var self = this;
// enforce dispatch to aways work on same context (#47)
var self = this;
/**
* @property {Description} dispatch - Description.
*/
this.dispatch = function(){
Phaser.Signal.prototype.dispatch.apply(self, arguments);
};
/**
* @property {Description} dispatch - Description.
*/
this.dispatch = function(){
Phaser.Signal.prototype.dispatch.apply(self, arguments);
};
};
Phaser.Signal.prototype = {
/**
/**
* If Signal should keep record of previously dispatched parameters and
* automatically execute listener during `add()`/`addOnce()` if Signal was
* already dispatched before.
* @property {boolean} memorize
*/
memorize: false,
* automatically execute listener during `add()`/`addOnce()` if Signal was
* already dispatched before.
* @property {boolean} memorize
*/
memorize: false,
/**
* @property {boolean} _shouldPropagate
* @private
*/
_shouldPropagate: true,
/**
* @property {boolean} _shouldPropagate
* @private
*/
_shouldPropagate: true,
/**
* If Signal is active and should broadcast events.
* <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
/**
* If Signal is active and should broadcast events.
* <p><strong>IMPORTANT:</strong> Setting this property during a dispatch will only affect the next dispatch, if you want to stop the propagation of a signal use `halt()` instead.</p>
* @property {boolean} active
* @default
*/
active: true,
active: true,
/**
* @method Phaser.Signal#validateListener
* @param {function} listener - Signal handler function.
* @param {Description} fnName - Description.
* @private
/**
* @method Phaser.Signal#validateListener
* @param {function} listener - Signal handler function.
* @param {Description} fnName - Description.
* @private
*/
validateListener: function (listener, fnName) {
if (typeof listener !== 'function') {
throw new Error( 'listener is a required param of {fn}() and should be a Function.'.replace('{fn}', fnName) );
}
},
validateListener: function (listener, fnName) {
if (typeof listener !== 'function') {
throw new Error( 'listener is a required param of {fn}() and should be a Function.'.replace('{fn}', fnName) );
}
},
/**
* @method Phaser.Signal#_registerListener
* @param {function} listener - Signal handler function.
* @param {boolean} isOnce - Description.
* @param {object} [listenerContext] - Description.
* @param {number} [priority] - The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0).
* @return {Phaser.SignalBinding} An Object representing the binding between the Signal and listener.
* @private
*/
_registerListener: function (listener, isOnce, listenerContext, priority) {
/**
* @method Phaser.Signal#_registerListener
* @param {function} listener - Signal handler function.
* @param {boolean} isOnce - Description.
* @param {object} [listenerContext] - Description.
* @param {number} [priority] - The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0).
* @return {Phaser.SignalBinding} An Object representing the binding between the Signal and listener.
* @private
*/
_registerListener: function (listener, isOnce, listenerContext, priority) {
var prevIndex = this._indexOfListener(listener, listenerContext),
binding;
var prevIndex = this._indexOfListener(listener, listenerContext),
binding;
if (prevIndex !== -1) {
binding = this._bindings[prevIndex];
if (binding.isOnce() !== isOnce) {
throw new Error('You cannot add'+ (isOnce? '' : 'Once') +'() then add'+ (!isOnce? '' : 'Once') +'() the same listener without removing the relationship first.');
}
} else {
binding = new Phaser.SignalBinding(this, listener, isOnce, listenerContext, priority);
this._addBinding(binding);
}
if (prevIndex !== -1) {
binding = this._bindings[prevIndex];
if (binding.isOnce() !== isOnce) {
throw new Error('You cannot add'+ (isOnce? '' : 'Once') +'() then add'+ (!isOnce? '' : 'Once') +'() the same listener without removing the relationship first.');
}
} else {
binding = new Phaser.SignalBinding(this, listener, isOnce, listenerContext, priority);
this._addBinding(binding);
}
if (this.memorize && this._prevParams){
binding.execute(this._prevParams);
}
if (this.memorize && this._prevParams){
binding.execute(this._prevParams);
}
return binding;
},
return binding;
},
/**
* @method Phaser.Signal#_addBinding
* @param {Phaser.SignalBinding} binding - An Object representing the binding between the Signal and listener.
* @private
*/
_addBinding: function (binding) {
//simplified insertion sort
var n = this._bindings.length;
do { --n; } while (this._bindings[n] && binding._priority <= this._bindings[n]._priority);
this._bindings.splice(n + 1, 0, binding);
},
/**
* @method Phaser.Signal#_addBinding
* @param {Phaser.SignalBinding} binding - An Object representing the binding between the Signal and listener.
* @private
*/
_addBinding: function (binding) {
//simplified insertion sort
var n = this._bindings.length;
do { --n; } while (this._bindings[n] && binding._priority <= this._bindings[n]._priority);
this._bindings.splice(n + 1, 0, binding);
},
/**
* @method Phaser.Signal#_indexOfListener
* @param {function} listener - Signal handler function.
* @return {number} Description.
* @private
*/
_indexOfListener: function (listener, context) {
var n = this._bindings.length,
cur;
while (n--) {
cur = this._bindings[n];
if (cur._listener === listener && cur.context === context) {
return n;
}
}
return -1;
},
/**
* @method Phaser.Signal#_indexOfListener
* @param {function} listener - Signal handler function.
* @return {number} Description.
* @private
*/
_indexOfListener: function (listener, context) {
var n = this._bindings.length,
cur;
while (n--) {
cur = this._bindings[n];
if (cur._listener === listener && cur.context === context) {
return n;
}
}
return -1;
},
/**
* Check if listener was attached to Signal.
*
* @method Phaser.Signal#has
* @param {Function} listener - Signal handler function.
* @param {Object} [context] - Context on which listener will be executed (object that should represent the `this` variable inside listener function).
* @return {boolean} If Signal has the specified listener.
*/
has: function (listener, context) {
return this._indexOfListener(listener, context) !== -1;
},
/**
* Check if listener was attached to Signal.
*
* @method Phaser.Signal#has
* @param {Function} listener - Signal handler function.
* @param {Object} [context] - Context on which listener will be executed (object that should represent the `this` variable inside listener function).
* @return {boolean} If Signal has the specified listener.
*/
has: function (listener, context) {
return this._indexOfListener(listener, context) !== -1;
},
/**
* Add a listener to the signal.
*
* @method Phaser.Signal#add
* @param {function} listener - Signal handler function.
* @param {object} [listenerContext] Context on which listener will be executed (object that should represent the `this` variable inside listener function).
* @param {number} [priority] The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0).
* @return {Phaser.SignalBinding} An Object representing the binding between the Signal and listener.
*/
add: function (listener, listenerContext, priority) {
this.validateListener(listener, 'add');
return this._registerListener(listener, false, listenerContext, priority);
},
/**
* Add a listener to the signal.
*
* @method Phaser.Signal#add
* @param {function} listener - Signal handler function.
* @param {object} [listenerContext] Context on which listener will be executed (object that should represent the `this` variable inside listener function).
* @param {number} [priority] The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0).
* @return {Phaser.SignalBinding} An Object representing the binding between the Signal and listener.
*/
add: function (listener, listenerContext, priority) {
this.validateListener(listener, 'add');
return this._registerListener(listener, false, listenerContext, priority);
},
/**
* Add listener to the signal that should be removed after first execution (will be executed only once).
*
* @method Phaser.Signal#addOnce
* @param {function} listener Signal handler function.
* @param {object} [listenerContext] Context on which listener will be executed (object that should represent the `this` variable inside listener function).
* @param {number} [priority] The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0)
* @return {Phaser.SignalBinding} An Object representing the binding between the Signal and listener.
*/
addOnce: function (listener, listenerContext, priority) {
this.validateListener(listener, 'addOnce');
return this._registerListener(listener, true, listenerContext, priority);
},
/**
* Add listener to the signal that should be removed after first execution (will be executed only once).
*
* @method Phaser.Signal#addOnce
* @param {function} listener Signal handler function.
* @param {object} [listenerContext] Context on which listener will be executed (object that should represent the `this` variable inside listener function).
* @param {number} [priority] The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0)
* @return {Phaser.SignalBinding} An Object representing the binding between the Signal and listener.
*/
addOnce: function (listener, listenerContext, priority) {
this.validateListener(listener, 'addOnce');
return this._registerListener(listener, true, listenerContext, priority);
},
/**
* Remove a single listener from the dispatch queue.
*
* @method Phaser.Signal#remove
* @param {function} listener Handler function that should be removed.
* @param {object} [context] Execution context (since you can add the same handler multiple times if executing in a different context).
* @return {function} Listener handler function.
*/
remove: function (listener, context) {
/**
* Remove a single listener from the dispatch queue.
*
* @method Phaser.Signal#remove
* @param {function} listener Handler function that should be removed.
* @param {object} [context] Execution context (since you can add the same handler multiple times if executing in a different context).
* @return {function} Listener handler function.
*/
remove: function (listener, context) {
this.validateListener(listener, 'remove');
this.validateListener(listener, 'remove');
var i = this._indexOfListener(listener, context);
var i = this._indexOfListener(listener, context);
if (i !== -1)
{
this._bindings[i]._destroy(); //no reason to a Phaser.SignalBinding exist if it isn't attached to a signal
this._bindings.splice(i, 1);
}
if (i !== -1)
{
this._bindings[i]._destroy(); //no reason to a Phaser.SignalBinding exist if it isn't attached to a signal
this._bindings.splice(i, 1);
}
return listener;
return listener;
},
},
/**
* Remove all listeners from the Signal.
*
* @method Phaser.Signal#removeAll
*/
removeAll: function () {
var n = this._bindings.length;
while (n--) {
this._bindings[n]._destroy();
}
this._bindings.length = 0;
},
/**
* Remove all listeners from the Signal.
*
* @method Phaser.Signal#removeAll
*/
removeAll: function () {
var n = this._bindings.length;
while (n--) {
this._bindings[n]._destroy();
}
this._bindings.length = 0;
},
/**
* Gets the total number of listeneres attached to ths Signal.
*
* @method Phaser.Signal#getNumListeners
* @return {number} Number of listeners attached to the Signal.
*/
getNumListeners: function () {
return this._bindings.length;
},
/**
* Gets the total number of listeneres attached to ths Signal.
*
* @method Phaser.Signal#getNumListeners
* @return {number} Number of listeners attached to the Signal.
*/
getNumListeners: function () {
return this._bindings.length;
},
/**
* Stop propagation of the event, blocking the dispatch to next listeners on the queue.
* <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
*
* @method Phaser.Signal#halt
*/
halt: function () {
this._shouldPropagate = false;
},
/**
* Stop propagation of the event, blocking the dispatch to next listeners on the queue.
* <p><strong>IMPORTANT:</strong> should be called only during signal dispatch, calling it before/after dispatch won't affect signal broadcast.</p>
* @see Signal.prototype.disable
*
* @method Phaser.Signal#halt
*/
halt: function () {
this._shouldPropagate = false;
},
/**
* Dispatch/Broadcast Signal to all listeners added to the queue.
*
* @method Phaser.Signal#dispatch
* @param {any} [params] - Parameters that should be passed to each handler.
*/
dispatch: function (params) {
if (! this.active) {
return;
}
/**
* Dispatch/Broadcast Signal to all listeners added to the queue.
*
* @method Phaser.Signal#dispatch
* @param {...} [params] - Parameters that should be passed to each handler.
*/
dispatch: function () {
var paramsArr = Array.prototype.slice.call(arguments),
n = this._bindings.length,
bindings;
if (!this.active)
{
return;
}
if (this.memorize) {
this._prevParams = paramsArr;
}
var paramsArr = Array.prototype.slice.call(arguments);
var n = this._bindings.length;
var bindings;
if (! n) {
//should come after memorize
return;
}
if (this.memorize)
{
this._prevParams = paramsArr;
}
bindings = this._bindings.slice(); //clone array in case add/remove items during dispatch
this._shouldPropagate = true; //in case `halt` was called before dispatch or during the previous dispatch.
if (!n)
{
// Should come after memorize
return;
}
//execute all callbacks until end of the list or until a callback returns `false` or stops propagation
//reverse loop since listeners with higher priority will be added at the end of the list
do { n--; } while (bindings[n] && this._shouldPropagate && bindings[n].execute(paramsArr) !== false);
},
bindings = this._bindings.slice(); //clone array in case add/remove items during dispatch
this._shouldPropagate = true; //in case `halt` was called before dispatch or during the previous dispatch.
/**
* Forget memorized arguments.
* @see Signal.memorize
*
* @method Phaser.Signal#forget
*/
forget: function(){
this._prevParams = null;
},
//execute all callbacks until end of the list or until a callback returns `false` or stops propagation
//reverse loop since listeners with higher priority will be added at the end of the list
do { n--; } while (bindings[n] && this._shouldPropagate && bindings[n].execute(paramsArr) !== false);
},
/**
* Remove all bindings from signal and destroy any reference to external objects (destroy Signal object).
* <p><strong>IMPORTANT:</strong> calling any method on the signal instance after calling dispose will throw errors.</p>
*
* @method Phaser.Signal#dispose
*/
dispose: function () {
this.removeAll();
delete this._bindings;
delete this._prevParams;
},
/**
* Forget memorized arguments.
* @see Signal.memorize
*
* @method Phaser.Signal#forget
*/
forget: function(){
this._prevParams = null;
},
/**
*
* @method Phaser.Signal#toString
* @return {string} String representation of the object.
*/
toString: function () {
return '[Phaser.Signal active:'+ this.active +' numListeners:'+ this.getNumListeners() +']';
}
/**
* Remove all bindings from signal and destroy any reference to external objects (destroy Signal object).
* <p><strong>IMPORTANT:</strong> calling any method on the signal instance after calling dispose will throw errors.</p>
*
* @method Phaser.Signal#dispose
*/
dispose: function () {
this.removeAll();
delete this._bindings;
delete this._prevParams;
},
/**
*
* @method Phaser.Signal#toString
* @return {string} String representation of the object.
*/
toString: function () {
return '[Phaser.Signal active:'+ this.active +' numListeners:'+ this.getNumListeners() +']';
}
};

View file

@ -25,33 +25,33 @@
Phaser.SignalBinding = function (signal, listener, isOnce, listenerContext, priority) {
/**
* @property {Phaser.Game} _listener - Handler function bound to the signal.
* @private
*/
* @property {Phaser.Game} _listener - Handler function bound to the signal.
* @private
*/
this._listener = listener;
/**
* @property {boolean} _isOnce - If binding should be executed just once.
* @private
*/
* @property {boolean} _isOnce - If binding should be executed just once.
* @private
*/
this._isOnce = isOnce;
/**
* @property {object|undefined|null} context - Context on which listener will be executed (object that should represent the `this` variable inside listener function).
* @memberof SignalBinding.prototype
*/
* @property {object|undefined|null} context - Context on which listener will be executed (object that should represent the `this` variable inside listener function).
* @memberof SignalBinding.prototype
*/
this.context = listenerContext;
/**
* @property {Signal} _signal - Reference to Signal object that listener is currently bound to.
* @private
*/
* @property {Signal} _signal - Reference to Signal object that listener is currently bound to.
* @private
*/
this._signal = signal;
/**
* @property {number} _priority - Listener priority.
* @private
*/
* @property {number} _priority - Listener priority.
* @private
*/
this._priority = priority || 0;
};
@ -62,7 +62,7 @@ Phaser.SignalBinding.prototype = {
* If binding is active and should be executed.
* @property {boolean} active
* @default
*/
*/
active: true,
/**

View file

@ -17,26 +17,26 @@
Phaser.Stage = function (game, width, height) {
/**
* @property {Phaser.Game} game - A reference to the currently running Game.
*/
this.game = game;
* @property {Phaser.Game} game - A reference to the currently running Game.
*/
this.game = game;
/**
* @property {string} game - Background color of the stage (defaults to black). Set via the public backgroundColor property.
* @private
* @default 'rgb(0,0,0)'
*/
* @property {string} game - Background color of the stage (defaults to black). Set via the public backgroundColor property.
* @private
* @default 'rgb(0,0,0)'
*/
this._backgroundColor = 'rgb(0,0,0)';
/**
* @property {Phaser.Point} offset - Get the offset values (for input and other things).
*/
this.offset = new Phaser.Point;
* @property {Phaser.Point} offset - Get the offset values (for input and other things).
*/
this.offset = new Phaser.Point();
/**
* @property {HTMLCanvasElement} canvas - Reference to the newly created &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%';
/**
@ -49,7 +49,7 @@ Phaser.Stage = function (game, width, height) {
/**
* @property {number} scaleMode - The current scaleMode.
*/
*/
this.scaleMode = Phaser.StageScaleMode.NO_SCALE;
/**
@ -126,7 +126,7 @@ Phaser.Stage.prototype = {
},
/**
/**
* This method is called when the document visibility is changed.
* @method Phaser.Stage#visibilityChange
* @param {Event} event - Its type will be used to decide whether the game should be paused or not.
@ -138,16 +138,16 @@ Phaser.Stage.prototype = {
return;
}
if (event.type == 'pagehide' || event.type == 'blur' || document['hidden'] == true || document['webkitHidden'] == true)
if (event.type == 'pagehide' || event.type == 'blur' || document['hidden'] === true || document['webkitHidden'] === true)
{
this.game.paused = true;
this.game.paused = true;
}
else
{
this.game.paused = false;
this.game.paused = false;
}
},
}
};

View file

@ -15,86 +15,86 @@
Phaser.State = function () {
/**
* @property {Phaser.Game} game - A reference to the currently running Game.
*/
* @property {Phaser.Game} game - A reference to the currently running Game.
*/
this.game = null;
/**
* @property {Phaser.GameObjectFactory} add - Reference to the GameObjectFactory.
* @default
*/
/**
* @property {Phaser.GameObjectFactory} add - Reference to the GameObjectFactory.
* @default
*/
this.add = null;
/**
* @property {Phaser.Physics.PhysicsManager} camera - A handy reference to world.camera.
* @default
*/
* @property {Phaser.Camera} camera - A handy reference to world.camera.
* @default
*/
this.camera = null;
/**
* @property {Phaser.Cache} cache - Reference to the assets cache.
* @default
*/
* @property {Phaser.Cache} cache - Reference to the assets cache.
* @default
*/
this.cache = null;
/**
* @property {Phaser.Input} input - Reference to the input manager
* @default
*/
* @property {Phaser.Input} input - Reference to the input manager
* @default
*/
this.input = null;
/**
* @property {Phaser.Loader} load - Reference to the assets loader.
* @default
*/
* @property {Phaser.Loader} load - Reference to the assets loader.
* @default
*/
this.load = null;
/**
* @property {Phaser.Math} math - Reference to the math helper.
* @default
*/
* @property {Phaser.Math} math - Reference to the math helper.
* @default
*/
this.math = null;
/**
* @property {Phaser.SoundManager} sound - Reference to the sound manager.
* @default
*/
* @property {Phaser.SoundManager} sound - Reference to the sound manager.
* @default
*/
this.sound = null;
/**
* @property {Phaser.Stage} stage - Reference to the stage.
* @default
*/
* @property {Phaser.Stage} stage - Reference to the stage.
* @default
*/
this.stage = null;
/**
* @property {Phaser.TimeManager} time - Reference to game clock.
* @default
*/
* @property {Phaser.TimeManager} time - Reference to game clock.
* @default
*/
this.time = null;
/**
* @property {Phaser.TweenManager} tweens - Reference to the tween manager.
* @default
*/
* @property {Phaser.TweenManager} tweens - Reference to the tween manager.
* @default
*/
this.tweens = null;
/**
* @property {Phaser.World} world - Reference to the world.
* @default
*/
* @property {Phaser.World} world - Reference to the world.
* @default
*/
this.world = null;
/**
* @property {Description} add - Description.
* @default
*/
/**
* @property {Phaser.Particles} particles - The Particle Manager for the game. It is called during the game update loop and in turn updates any Emitters attached to it.
* @default
*/
this.particles = null;
/**
* @property {Phaser.Physics.PhysicsManager} physics - Reference to the physics manager.
* @default
*/
* @property {Phaser.Physics.PhysicsManager} physics - Reference to the physics manager.
* @default
*/
this.physics = null;
};

View file

@ -1,3 +1,5 @@
/* jshint newcap: false */
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2013 Photon Storm Ltd.
@ -14,148 +16,117 @@
*/
Phaser.StateManager = function (game, pendingState) {
/**
* A reference to the currently running game.
* @property {Phaser.Game} game.
*/
this.game = game;
/**
* @property {Phaser.Game} game - A reference to the currently running game.
*/
this.game = game;
/**
* Description.
* @property {Description} states.
*/
this.states = {};
/**
* @property {Object} states - The object containing Phaser.States.
*/
this.states = {};
/**
* @property {Phaser.State} _pendingState - The state to be switched to in the next frame.
* @private
*/
this._pendingState = null;
if (pendingState !== null)
{
this._pendingState = pendingState;
}
/**
* @property {boolean} _created - Flag that sets if the State has been created or not.
* @private
*/
this._created = false;
/**
* @property {string} current - The current active State object (defaults to null).
*/
this.current = '';
/**
* @property {function} onInitCallback - This will be called when the state is started (i.e. set as the current active state).
*/
this.onInitCallback = null;
/**
* @property {function} onPreloadCallback - This will be called when init states (loading assets...).
*/
this.onPreloadCallback = null;
/**
* @property {function} onCreateCallback - This will be called when create states (setup states...).
*/
this.onCreateCallback = null;
/**
* @property {function} onUpdateCallback - This will be called when State is updated, this doesn't happen during load (@see onLoadUpdateCallback).
*/
this.onUpdateCallback = null;
/**
* @property {function} onRenderCallback - This will be called when the State is rendered, this doesn't happen during load (see onLoadRenderCallback).
*/
this.onRenderCallback = null;
/**
* @property {function} onPreRenderCallback - This will be called before the State is rendered and before the stage is cleared.
*/
this.onPreRenderCallback = null;
/**
* @property {function} onLoadUpdateCallback - This will be called when the State is updated but only during the load process.
*/
this.onLoadUpdateCallback = null;
/**
* @property {function} onLoadRenderCallback - This will be called when the State is rendered but only during the load process.
*/
this.onLoadRenderCallback = null;
/**
* @property {function} onPausedCallback - This will be called when the state is paused.
*/
this.onPausedCallback = null;
/**
* @property {function} onShutDownCallback - This will be called when the state is shut down (i.e. swapped to another state).
*/
this.onShutDownCallback = null;
if (pendingState !== null)
{
this._pendingState = pendingState;
}
};
Phaser.StateManager.prototype = {
/**
* A reference to the currently running game.
* @property {Phaser.Game} game.
*/
game: null,
/**
* The state to be switched to in the next frame.
* @property {State} _pendingState
* @private
*/
_pendingState: null,
/**
* The Boot handler is called by Phaser.Game when it first starts up.
* @method Phaser.StateManager#boot
* @private
*/
boot: function () {
/**
* Flag that sets if the State has been created or not.
* @property {boolean}_created
* @private
*/
_created: false,
if (this._pendingState !== null)
{
if (typeof this._pendingState === 'string')
{
// State was already added, so just start it
this.start(this._pendingState, false, false);
}
else
{
this.add('default', this._pendingState, true);
}
/**
* The state to be switched to in the next frame.
* @property {Description} states
*/
states: {},
}
/**
* The current active State object (defaults to null).
* @property {string} current
*/
current: '',
/**
* This will be called when the state is started (i.e. set as the current active state).
* @property {function} onInitCallback
*/
onInitCallback: null,
},
/**
* This will be called when init states (loading assets...).
* @property {function} onPreloadCallback
*/
onPreloadCallback: null,
/**
* This will be called when create states (setup states...).
* @property {function} onCreateCallback
*/
onCreateCallback: null,
/**
* This will be called when State is updated, this doesn't happen during load (@see onLoadUpdateCallback).
* @property {function} onUpdateCallback
*/
onUpdateCallback: null,
/**
* This will be called when the State is rendered, this doesn't happen during load (see onLoadRenderCallback).
* @property {function} onRenderCallback
*/
onRenderCallback: null,
/**
* This will be called before the State is rendered and before the stage is cleared.
* @property {function} onPreRenderCallback
*/
onPreRenderCallback: null,
/**
* This will be called when the State is updated but only during the load process.
* @property {function} onLoadUpdateCallback
*/
onLoadUpdateCallback: null,
/**
* This will be called when the State is rendered but only during the load process.
* @property {function} onLoadRenderCallback
*/
onLoadRenderCallback: null,
/**
* This will be called when states paused.
* @property {function} onPausedCallback
*/
onPausedCallback: null,
/**
* This will be called when the state is shut down (i.e. swapped to another state).
* @property {function} onShutDownCallback
*/
onShutDownCallback: null,
/**
* Description.
* @method Phaser.StateManager#boot
* @private
*/
boot: function () {
// console.log('Phaser.StateManager.boot');
if (this._pendingState !== null)
{
// console.log('_pendingState found');
// console.log(typeof this._pendingState);
if (typeof this._pendingState === 'string')
{
// State was already added, so just start it
this.start(this._pendingState, false, false);
}
else
{
this.add('default', this._pendingState, true);
}
}
},
/**
/**
* Add a new State.
* @method Phaser.StateManager#add
* @param key {string} - A unique key you use to reference this state, i.e. "MainMenu", "Level1".
@ -166,78 +137,69 @@ Phaser.StateManager.prototype = {
if (typeof autoStart === "undefined") { autoStart = false; }
// console.log('Phaser.StateManager.addState', key);
// console.log(typeof state);
// console.log('autoStart?', autoStart);
var newState;
var newState;
if (state instanceof Phaser.State)
{
newState = state;
}
else if (typeof state === 'object')
{
newState = state;
newState.game = this.game;
}
else if (typeof state === 'function')
{
newState = new state(this.game);
}
if (state instanceof Phaser.State)
{
// console.log('Phaser.StateManager.addState: Phaser.State given');
newState = state;
}
else if (typeof state === 'object')
{
// console.log('Phaser.StateManager.addState: Object given');
newState = state;
newState.game = this.game;
}
else if (typeof state === 'function')
{
// console.log('Phaser.StateManager.addState: Function given');
newState = new state(this.game);
}
this.states[key] = newState;
this.states[key] = newState;
if (autoStart)
{
if (this.game.isBooted)
{
this.start(key);
}
else
{
this._pendingState = key;
}
}
if (autoStart)
{
if (this.game.isBooted)
{
// console.log('Game is booted, so we can start the state now');
this.start(key);
}
else
{
// console.log('Game is NOT booted, so set the current state as pending');
this._pendingState = key;
}
}
return newState;
return newState;
},
/**
/**
* Delete the given state.
* @method Phaser.StateManager#remove
* @param {string} key - A unique key you use to reference this state, i.e. "MainMenu", "Level1".
*/
remove: function (key) {
if (this.current == key)
{
this.callbackContext = null;
if (this.current == key)
{
this.callbackContext = null;
this.onInitCallback = null;
this.onShutDownCallback = null;
this.onInitCallback = null;
this.onShutDownCallback = null;
this.onPreloadCallback = null;
this.onLoadRenderCallback = null;
this.onLoadUpdateCallback = null;
this.onCreateCallback = null;
this.onUpdateCallback = null;
this.onRenderCallback = null;
this.onPausedCallback = null;
this.onDestroyCallback = null;
}
this.onPreloadCallback = null;
this.onLoadRenderCallback = null;
this.onLoadUpdateCallback = null;
this.onCreateCallback = null;
this.onUpdateCallback = null;
this.onRenderCallback = null;
this.onPausedCallback = null;
this.onDestroyCallback = null;
}
delete this.states[key];
delete this.states[key];
},
/**
/**
* Start the given state
* @method Phaser.StateManager#start
* @param {string} key - The key of the state you want to start.
@ -246,84 +208,75 @@ Phaser.StateManager.prototype = {
*/
start: function (key, clearWorld, clearCache) {
// console.log('Phaser.StateManager.start', key);
// console.log(this);
// console.log(this.callbackContext);
if (typeof clearWorld === "undefined") { clearWorld = true; }
if (typeof clearCache === "undefined") { clearCache = false; }
if (this.game.isBooted == false)
if (this.game.isBooted === false)
{
// console.log('Game is NOT booted, so set the requested state as pending');
this._pendingState = key;
return;
this._pendingState = key;
return;
}
if (this.checkState(key) == false)
{
return;
}
else
{
// Already got a state running?
if (this.current)
{
this.onShutDownCallback.call(this.callbackContext, this.game);
}
if (this.checkState(key) === false)
{
return;
}
else
{
// Already got a state running?
if (this.current)
{
this.onShutDownCallback.call(this.callbackContext, this.game);
}
if (clearWorld)
{
this.game.tweens.removeAll();
if (clearWorld)
{
this.game.tweens.removeAll();
this.game.world.destroy();
this.game.world.destroy();
if (clearCache == true)
{
this.game.cache.destroy();
}
}
if (clearCache === true)
{
this.game.cache.destroy();
}
}
this.setCurrentState(key);
}
this.setCurrentState(key);
}
if (this.onPreloadCallback)
{
// console.log('Preload Callback found');
this.game.load.reset();
this.onPreloadCallback.call(this.callbackContext, this.game);
// Is the loader empty?
if (this.game.load.queueSize == 0)
if (this.game.load.queueSize === 0)
{
// console.log('Loader queue empty');
this.game.loadComplete();
}
else
{
// console.log('Loader started');
// Start the loader going as we have something in the queue
this.game.load.start();
}
}
else
{
// console.log('Preload callback not found');
// No init? Then there was nothing to load either
this.game.loadComplete();
}
},
/**
* Used by onInit and onShutdown when those functions don't exist on the state
/**
* Used by onInit and onShutdown when those functions don't exist on the state
* @method Phaser.StateManager#dummy
* @private
*/
dummy: function () {
},
/**
/**
* Description.
* @method Phaser.StateManager#checkState
* @param {string} key - The key of the state you want to check.
@ -331,37 +284,37 @@ Phaser.StateManager.prototype = {
*/
checkState: function (key) {
if (this.states[key])
{
var valid = false;
if (this.states[key])
{
var valid = false;
if (this.states[key]['preload']) { valid = true; }
if (this.states[key]['preload']) { valid = true; }
if (valid == false && this.states[key]['loadRender']) { valid = true; }
if (valid == false && this.states[key]['loadUpdate']) { valid = true; }
if (valid == false && this.states[key]['create']) { valid = true; }
if (valid == false && this.states[key]['update']) { valid = true; }
if (valid == false && this.states[key]['preRender']) { valid = true; }
if (valid == false && this.states[key]['render']) { valid = true; }
if (valid == false && this.states[key]['paused']) { valid = true; }
if (valid === false && this.states[key]['loadRender']) { valid = true; }
if (valid === false && this.states[key]['loadUpdate']) { valid = true; }
if (valid === false && this.states[key]['create']) { valid = true; }
if (valid === false && this.states[key]['update']) { valid = true; }
if (valid === false && this.states[key]['preRender']) { valid = true; }
if (valid === false && this.states[key]['render']) { valid = true; }
if (valid === false && this.states[key]['paused']) { valid = true; }
if (valid == false)
{
console.warn("Invalid Phaser State object given. Must contain at least a one of the required functions.");
return false;
}
if (valid === false)
{
console.warn("Invalid Phaser State object given. Must contain at least a one of the required functions.");
return false;
}
return true;
}
else
{
console.warn("Phaser.StateManager - No state found with the key: " + key);
return false;
}
return true;
}
else
{
console.warn("Phaser.StateManager - No state found with the key: " + key);
return false;
}
},
/**
/**
* Links game properties to the State given by the key.
* @method Phaser.StateManager#link
* @param {string} key - State key.
@ -369,7 +322,6 @@ Phaser.StateManager.prototype = {
*/
link: function (key) {
// console.log('linked');
this.states[key].game = this.game;
this.states[key].add = this.game.add;
this.states[key].camera = this.game.camera;
@ -388,19 +340,19 @@ Phaser.StateManager.prototype = {
},
/**
/**
* Sets the current State. Should not be called directly (use StateManager.start)
* @method Phaser.StateManager#setCurrentState
* @param {string} key - State key.
* @protected
*/
setCurrentState: function (key) {
setCurrentState: function (key) {
this.callbackContext = this.states[key];
this.link(key);
// Used when the state is set as being the current active state
// Used when the state is set as being the current active state
this.onInitCallback = this.states[key]['init'] || this.dummy;
this.onPreloadCallback = this.states[key]['preload'] || null;
@ -412,102 +364,99 @@ Phaser.StateManager.prototype = {
this.onRenderCallback = this.states[key]['render'] || null;
this.onPausedCallback = this.states[key]['paused'] || null;
// Used when the state is no longer the current active state
// Used when the state is no longer the current active state
this.onShutDownCallback = this.states[key]['shutdown'] || this.dummy;
this.current = key;
this._created = false;
this.current = key;
this._created = false;
this.onInitCallback.call(this.callbackContext, this.game);
this.onInitCallback.call(this.callbackContext, this.game);
},
},
/**
* @method Phaser.StateManager#loadComplete
/**
* @method Phaser.StateManager#loadComplete
* @protected
*/
*/
loadComplete: function () {
// console.log('Phaser.StateManager.loadComplete');
if (this._created == false && this.onCreateCallback)
if (this._created === false && this.onCreateCallback)
{
// console.log('Create callback found');
this._created = true;
this._created = true;
this.onCreateCallback.call(this.callbackContext, this.game);
}
else
{
this._created = true;
this._created = true;
}
},
/**
* @method Phaser.StateManager#update
/**
* @method Phaser.StateManager#update
* @protected
*/
*/
update: function () {
if (this._created && this.onUpdateCallback)
{
this.onUpdateCallback.call(this.callbackContext, this.game);
}
else
{
if (this.onLoadUpdateCallback)
{
this.onLoadUpdateCallback.call(this.callbackContext, this.game);
}
}
if (this._created && this.onUpdateCallback)
{
this.onUpdateCallback.call(this.callbackContext, this.game);
}
else
{
if (this.onLoadUpdateCallback)
{
this.onLoadUpdateCallback.call(this.callbackContext, this.game);
}
}
},
/**
* @method Phaser.StateManager#preRender
/**
* @method Phaser.StateManager#preRender
* @protected
*/
*/
preRender: function () {
if (this.onPreRenderCallback)
{
this.onPreRenderCallback.call(this.callbackContext, this.game);
}
if (this.onPreRenderCallback)
{
this.onPreRenderCallback.call(this.callbackContext, this.game);
}
},
/**
* @method Phaser.StateManager#render
/**
* @method Phaser.StateManager#render
* @protected
*/
*/
render: function () {
if (this._created && this.onRenderCallback)
{
if (this.game.renderType === Phaser.CANVAS)
{
this.game.context.save();
this.game.context.setTransform(1, 0, 0, 1, 0, 0);
}
if (this._created && this.onRenderCallback)
{
if (this.game.renderType === Phaser.CANVAS)
{
this.game.context.save();
this.game.context.setTransform(1, 0, 0, 1, 0, 0);
}
this.onRenderCallback.call(this.callbackContext, this.game);
this.onRenderCallback.call(this.callbackContext, this.game);
if (this.game.renderType === Phaser.CANVAS)
{
this.game.context.restore();
}
}
else
{
if (this.onLoadRenderCallback)
{
this.onLoadRenderCallback.call(this.callbackContext, this.game);
}
}
if (this.game.renderType === Phaser.CANVAS)
{
this.game.context.restore();
}
}
else
{
if (this.onLoadRenderCallback)
{
this.onLoadRenderCallback.call(this.callbackContext, this.game);
}
}
},
/**
/**
* Nuke the entire game from orbit
* @method Phaser.StateManager#destroy
*/

View file

@ -21,7 +21,7 @@ Phaser.World = function (game) {
/**
* @property {Phaser.Point} scale - Replaces the PIXI.Point with a slightly more flexible one.
*/
*/
this.scale = new Phaser.Point(1, 1);
/**
@ -29,20 +29,20 @@ Phaser.World = function (game) {
* By default we set the Bounds to be from 0,0 to Game.width,Game.height. I.e. it will match the size given to the game constructor with 0,0 representing the top-left of the display.
* However 0,0 is actually the center of the world, and if you rotate or scale the world all of that will happen from 0,0.
* So if you want to make a game in which the world itself will rotate you should adjust the bounds so that 0,0 is the center point, i.e. set them to -1000,-1000,2000,2000 for a 2000x2000 sized world centered around 0,0.
* @property {Phaser.Rectangle} bounds - Bound of this world that objects can not escape from.
*/
this.bounds = new Phaser.Rectangle(0, 0, game.width, game.height);
* @property {Phaser.Rectangle} bounds - Bound of this world that objects can not escape from.
*/
this.bounds = new Phaser.Rectangle(0, 0, game.width, game.height);
/**
* @property {Phaser.Camera} camera - Camera instance.
*/
this.camera = null;
* @property {Phaser.Camera} camera - Camera instance.
*/
this.camera = null;
/**
* @property {number} currentRenderOrderID - Reset each frame, keeps a count of the total number of objects updated.
*/
this.currentRenderOrderID = 0;
* @property {number} currentRenderOrderID - Reset each frame, keeps a count of the total number of objects updated.
*/
this.currentRenderOrderID = 0;
};
Phaser.World.prototype = Object.create(Phaser.Group.prototype);
@ -71,27 +71,27 @@ Phaser.World.prototype.boot = function () {
*/
Phaser.World.prototype.update = function () {
this.currentRenderOrderID = 0;
this.currentRenderOrderID = 0;
if (this.game.stage._stage.first._iNext)
{
var currentNode = this.game.stage._stage.first._iNext;
if (this.game.stage._stage.first._iNext)
{
var currentNode = this.game.stage._stage.first._iNext;
var skipChildren;
do
{
do
{
skipChildren = false;
if (currentNode['preUpdate'])
{
skipChildren = (currentNode.preUpdate() === false);
}
if (currentNode['preUpdate'])
{
skipChildren = (currentNode.preUpdate() === false);
}
if (currentNode['update'])
{
skipChildren = (currentNode.update() === false) || skipChildren;
}
if (currentNode['update'])
{
skipChildren = (currentNode.update() === false) || skipChildren;
}
if (skipChildren)
{
currentNode = currentNode.last._iNext;
@ -100,10 +100,10 @@ Phaser.World.prototype.update = function () {
{
currentNode = currentNode._iNext;
}
}
while (currentNode != this.game.stage._stage.last._iNext)
}
}
while (currentNode != this.game.stage._stage.last._iNext)
}
}
@ -119,7 +119,7 @@ Phaser.World.prototype.postUpdate = function () {
{
var currentNode = this.game.stage._stage.first._iNext;
do
do
{
if (currentNode['postUpdate'])
{

File diff suppressed because it is too large Load diff

View file

@ -25,28 +25,28 @@ Phaser.BitmapText = function (game, x, y, text, style) {
text = text || '';
style = style || '';
/**
* @property {boolean} exists - If exists = false then the Sprite isn't updated by the core game loop or physics subsystem at all.
* @default
*/
/**
* @property {boolean} exists - If exists = false then the Sprite isn't updated by the core game loop or physics subsystem at all.
* @default
*/
this.exists = true;
/**
/**
* @property {boolean} alive - This is a handy little var your game can use to determine if a sprite is alive or not, it doesn't effect rendering.
* @default
*/
* @default
*/
this.alive = true;
/**
/**
* @property {Description} group - Description.
* @default
*/
* @default
*/
this.group = null;
/**
/**
* @property {string} name - Description.
* @default
*/
* @default
*/
this.name = '';
/**
@ -61,54 +61,62 @@ Phaser.BitmapText = function (game, x, y, text, style) {
*/
this.type = Phaser.BITMAPTEXT;
/**
* @property {number} position.x - Description.
*/
/**
* @property {number} position.x - Description.
*/
this.position.x = x;
/**
* @property {number} position.y - Description.
*/
/**
* @property {number} position.y - Description.
*/
this.position.y = y;
// Replaces the PIXI.Point with a slightly more flexible one
/**
* @property {Phaser.Point} anchor - Description.
*/
/**
* @property {Phaser.Point} anchor - Description.
*/
this.anchor = new Phaser.Point();
/**
* @property {Phaser.Point} scale - Description.
*/
/**
* @property {Phaser.Point} scale - Description.
*/
this.scale = new Phaser.Point(1, 1);
// A mini cache for storing all of the calculated values
/**
* @property {function} _cache - Description.
* @private
*/
this._cache = {
/**
* @property {function} _cache - Description.
* @private
*/
this._cache = {
dirty: false,
// Transform cache
a00: 1, a01: 0, a02: x, a10: 0, a11: 1, a12: y, id: 1,
a00: 1,
a01: 0,
a02: x,
a10: 0,
a11: 1,
a12: y,
id: 1,
// The previous calculated position
x: -1, y: -1,
x: -1,
y: -1,
// The actual scale values based on the worldTransform
scaleX: 1, scaleY: 1
scaleX: 1,
scaleY: 1
};
this._cache.x = this.x;
this._cache.y = this.y;
/**
* @property {boolean} renderable - Description.
* @private
*/
/**
* @property {boolean} renderable - Description.
* @private
*/
this.renderable = true;
};

View file

@ -33,67 +33,67 @@ Phaser.Button = function (game, x, y, key, callback, callbackContext, overFrame,
callback = callback || null;
callbackContext = callbackContext || this;
Phaser.Sprite.call(this, game, x, y, key, outFrame);
Phaser.Sprite.call(this, game, x, y, key, outFrame);
/**
* @property {number} type - The Phaser Object Type.
*/
/**
* @property {number} type - The Phaser Object Type.
*/
this.type = Phaser.BUTTON;
/**
* @property {string} _onOverFrameName - Internal variable.
* @private
* @default
*/
/**
* @property {string} _onOverFrameName - Internal variable.
* @private
* @default
*/
this._onOverFrameName = null;
/**
* @property {string} _onOutFrameName - Internal variable.
* @private
* @default
*/
/**
* @property {string} _onOutFrameName - Internal variable.
* @private
* @default
*/
this._onOutFrameName = null;
/**
* @property {string} _onDownFrameName - Internal variable.
* @private
* @default
*/
/**
* @property {string} _onDownFrameName - Internal variable.
* @private
* @default
*/
this._onDownFrameName = null;
/**
* @property {string} _onUpFrameName - Internal variable.
* @private
* @default
*/
/**
* @property {string} _onUpFrameName - Internal variable.
* @private
* @default
*/
this._onUpFrameName = null;
/**
* @property {number} _onOverFrameID - Internal variable.
* @private
* @default
*/
/**
* @property {number} _onOverFrameID - Internal variable.
* @private
* @default
*/
this._onOverFrameID = null;
/**
* @property {number} _onOutFrameID - Internal variable.
* @private
* @default
*/
/**
* @property {number} _onOutFrameID - Internal variable.
* @private
* @default
*/
this._onOutFrameID = null;
/**
* @property {number} _onDownFrameID - Internal variable.
* @private
* @default
*/
/**
* @property {number} _onDownFrameID - Internal variable.
* @private
* @default
*/
this._onDownFrameID = null;
/**
* @property {number} _onUpFrameID - Internal variable.
* @private
* @default
*/
/**
* @property {number} _onUpFrameID - Internal variable.
* @private
* @default
*/
this._onUpFrameID = null;
/**
@ -144,25 +144,25 @@ Phaser.Button = function (game, x, y, key, callback, callbackContext, overFrame,
*/
this.onUpSoundMarker = '';
/**
* @property {Phaser.Signal} onInputOver - The Signal (or event) dispatched when this Button is in an Over state.
*/
this.onInputOver = new Phaser.Signal;
/**
* @property {Phaser.Signal} onInputOver - The Signal (or event) dispatched when this Button is in an Over state.
*/
this.onInputOver = new Phaser.Signal();
/**
* @property {Phaser.Signal} onInputOut - The Signal (or event) dispatched when this Button is in an Out state.
*/
this.onInputOut = new Phaser.Signal;
/**
* @property {Phaser.Signal} onInputOut - The Signal (or event) dispatched when this Button is in an Out state.
*/
this.onInputOut = new Phaser.Signal();
/**
* @property {Phaser.Signal} onInputDown - The Signal (or event) dispatched when this Button is in an Down state.
*/
this.onInputDown = new Phaser.Signal;
/**
* @property {Phaser.Signal} onInputDown - The Signal (or event) dispatched when this Button is in an Down state.
*/
this.onInputDown = new Phaser.Signal();
/**
* @property {Phaser.Signal} onInputUp - The Signal (or event) dispatched when this Button is in an Up state.
*/
this.onInputUp = new Phaser.Signal;
/**
* @property {Phaser.Signal} onInputUp - The Signal (or event) dispatched when this Button is in an Up state.
*/
this.onInputUp = new Phaser.Signal();
/**
* @property {boolean} freezeFrames - When true the Button will cease to change texture frame on all events (over, out, up, down).
@ -237,7 +237,7 @@ Phaser.Button.prototype.setFrames = function (overFrame, outFrame, downFrame) {
this._onOutFrameName = outFrame;
this._onUpFrameName = outFrame;
if (this.input.pointerOver() == false)
if (this.input.pointerOver() === false)
{
this.frameName = outFrame;
}
@ -247,7 +247,7 @@ Phaser.Button.prototype.setFrames = function (overFrame, outFrame, downFrame) {
this._onOutFrameID = outFrame;
this._onUpFrameID = outFrame;
if (this.input.pointerOver() == false)
if (this.input.pointerOver() === false)
{
this.frame = outFrame;
}
@ -407,7 +407,7 @@ Phaser.Button.prototype.setDownSound = function (sound, marker) {
*/
Phaser.Button.prototype.onInputOverHandler = function (pointer) {
if (this.freezeFrames == false)
if (this.freezeFrames === false)
{
if (this._onOverFrameName != null)
{
@ -439,7 +439,7 @@ Phaser.Button.prototype.onInputOverHandler = function (pointer) {
*/
Phaser.Button.prototype.onInputOutHandler = function (pointer) {
if (this.freezeFrames == false)
if (this.freezeFrames === false)
{
if (this._onOutFrameName != null)
{
@ -471,7 +471,7 @@ Phaser.Button.prototype.onInputOutHandler = function (pointer) {
*/
Phaser.Button.prototype.onInputDownHandler = function (pointer) {
if (this.freezeFrames == false)
if (this.freezeFrames === false)
{
if (this._onDownFrameName != null)
{
@ -503,7 +503,7 @@ Phaser.Button.prototype.onInputDownHandler = function (pointer) {
*/
Phaser.Button.prototype.onInputUpHandler = function (pointer) {
if (this.freezeFrames == false)
if (this.freezeFrames === false)
{
if (this._onUpFrameName != null)
{
@ -520,7 +520,7 @@ Phaser.Button.prototype.onInputUpHandler = function (pointer) {
this.onUpSound.play(this.onUpSoundMarker);
}
if (this.forceOut && this.freezeFrames == false)
if (this.forceOut && this.freezeFrames === false)
{
if (this._onOutFrameName != null)
{

View file

@ -4,7 +4,6 @@
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
/**
* The Events component is a collection of events fired by the parent game object and its components.
*
@ -14,13 +13,13 @@
* @param {Phaser.Sprite} sprite - A reference to Description.
*/
Phaser.Events = function (sprite) {
this.parent = sprite;
this.onAddedToGroup = new Phaser.Signal;
this.onRemovedFromGroup = new Phaser.Signal;
this.onKilled = new Phaser.Signal;
this.onRevived = new Phaser.Signal;
this.onOutOfBounds = new Phaser.Signal;
this.parent = sprite;
this.onAddedToGroup = new Phaser.Signal();
this.onRemovedFromGroup = new Phaser.Signal();
this.onKilled = new Phaser.Signal();
this.onRevived = new Phaser.Signal();
this.onOutOfBounds = new Phaser.Signal();
this.onInputOver = null;
this.onInputOut = null;
@ -29,40 +28,40 @@ Phaser.Events = function (sprite) {
this.onDragStart = null;
this.onDragStop = null;
this.onAnimationStart = null;
this.onAnimationComplete = null;
this.onAnimationLoop = null;
this.onAnimationStart = null;
this.onAnimationComplete = null;
this.onAnimationLoop = null;
};
Phaser.Events.prototype = {
destroy: function () {
destroy: function () {
this.parent = null;
this.onAddedToGroup.dispose();
this.onRemovedFromGroup.dispose();
this.onKilled.dispose();
this.onRevived.dispose();
this.onOutOfBounds.dispose();
this.parent = null;
this.onAddedToGroup.dispose();
this.onRemovedFromGroup.dispose();
this.onKilled.dispose();
this.onRevived.dispose();
this.onOutOfBounds.dispose();
if (this.onInputOver)
{
this.onInputOver.dispose();
this.onInputOut.dispose();
this.onInputDown.dispose();
this.onInputUp.dispose();
this.onDragStart.dispose();
this.onDragStop.dispose();
}
if (this.onInputOver)
{
this.onInputOver.dispose();
this.onInputOut.dispose();
this.onInputDown.dispose();
this.onInputUp.dispose();
this.onDragStart.dispose();
this.onDragStop.dispose();
}
if (this.onAnimationStart)
{
this.onAnimationStart.dispose();
this.onAnimationComplete.dispose();
this.onAnimationLoop.dispose();
}
if (this.onAnimationStart)
{
this.onAnimationStart.dispose();
this.onAnimationComplete.dispose();
this.onAnimationLoop.dispose();
}
}
}
};

View file

@ -14,14 +14,14 @@
Phaser.GameObjectFactory = function (game) {
/**
* @property {Phaser.Game} game - A reference to the currently running Game.
*/
this.game = game;
* @property {Phaser.Game} game - A reference to the currently running Game.
*/
this.game = game;
/**
* @property {Phaser.World} world - A reference to the game world.
*/
this.world = this.game.world;
* @property {Phaser.World} world - A reference to the game world.
*/
this.world = this.game.world;
};
@ -39,7 +39,7 @@ Phaser.GameObjectFactory.prototype = {
},
/**
/**
* Create a new Sprite with specific position and sprite sheet key.
*
* @method Phaser.GameObjectFactory#sprite

View file

@ -5,7 +5,7 @@
*/
/**
* Creates a new <code>Graphics</code> object.
* Creates a new `Graphics` object.
*
* @class Phaser.Graphics
* @constructor
@ -21,22 +21,20 @@ Phaser.Graphics = function (game, x, y) {
PIXI.Graphics.call(this);
/**
* @property {Description} type - Description.
* @property {number} type - The Phaser Object Type.
*/
this.type = Phaser.GRAPHICS;
this.position.x = x;
this.position.y = y;
this.position.y = y;
};
Phaser.Graphics.prototype = Object.create(PIXI.Graphics.prototype);
Phaser.Graphics.prototype.constructor = Phaser.Graphics;
// Add our own custom methods
/**
* Description.
* Destroy this Graphics instance.
*
* @method Phaser.Sprite.prototype.destroy
*/
@ -58,14 +56,14 @@ Phaser.Graphics.prototype.destroy = function() {
*/
Phaser.Graphics.prototype.drawPolygon = function (poly) {
graphics.moveTo(poly.points[0].x, poly.points[0].y);
this.moveTo(poly.points[0].x, poly.points[0].y);
for (var i = 1; i < poly.points.length; i += 1)
{
graphics.lineTo(poly.points[i].x, poly.points[i].y);
this.lineTo(poly.points[i].x, poly.points[i].y);
}
graphics.lineTo(poly.points[0].x, poly.points[0].y);
this.lineTo(poly.points[0].x, poly.points[0].y);
}

View file

@ -15,54 +15,54 @@
*/
Phaser.RenderTexture = function (game, key, width, height) {
/**
* @property {Phaser.Game} game - A reference to the currently running game.
*/
this.game = game;
/**
* @property {Phaser.Game} game - A reference to the currently running game.
*/
this.game = game;
/**
/**
* @property {string} name - the name of the object.
*/
*/
this.name = key;
PIXI.EventTarget.call(this);
PIXI.EventTarget.call(this);
/**
* @property {number} width - the width.
/**
* @property {number} width - the width.
*/
this.width = width || 100;
/**
* @property {number} height - the height.
this.width = width || 100;
/**
* @property {number} height - the height.
*/
this.height = height || 100;
this.height = height || 100;
/**
/**
* @property {PIXI.mat3} indetityMatrix - Matrix object.
*/
this.indetityMatrix = PIXI.mat3.create();
/**
* @property {PIXI.Rectangle} frame - The frame for this texture.
*/
this.frame = new PIXI.Rectangle(0, 0, this.width, this.height);
this.indetityMatrix = PIXI.mat3.create();
/**
* @property {number} type - Base Phaser object type.
/**
* @property {PIXI.Rectangle} frame - The frame for this texture.
*/
this.type = Phaser.RENDERTEXTURE;
this.frame = new PIXI.Rectangle(0, 0, this.width, this.height);
this._tempPoint = { x: 0, y: 0 };
/**
* @property {number} type - Base Phaser object type.
*/
this.type = Phaser.RENDERTEXTURE;
if (PIXI.gl)
{
this.initWebGL();
}
else
{
this.initCanvas();
}
this._tempPoint = { x: 0, y: 0 };
if (PIXI.gl)
{
this.initWebGL();
}
else
{
this.initCanvas();
}
};
Phaser.RenderTexture.prototype = Object.create(PIXI.Texture.prototype);
@ -79,22 +79,22 @@ Phaser.RenderTexture.prototype.constructor = PIXI.RenderTexture;
*/
Phaser.RenderTexture.prototype.render = function(displayObject, position, clear) {
if (typeof position === 'undefined') { position = false; }
if (typeof clear === 'undefined') { clear = false; }
if (typeof position === 'undefined') { position = false; }
if (typeof clear === 'undefined') { clear = false; }
if (displayObject instanceof Phaser.Group)
{
displayObject = displayObject._container;
}
if (displayObject instanceof Phaser.Group)
{
displayObject = displayObject._container;
}
if (PIXI.gl)
{
this.renderWebGL(displayObject, position, clear);
}
else
{
this.renderCanvas(displayObject, position, clear);
}
if (PIXI.gl)
{
this.renderWebGL(displayObject, position, clear);
}
else
{
this.renderCanvas(displayObject, position, clear);
}
}
@ -110,10 +110,10 @@ Phaser.RenderTexture.prototype.render = function(displayObject, position, clear)
*/
Phaser.RenderTexture.prototype.renderXY = function(displayObject, x, y, clear) {
this._tempPoint.x = x;
this._tempPoint.y = y;
this._tempPoint.x = x;
this._tempPoint.y = y;
this.render(displayObject, this._tempPoint, clear);
this.render(displayObject, this._tempPoint, clear);
}
@ -125,64 +125,64 @@ Phaser.RenderTexture.prototype.renderXY = function(displayObject, x, y, clear) {
*/
Phaser.RenderTexture.prototype.initWebGL = function()
{
var gl = PIXI.gl;
this.glFramebuffer = gl.createFramebuffer();
var gl = PIXI.gl;
this.glFramebuffer = gl.createFramebuffer();
gl.bindFramebuffer(gl.FRAMEBUFFER, this.glFramebuffer );
gl.bindFramebuffer(gl.FRAMEBUFFER, this.glFramebuffer );
this.glFramebuffer.width = this.width;
this.glFramebuffer.height = this.height;
this.glFramebuffer.height = this.height;
this.baseTexture = new PIXI.BaseTexture();
this.baseTexture = new PIXI.BaseTexture();
this.baseTexture.width = this.width;
this.baseTexture.height = this.height;
this.baseTexture.width = this.width;
this.baseTexture.height = this.height;
this.baseTexture._glTexture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, this.baseTexture._glTexture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, this.width, this.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, this.width, this.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
this.baseTexture.isRender = true;
this.baseTexture.isRender = true;
gl.bindFramebuffer(gl.FRAMEBUFFER, this.glFramebuffer );
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this.baseTexture._glTexture, 0);
gl.bindFramebuffer(gl.FRAMEBUFFER, this.glFramebuffer );
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this.baseTexture._glTexture, 0);
// create a projection matrix..
this.projection = new PIXI.Point(this.width/2 , -this.height/2);
// create a projection matrix..
this.projection = new PIXI.Point(this.width/2 , -this.height/2);
// set the correct render function..
// this.render = this.renderWebGL;
// set the correct render function..
// this.render = this.renderWebGL;
}
Phaser.RenderTexture.prototype.resize = function(width, height)
{
this.width = width;
this.height = height;
if(PIXI.gl)
{
this.projection.x = this.width/2
this.projection.y = -this.height/2;
var gl = PIXI.gl;
gl.bindTexture(gl.TEXTURE_2D, this.baseTexture._glTexture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, this.width, this.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
}
else
{
this.frame.width = this.width
this.frame.height = this.height;
this.renderer.resize(this.width, this.height);
}
this.width = width;
this.height = height;
if(PIXI.gl)
{
this.projection.x = this.width/2
this.projection.y = -this.height/2;
var gl = PIXI.gl;
gl.bindTexture(gl.TEXTURE_2D, this.baseTexture._glTexture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, this.width, this.height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
}
else
{
this.frame.width = this.width
this.frame.height = this.height;
this.renderer.resize(this.width, this.height);
}
}
/**
@ -193,12 +193,12 @@ Phaser.RenderTexture.prototype.resize = function(width, height)
*/
Phaser.RenderTexture.prototype.initCanvas = function()
{
this.renderer = new PIXI.CanvasRenderer(this.width, this.height, null, 0);
this.renderer = new PIXI.CanvasRenderer(this.width, this.height, null, 0);
this.baseTexture = new PIXI.BaseTexture(this.renderer.view);
this.frame = new PIXI.Rectangle(0, 0, this.width, this.height);
this.baseTexture = new PIXI.BaseTexture(this.renderer.view);
this.frame = new PIXI.Rectangle(0, 0, this.width, this.height);
// this.render = this.renderCanvas;
// this.render = this.renderCanvas;
}
/**
@ -211,69 +211,72 @@ Phaser.RenderTexture.prototype.initCanvas = function()
*/
Phaser.RenderTexture.prototype.renderWebGL = function(displayObject, position, clear)
{
var gl = PIXI.gl;
var gl = PIXI.gl;
// enable the alpha color mask..
gl.colorMask(true, true, true, true);
// enable the alpha color mask..
gl.colorMask(true, true, true, true);
gl.viewport(0, 0, this.width, this.height);
gl.viewport(0, 0, this.width, this.height);
gl.bindFramebuffer(gl.FRAMEBUFFER, this.glFramebuffer );
gl.bindFramebuffer(gl.FRAMEBUFFER, this.glFramebuffer );
if(clear)
{
gl.clearColor(0,0,0, 0);
gl.clear(gl.COLOR_BUFFER_BIT);
}
if (clear)
{
gl.clearColor(0,0,0, 0);
gl.clear(gl.COLOR_BUFFER_BIT);
}
// THIS WILL MESS WITH HIT TESTING!
var children = displayObject.children;
// THIS WILL MESS WITH HIT TESTING!
var children = displayObject.children;
//TODO -? create a new one??? dont think so!
var originalWorldTransform = displayObject.worldTransform;
displayObject.worldTransform = PIXI.mat3.create();//sthis.indetityMatrix;
// modify to flip...
displayObject.worldTransform[4] = -1;
displayObject.worldTransform[5] = this.projection.y * -2;
//TODO -? create a new one??? dont think so!
var originalWorldTransform = displayObject.worldTransform;
displayObject.worldTransform = PIXI.mat3.create();//sthis.indetityMatrix;
// modify to flip...
displayObject.worldTransform[4] = -1;
displayObject.worldTransform[5] = this.projection.y * -2;
if(position)
{
displayObject.worldTransform[2] = position.x;
displayObject.worldTransform[5] -= position.y;
}
PIXI.visibleCount++;
displayObject.vcount = PIXI.visibleCount;
for(var i=0,j=children.length; i<j; i++)
{
children[i].updateTransform();
}
if (position)
{
displayObject.worldTransform[2] = position.x;
displayObject.worldTransform[5] -= position.y;
}
PIXI.visibleCount++;
displayObject.vcount = PIXI.visibleCount;
for (var i = 0, j = children.length; i < j; i++)
{
children[i].updateTransform();
}
var renderGroup = displayObject.__renderGroup;
var renderGroup = displayObject.__renderGroup;
if(renderGroup)
{
if(displayObject == renderGroup.root)
{
renderGroup.render(this.projection, this.glFramebuffer);
}
else
{
renderGroup.renderSpecific(displayObject, this.projection, this.glFramebuffer);
}
}
else
{
if(!this.renderGroup)this.renderGroup = new PIXI.WebGLRenderGroup(gl);
this.renderGroup.setRenderable(displayObject);
this.renderGroup.render(this.projection, this.glFramebuffer);
}
displayObject.worldTransform = originalWorldTransform;
if (renderGroup)
{
if (displayObject == renderGroup.root)
{
renderGroup.render(this.projection, this.glFramebuffer);
}
else
{
renderGroup.renderSpecific(displayObject, this.projection, this.glFramebuffer);
}
}
else
{
if (!this.renderGroup)
{
this.renderGroup = new PIXI.WebGLRenderGroup(gl);
}
this.renderGroup.setRenderable(displayObject);
this.renderGroup.render(this.projection, this.glFramebuffer);
}
displayObject.worldTransform = originalWorldTransform;
}
/**
* 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)
{
var children = displayObject.children;
var children = displayObject.children;
displayObject.worldTransform = PIXI.mat3.create();
if(position)
{
displayObject.worldTransform[2] = position.x;
displayObject.worldTransform[5] = position.y;
}
displayObject.worldTransform = PIXI.mat3.create();
if (position)
{
displayObject.worldTransform[2] = position.x;
displayObject.worldTransform[5] = position.y;
}
for(var i=0,j=children.length; i<j; i++)
{
children[i].updateTransform();
}
for (var i = 0, j = children.length; i < j; i++)
{
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.context.setTransform(1,0,0,1,0,0);
this.renderer.context.setTransform(1, 0, 0, 1, 0, 0);
// PIXI.texturesToUpdate.push(this.baseTexture);
}

View file

@ -26,51 +26,51 @@ Phaser.Sprite = function (game, x, y, key, frame) {
frame = frame || null;
/**
* @property {Phaser.Game} game - A reference to the currently running Game.
*/
this.game = game;
* @property {Phaser.Game} game - A reference to the currently running Game.
*/
this.game = game;
/**
* @property {boolean} exists - If exists = false then the Sprite isn't updated by the core game loop or physics subsystem at all.
* @default
*/
/**
* @property {boolean} exists - If exists = false then the Sprite isn't updated by the core game loop or physics subsystem at all.
* @default
*/
this.exists = true;
/**
/**
* @property {boolean} alive - This is a handy little var your game can use to determine if a sprite is alive or not, it doesn't effect rendering.
* @default
*/
* @default
*/
this.alive = true;
/**
/**
* @property {Phaser.Group} group - The parent Group of this Sprite. This is usually set after Sprite instantiation by the parent.
*/
*/
this.group = null;
/**
* @property {string} name - The user defined name given to this Sprite.
* @default
*/
* @property {string} name - The user defined name given to this Sprite.
* @default
*/
this.name = '';
/**
* @property {number} type - The const type of this object.
* @default
*/
* @property {number} type - The const type of this object.
* @readonly
*/
this.type = Phaser.SPRITE;
/**
* @property {number} renderOrderID - Used by the Renderer and Input Manager to control picking order.
* @default
*/
* @property {number} renderOrderID - Used by the Renderer and Input Manager to control picking order.
* @default
*/
this.renderOrderID = -1;
/**
* If you would like the Sprite to have a lifespan once 'born' you can set this to a positive value. Handy for particles, bullets, etc.
* The lifespan is decremented by game.time.elapsed each update, once it reaches zero the kill() function is called.
* @property {number} lifespan - The lifespan of the Sprite (in ms) before it will be killed.
* @default
*/
* 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.
* @default
*/
this.lifespan = 0;
/**
@ -123,7 +123,7 @@ Phaser.Sprite = function (game, x, y, key, frame) {
key = '__default';
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';
this.key = key;
@ -179,8 +179,8 @@ Phaser.Sprite = function (game, x, y, key, frame) {
*/
this.y = y;
this.position.x = x;
this.position.y = y;
this.position.x = x;
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.
@ -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.
*/
*/
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
*/
this._cache = {
this._cache = {
dirty: false,
// 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
i01: -1, i10: -1, idi: -1,
i01: -1,
i10: -1,
idi: -1,
// Bounds check
left: null, right: null, top: null, bottom: null,
left: null,
right: null,
top: null,
bottom: null,
// delta cache
prevX: x, prevY: y,
prevX: x,
prevY: y,
// The previous calculated position
x: -1, y: -1,
x: -1,
y: -1,
// The actual scale values based on the worldTransform
scaleX: 1, scaleY: 1,
scaleX: 1,
scaleY: 1,
// 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
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
calcWidth: -1, calcHeight: -1,
calcWidth: -1,
calcHeight: -1,
// The current frame details
// 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)
cameraVisible: true,
// 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.
*/
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.
@ -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.
*/
*/
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.
*/
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.
@ -537,7 +559,7 @@ Phaser.Sprite.prototype.updateBounds = function() {
this.updateFrame = true;
if (this.inWorld == false)
if (this.inWorld === false)
{
// Sprite WAS out of the screen, is it still?
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?
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._outOfBoundsFired = true;
@ -1079,7 +1101,7 @@ Object.defineProperty(Phaser.Sprite.prototype, "inputEnabled", {
if (value)
{
if (this.input.enabled == false)
if (this.input.enabled === false)
{
this.input.start();
}

View file

@ -21,81 +21,99 @@ Phaser.Text = function (game, x, y, text, style) {
text = text || '';
style = style || '';
// If exists = false then the Sprite isn't updated by the core game loop or physics subsystem at all
/**
* @property {boolean} exists - Description.
* @default
*/
/**
* @property {Phaser.Game} game - A reference to the currently running 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.
* @default
*/
this.exists = true;
// This is a handy little var your game can use to determine if a sprite is alive or not, it doesn't effect rendering
/**
* @property {boolean} alive - Description.
* @default
*/
/**
* @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
*/
this.alive = true;
/**
* @property {Description} group - Description.
* @default
*/
/**
* @property {Phaser.Group} group - The parent Group of this Sprite. This is usually set after Sprite instantiation by the parent.
*/
this.group = null;
/**
* @property {string} name - Description.
* @default
*/
/**
* @property {string} name - The user defined name given to this Sprite.
* @default
*/
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;
/**
* @property {string} _style - Internal value.
* @private
*/
this._style = style;
PIXI.Text.call(this, text, style);
/**
* @property {Description} type - Description.
*/
this.type = Phaser.TEXT;
/**
* @property {Description} position - Description.
* @property {Phaser.Point} position - The position of this Text object in world space.
*/
this.position.x = this.x = x;
this.position.y = this.y = y;
// Replaces the PIXI.Point with a slightly more flexible one
/**
* @property {Phaser.Point} anchor - Description.
*/
* 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();
/**
* @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);
// 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
*/
this._cache = {
this._cache = {
dirty: false,
// Transform cache
a00: 1, a01: 0, a02: x, a10: 0, a11: 1, a12: y, id: 1,
a00: 1,
a01: 0,
a02: x,
a10: 0,
a11: 1,
a12: y,
id: 1,
// The previous calculated position
x: -1, y: -1,
x: -1,
y: -1,
// The actual scale values based on the worldTransform
scaleX: 1, scaleY: 1
scaleX: 1,
scaleY: 1
};
@ -103,7 +121,7 @@ Phaser.Text = function (game, x, y, text, style) {
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;

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
* @extends Phaser.Sprite
* @constructor
* @param {Phaser.Game} game - Current game instance.
* @param {number} x - X position of the new tileSprite.
@ -25,33 +26,33 @@ Phaser.TileSprite = function (game, x, y, width, height, key, frame) {
key = key || null;
frame = frame || null;
Phaser.Sprite.call(this, game, x, y, key, frame);
Phaser.Sprite.call(this, game, x, y, key, frame);
/**
* @property {Description} texture - Description.
/**
* @property {PIXI.Texture} texture - The texture that the sprite renders with.
*/
this.texture = PIXI.TextureCache[key];
PIXI.TilingSprite.call(this, this.texture, width, height);
PIXI.TilingSprite.call(this, this.texture, width, height);
/**
* @property {Description} type - Description.
/**
* @property {number} type - The const type of this object.
* @readonly
*/
this.type = Phaser.TILESPRITE;
this.type = Phaser.TILESPRITE;
/**
* @property {Point} tileScale - The scaling of the image that is being tiled.
*/
this.tileScale = new Phaser.Point(1, 1);
/**
* @property {Phaser.Point} tileScale - The scaling of the image that is being tiled.
*/
this.tileScale = new Phaser.Point(1, 1);
/**
* @property {Point} tilePosition - The offset position of the image that is being tiled.
*/
this.tilePosition = new Phaser.Point(0, 0);
/**
* @property {Phaser.Point} tilePosition - The offset position of the image that is being tiled.
*/
this.tilePosition = new Phaser.Point(0, 0);
};
Phaser.TileSprite.prototype = Phaser.Utils.extend(true, PIXI.TilingSprite.prototype, Phaser.Sprite.prototype);
Phaser.TileSprite.prototype.constructor = Phaser.TileSprite;
// Add our own custom methods

View file

@ -13,7 +13,7 @@
* @param {number} [y] The y coordinate of the center of the circle.
* @param {number} [diameter] The diameter of the circle.
* @return {Phaser.Circle} This circle object
**/
*/
Phaser.Circle = function (x, y, diameter) {
x = x || 0;
@ -22,26 +22,26 @@ Phaser.Circle = function (x, y, diameter) {
/**
* @property {number} x - The x coordinate of the center of the circle.
**/
*/
this.x = x;
/**
* @property {number} y - The y coordinate of the center of the circle.
**/
*/
this.y = y;
/**
* @property {number} _diameter - The diameter of the circle.
* @private
**/
*/
this._diameter = diameter;
if (diameter > 0)
{
/**
* @property {number} _radius - The radius of the circle.
* @private
**/
/**
* @property {number} _radius - The radius of the circle.
* @private
*/
this._radius = diameter * 0.5;
}
else
@ -57,7 +57,7 @@ Phaser.Circle.prototype = {
* The circumference of the circle.
* @method Phaser.Circle#circumference
* @return {number}
**/
*/
circumference: function () {
return 2 * (Math.PI * this._radius);
},
@ -69,7 +69,7 @@ Phaser.Circle.prototype = {
* @param {number} y - The y coordinate of the center of the circle.
* @param {number} diameter - The diameter of the circle in pixels.
* @return {Circle} This circle object.
**/
*/
setTo: function (x, y, diameter) {
this.x = x;
this.y = y;
@ -83,7 +83,7 @@ Phaser.Circle.prototype = {
* @method Phaser.Circle#copyFrom
* @param {any} source - The object to copy from.
* @return {Circle} This Circle object.
**/
*/
copyFrom: function (source) {
return this.setTo(source.x, source.y, source.diameter);
},
@ -93,11 +93,11 @@ Phaser.Circle.prototype = {
* @method Phaser.Circle#copyTo
* @param {any} dest - The object to copy to.
* @return {Object} This dest object.
**/
*/
copyTo: function(dest) {
dest[x] = this.x;
dest[y] = this.y;
dest[diameter] = this._diameter;
dest.x = this.x;
dest.y = this.y;
dest.diameter = this._diameter;
return dest;
},
@ -134,7 +134,7 @@ Phaser.Circle.prototype = {
if (typeof out === "undefined") { out = new Phaser.Circle(); }
return out.setTo(a.x, a.y, a.diameter);
return out.setTo(this.x, this.y, this.diameter);
},
@ -167,7 +167,7 @@ Phaser.Circle.prototype = {
* @param {number} dx - Moves the x value of the Circle object by this amount.
* @param {number} dy - Moves the y value of the Circle object by this amount.
* @return {Circle} This Circle object.
**/
*/
offset: function (dx, dy) {
this.x += dx;
this.y += dy;
@ -179,7 +179,7 @@ Phaser.Circle.prototype = {
* @method Phaser.Circle#offsetPoint
* @param {Point} point A Point object to use to offset this Circle object (or any valid object with exposed x and y properties).
* @return {Circle} This Circle object.
**/
*/
offsetPoint: function (point) {
return this.offset(point.x, point.y);
},
@ -188,7 +188,7 @@ Phaser.Circle.prototype = {
* Returns a string representation of this object.
* @method Phaser.Circle#toString
* @return {string} a string representation of the instance.
**/
*/
toString: function () {
return "[{Phaser.Circle (x=" + this.x + " y=" + this.y + " diameter=" + this.diameter + " radius=" + this.radius + ")}]";
}
@ -351,11 +351,16 @@ Object.defineProperty(Phaser.Circle.prototype, "area", {
Object.defineProperty(Phaser.Circle.prototype, "empty", {
get: function () {
return (this._diameter == 0);
return (this._diameter === 0);
},
set: function (value) {
this.setTo(0, 0, 0);
if (value === true)
{
this.setTo(0, 0, 0);
}
}
});

View file

@ -11,20 +11,20 @@
* @constructor
* @param {number} x The horizontal position of this Point (default 0)
* @param {number} y The vertical position of this Point (default 0)
**/
*/
Phaser.Point = function (x, y) {
x = x || 0;
y = y || 0;
/**
* @property {number} x - The x coordinate of the point.
**/
* @property {number} x - The x coordinate of the point.
*/
this.x = x;
/**
* @property {number} y - The y coordinate of the point.
**/
* @property {number} y - The y coordinate of the point.
*/
this.y = y;
};
@ -36,7 +36,7 @@ Phaser.Point.prototype = {
* @method Phaser.Point#copyFrom
* @param {any} source - The object to copy from.
* @return {Point} This Point object.
**/
*/
copyFrom: function (source) {
return this.setTo(source.x, source.y);
},
@ -45,7 +45,7 @@ Phaser.Point.prototype = {
* Inverts the x and y values of this Point
* @method Phaser.Point#invert
* @return {Point} This Point object.
**/
*/
invert: function () {
return this.setTo(this.y, this.x);
},
@ -56,7 +56,7 @@ Phaser.Point.prototype = {
* @param {number} x - The horizontal position of this point.
* @param {number} y - The vertical position of this point.
* @return {Point} This Point object. Useful for chaining method calls.
**/
*/
setTo: function (x, y) {
this.x = x;
@ -71,7 +71,7 @@ Phaser.Point.prototype = {
* @param {number} x - The value to add to Point.x.
* @param {number} y - The value to add to Point.y.
* @return {Phaser.Point} This Point object. Useful for chaining method calls.
**/
*/
add: function (x, y) {
this.x += x;
@ -86,7 +86,7 @@ Phaser.Point.prototype = {
* @param {number} x - The value to subtract from Point.x.
* @param {number} y - The value to subtract from Point.y.
* @return {Phaser.Point} This Point object. Useful for chaining method calls.
**/
*/
subtract: function (x, y) {
this.x -= x;
@ -101,7 +101,7 @@ Phaser.Point.prototype = {
* @param {number} x - The value to multiply Point.x by.
* @param {number} y - The value to multiply Point.x by.
* @return {Phaser.Point} This Point object. Useful for chaining method calls.
**/
*/
multiply: function (x, y) {
this.x *= x;
@ -116,7 +116,7 @@ Phaser.Point.prototype = {
* @param {number} x - The value to divide Point.x by.
* @param {number} y - The value to divide Point.x by.
* @return {Phaser.Point} This Point object. Useful for chaining method calls.
**/
*/
divide: function (x, y) {
this.x /= x;
@ -176,32 +176,22 @@ Phaser.Point.prototype = {
*/
clone: function (output) {
if (typeof output === "undefined") { output = new Phaser.Point; }
if (typeof output === "undefined") { output = new Phaser.Point(); }
return output.setTo(this.x, this.y);
},
/**
* Copies the x and y properties from any given object to this Point.
* @method Phaser.Point#copyFrom
* @param {any} source - The object to copy from.
* @return {Point} This Point object.
**/
copyFrom: function (source) {
return this.setTo(source.x, source.y);
},
/**
* Copies the x and y properties from this Point to any given object.
* @method Phaser.Point#copyTo
* @param {any} dest - The object to copy to.
* @return {Object} The dest object.
**/
*/
copyTo: function(dest) {
dest[x] = this.x;
dest[y] = this.y;
dest.x = this.x;
dest.y = this.y;
return dest;
@ -291,7 +281,7 @@ Phaser.Point.prototype = {
* Returns a string representation of this object.
* @method Phaser.Point#toString
* @return {string} A string representation of the instance.
**/
*/
toString: function () {
return '[{Point (x=' + this.x + ' y=' + this.y + ')}]';
}
@ -406,7 +396,7 @@ Phaser.Point.distance = function (a, b, round) {
return Phaser.Math.distance(a.x, a.y, b.x, b.y);
}
},
};
/**
* Rotates a Point around the x/y coordinates given to the desired angle.

View file

@ -20,8 +20,8 @@ Phaser.Polygon = function (points) {
PIXI.Polygon.call(this, points);
/**
* @property {number} type - The base object type.
*/
* @property {number} type - The base object type.
*/
this.type = Phaser.POLYGON;
};

View file

@ -11,10 +11,10 @@
* @constructor
* @param {number} x - The x coordinate of the top-left corner of the Rectangle.
* @param {number} y - The y coordinate of the top-left corner of the Rectangle.
* @param {number} width - The width of the Rectangle in pixels.
* @param {number} height - The height of the Rectangle in pixels.
* @param {number} width - The width of the Rectangle.
* @param {number} height - The height of the Rectangle.
* @return {Rectangle} This Rectangle object.
**/
*/
Phaser.Rectangle = function (x, y, width, height) {
x = x || 0;
@ -23,22 +23,22 @@ Phaser.Rectangle = function (x, y, width, height) {
height = height || 0;
/**
* @property {number} x - Description.
* @property {number} x - The x coordinate of the top-left corner of the Rectangle.
*/
this.x = x;
/**
* @property {number} y - Description.
* @property {number} y - The y coordinate of the top-left corner of the Rectangle.
*/
this.y = y;
/**
* @property {number} width - Description.
* @property {number} width - The width of the Rectangle.
*/
this.width = width;
/**
* @property {number} height - Description.
* @property {number} height - The height of the Rectangle.
*/
this.height = height;
@ -52,7 +52,7 @@ Phaser.Rectangle.prototype = {
* @param {number} dx - Moves the x value of the Rectangle object by this amount.
* @param {number} dy - Moves the y value of the Rectangle object by this amount.
* @return {Rectangle} This Rectangle object.
**/
*/
offset: function (dx, dy) {
this.x += dx;
@ -67,7 +67,7 @@ Phaser.Rectangle.prototype = {
* @method Phaser.Rectangle#offsetPoint
* @param {Point} point - A Point object to use to offset this Rectangle object.
* @return {Rectangle} This Rectangle object.
**/
*/
offsetPoint: function (point) {
return this.offset(point.x, point.y);
},
@ -80,7 +80,7 @@ Phaser.Rectangle.prototype = {
* @param {number} width - The width of the Rectangle in pixels.
* @param {number} height - The height of the Rectangle in pixels.
* @return {Rectangle} This Rectangle object
**/
*/
setTo: function (x, y, width, height) {
this.x = x;
@ -95,7 +95,7 @@ Phaser.Rectangle.prototype = {
/**
* Runs Math.floor() on both the x and y values of this Rectangle.
* @method Phaser.Rectangle#floor
**/
*/
floor: function () {
this.x = Math.floor(this.x);
@ -106,7 +106,7 @@ Phaser.Rectangle.prototype = {
/**
* Runs Math.floor() on the x, y, width and height values of this Rectangle.
* @method Phaser.Rectangle#floorAll
**/
*/
floorAll: function () {
this.x = Math.floor(this.x);
@ -121,7 +121,7 @@ Phaser.Rectangle.prototype = {
* @method Phaser.Rectangle#copyFrom
* @param {any} source - The object to copy from.
* @return {Rectangle} This Rectangle object.
**/
*/
copyFrom: function (source) {
return this.setTo(source.x, source.y, source.width, source.height);
},
@ -131,7 +131,7 @@ Phaser.Rectangle.prototype = {
* @method Phaser.Rectangle#copyTo
* @param {any} source - The object to copy to.
* @return {object} This object.
**/
*/
copyTo: function (dest) {
dest.x = this.x;
@ -215,7 +215,7 @@ Phaser.Rectangle.prototype = {
* @return {Phaser.Rectangle} A Rectangle object that equals the area of intersection. If the Rectangles do not intersect, this method returns an empty Rectangle object; that is, a Rectangle with its x, y, width, and height properties set to 0.
*/
intersection: function (b, out) {
return Phaser.Rectangle.intersection(this, b, output);
return Phaser.Rectangle.intersection(this, b, out);
},
/**
@ -259,7 +259,7 @@ Phaser.Rectangle.prototype = {
* Returns a string representation of this object.
* @method Phaser.Rectangle#toString
* @return {string} A string representation of the instance.
**/
*/
toString: function () {
return "[{Rectangle (x=" + this.x + " y=" + this.y + " width=" + this.width + " height=" + this.height + " empty=" + this.empty + ")}]";
}
@ -490,7 +490,12 @@ Object.defineProperty(Phaser.Rectangle.prototype, "empty", {
},
set: function (value) {
this.setTo(0, 0, 0, 0);
if (value === true)
{
this.setTo(0, 0, 0, 0);
}
}
});
@ -615,7 +620,7 @@ Phaser.Rectangle.equals = function (a, b) {
*/
Phaser.Rectangle.intersection = function (a, b, out) {
out = out || new Phaser.Rectangle;
out = out || new Phaser.Rectangle();
if (Phaser.Rectangle.intersects(a, b))
{

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
* @classdesc A game specific Input manager that looks after the mouse, keyboard and touch objects.
* This is updated by the core game loop.
* @constructor
* @param {Phaser.Game} game - Current game instance.
*/
Phaser.Input = function (game) {
/**
* @property {Phaser.Game} game - A reference to the currently running game.
*/
this.game = game;
/**
* @property {Phaser.Game} game - A reference to the currently running game.
*/
this.game = game;
/**
* @property {Description} hitCanvas - Description.
/**
* @property {HTMLCanvasElement} hitCanvas - The canvas to which single pixels are drawn in order to perform pixel-perfect hit detection.
* @default
*/
*/
this.hitCanvas = null;
/**
* @property {Description} hitContext - Description.
* @default
*/
/**
* @property {CanvasRenderingContext2D} hitContext - The context of the pixel perfect hit canvas.
* @default
*/
this.hitContext = null;
};
/**
@ -53,11 +53,6 @@ Phaser.Input.MOUSE_TOUCH_COMBINE = 2;
Phaser.Input.prototype = {
/**
* @property {Phaser.Game} game
*/
game: null,
/**
* How often should the input pointers be checked for updates?
* A value of 0 means every single frame (60fps), a value of 1 means every other frame (30fps) and so on.
@ -67,31 +62,28 @@ Phaser.Input.prototype = {
pollRate: 0,
/**
* @property {number} _pollCounter - Description.
* @property {number} _pollCounter - Internal var holding the current poll counter.
* @private
* @default
*/
_pollCounter: 0,
/**
* A vector object representing the previous position of the Pointer.
* @property {Vec2} vector
* @property {Phaser.Point} _oldPosition - A point object representing the previous position of the Pointer.
* @private
* @default
*/
_oldPosition: null,
/**
* X coordinate of the most recent Pointer event
* @property {number} _x
* @property {number} _x - x coordinate of the most recent Pointer event
* @private
* @default
*/
_x: 0,
/**
* Y coordinate of the most recent Pointer event
* @property {number} _y
* @property {number} _y - Y coordinate of the most recent Pointer event
* @private
* @default
*/
@ -112,17 +104,14 @@ Phaser.Input.prototype = {
multiInputOverride: Phaser.Input.MOUSE_TOUCH_COMBINE,
/**
* A vector object representing the current position of the Pointer.
* @property {Phaser.Point} position
* @property {Phaser.Point} position - A point object representing the current position of the Pointer.
* @default
*/
position: null,
/**
* A vector object representing the speed of the Pointer. Only really useful in single Pointer games,
* otherwise see the Pointer objects directly.
* A point object representing the speed of the Pointer. Only really useful in single Pointer games, otherwise see the Pointer objects directly.
* @property {Phaser.Point} speed
* @default
*/
speed: null,
@ -130,7 +119,6 @@ Phaser.Input.prototype = {
* A Circle object centered on the x/y screen coordinates of the Input.
* Default size of 44px (Apples recommended "finger tip" size) but can be changed to anything.
* @property {Phaser.Circle} circle
* @default
*/
circle: null,
@ -138,7 +126,6 @@ Phaser.Input.prototype = {
* The scale by which all input coordinates are multiplied, calculated by the StageScaleMode.
* In an un-scaled game the values will be x: 1 and y: 1.
* @property {Phaser.Point} scale
* @default
*/
scale: null,
@ -267,7 +254,7 @@ Phaser.Input.prototype = {
/**
* A Pointer object
* @property {Phaser.Pointer} pointer9
*/
*/
pointer9: null,
/**
@ -353,40 +340,40 @@ Phaser.Input.prototype = {
*/
interactiveItems: new Phaser.LinkedList(),
/**
/**
* Starts the Input Manager running.
* @method Phaser.Input#boot
* @protected
*/
boot: function () {
this.mousePointer = new Phaser.Pointer(this.game, 0);
this.pointer1 = new Phaser.Pointer(this.game, 1);
this.pointer2 = new Phaser.Pointer(this.game, 2);
this.mousePointer = new Phaser.Pointer(this.game, 0);
this.pointer1 = new Phaser.Pointer(this.game, 1);
this.pointer2 = new Phaser.Pointer(this.game, 2);
this.mouse = new Phaser.Mouse(this.game);
this.keyboard = new Phaser.Keyboard(this.game);
this.touch = new Phaser.Touch(this.game);
this.mspointer = new Phaser.MSPointer(this.game);
this.mouse = new Phaser.Mouse(this.game);
this.keyboard = new Phaser.Keyboard(this.game);
this.touch = new Phaser.Touch(this.game);
this.mspointer = new Phaser.MSPointer(this.game);
this.onDown = new Phaser.Signal();
this.onUp = new Phaser.Signal();
this.onTap = new Phaser.Signal();
this.onHold = new Phaser.Signal();
this.onDown = new Phaser.Signal();
this.onUp = new Phaser.Signal();
this.onTap = new Phaser.Signal();
this.onHold = new Phaser.Signal();
this.scale = new Phaser.Point(1, 1);
this.speed = new Phaser.Point();
this.position = new Phaser.Point();
this._oldPosition = new Phaser.Point();
this.scale = new Phaser.Point(1, 1);
this.speed = new Phaser.Point();
this.position = new Phaser.Point();
this._oldPosition = new Phaser.Point();
this.circle = new Phaser.Circle(0, 0, 44);
this.circle = new Phaser.Circle(0, 0, 44);
this.activePointer = this.mousePointer;
this.currentPointers = 0;
this.activePointer = this.mousePointer;
this.currentPointers = 0;
this.hitCanvas = document.createElement('canvas');
this.hitCanvas.width = 1;
this.hitCanvas.height = 1;
this.hitCanvas = document.createElement('canvas');
this.hitCanvas.width = 1;
this.hitCanvas.height = 1;
this.hitContext = this.hitCanvas.getContext('2d');
this.mouse.start();
@ -410,7 +397,7 @@ Phaser.Input.prototype = {
},
/**
/**
* Add a new Pointer object to the Input Manager. By default Input creates 3 pointer objects: mousePointer, pointer1 and pointer2.
* If you need more then use this to create a new one, up to a maximum of 10.
* @method Phaser.Input#addPointer
@ -428,7 +415,7 @@ Phaser.Input.prototype = {
}
}
if (next == 0)
if (next === 0)
{
console.warn("You can only have 10 Pointer objects");
return null;
@ -441,7 +428,7 @@ Phaser.Input.prototype = {
},
/**
/**
* Updates the Input Manager. Called by the core Game loop.
* @method Phaser.Input#update
* @protected
@ -475,14 +462,14 @@ Phaser.Input.prototype = {
this._pollCounter = 0;
},
/**
/**
* Reset all of the Pointers and Input states
* @method Phaser.Input#reset
* @param {boolean} hard - A soft reset (hard = false) won't reset any Signals that might be bound. A hard reset will.
*/
reset: function (hard) {
if (this.game.isBooted == false)
if (this.game.isBooted === false)
{
return;
}
@ -503,7 +490,7 @@ Phaser.Input.prototype = {
this.currentPointers = 0;
this.game.stage.canvas.style.cursor = "default";
if (hard == true)
if (hard === true)
{
this.onDown.dispose();
this.onUp.dispose();
@ -534,7 +521,7 @@ Phaser.Input.prototype = {
},
/**
/**
* Find the first free Pointer object and start it, passing in the event data. This is called automatically by Phaser.Touch and Phaser.MSPointer.
* @method Phaser.Input#startPointer
* @param {Any} event - The event data from the Touch event.
@ -547,11 +534,11 @@ Phaser.Input.prototype = {
return null;
}
if (this.pointer1.active == false)
if (this.pointer1.active === false)
{
return this.pointer1.start(event);
}
else if (this.pointer2.active == false)
else if (this.pointer2.active === false)
{
return this.pointer2.start(event);
}
@ -559,7 +546,7 @@ Phaser.Input.prototype = {
{
for (var i = 3; i <= 10; i++)
{
if (this['pointer' + i] && this['pointer' + i].active == false)
if (this['pointer' + i] && this['pointer' + i].active === false)
{
return this['pointer' + i].start(event);
}
@ -570,7 +557,7 @@ Phaser.Input.prototype = {
},
/**
/**
* Updates the matching Pointer object, passing in the event data. This is called automatically and should not normally need to be invoked.
* @method Phaser.Input#updatePointer
* @param {Any} event - The event data from the Touch event.
@ -601,7 +588,7 @@ Phaser.Input.prototype = {
},
/**
/**
* Stops the matching Pointer object, passing in the event data.
* @method Phaser.Input#stopPointer
* @param {Any} event - The event data from the Touch event.
@ -632,7 +619,7 @@ Phaser.Input.prototype = {
},
/**
/**
* Get the next Pointer object whos active property matches the given state
* @method Phaser.Input#getPointer
* @param {boolean} state - The state the Pointer should be in (false for inactive, true for active).
@ -665,7 +652,7 @@ Phaser.Input.prototype = {
},
/**
/**
* Get the Pointer object whos identified property matches the given identifier value.
* @method Phaser.Input#getPointerFromIdentifier
* @param {number} identifier - The Pointer.identifier value to search for.
@ -793,7 +780,7 @@ Object.defineProperty(Phaser.Input.prototype, "totalActivePointers", {
Object.defineProperty(Phaser.Input.prototype, "worldX", {
get: function () {
return this.game.camera.view.x + this.x;
return this.game.camera.view.x + this.x;
}
});
@ -806,7 +793,7 @@ Object.defineProperty(Phaser.Input.prototype, "worldX", {
Object.defineProperty(Phaser.Input.prototype, "worldY", {
get: function () {
return this.game.camera.view.y + this.y;
return this.game.camera.view.y + this.y;
}
});

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
* @classdesc Description.
* @constructor
* @param {Phaser.Sprite} game - Description.
* @param {Phaser.Sprite} sprite - The Sprite object to which this Input Handler belongs.
*/
Phaser.InputHandler = function (sprite) {
/**
* @property {Phaser.Sprite} sprite - Description.
*/
this.sprite = sprite;
/**
* @property {Phaser.Sprite} sprite - The Sprite object to which this Input Handler belongs.
*/
this.sprite = sprite;
/**
* @property {Phaser.Game} game - A reference to the currently running game.
*/
this.game = sprite.game;
/**
* @property {boolean} enabled - Description.
* @default
*/
/**
* @property {boolean} enabled - If enabled the Input Handler will process input requests and monitor pointer activity.
* @default
*/
this.enabled = false;
// Linked list references
/**
* @property {Description} parent - Description.
* @default
*/
this.parent = null;
/**
* @property {Description} parent - Description.
* @default
*/
// this.parent = null;
/**
* @property {Description} next - Description.
* @default
*/
this.next = null;
/**
* @property {Description} next - Linked List
* @default
*/
// this.next = null;
/**
* @property {Description} prev - Description.
* @default
*/
this.prev = null;
/**
* @property {Description} prev - Description.
* @default
*/
// this.prev = null;
/**
* @property {Description} last - Description.
* @default
*/
this.last = this;
/**
* @property {Description} first - Description.
* @default
*/
this.first = this;
/**
* @property {Description} last - Description.
* @default
*/
// this.last = this;
/**
* @property {Description} first - Description.
* @default
*/
// this.first = this;
/**
* @property {number} priorityID - The PriorityID controls which Sprite receives an Input event first if they should overlap.
* @default
*/
/**
* @property {number} priorityID - The PriorityID controls which Sprite receives an Input event first if they should overlap.
* @default
*/
this.priorityID = 0;
/**
* @property {boolean} useHandCursor - Description.
* @default
*/
/**
* @property {boolean} useHandCursor - On a desktop browser you can set the 'hand' cursor to appear when moving over the Sprite.
* @default
*/
this.useHandCursor = false;
/**
* @property {boolean} isDragged - Description.
* @default
*/
/**
* @property {boolean} isDragged - true if the Sprite is being currently dragged.
* @default
*/
this.isDragged = false;
/**
* @property {boolean} allowHorizontalDrag - Description.
* @default
*/
/**
* @property {boolean} allowHorizontalDrag - Controls if the Sprite is allowed to be dragged horizontally.
* @default
*/
this.allowHorizontalDrag = true;
/**
* @property {boolean} allowVerticalDrag - Description.
* @default
*/
/**
* @property {boolean} allowVerticalDrag - Controls if the Sprite is allowed to be dragged vertically.
* @default
*/
this.allowVerticalDrag = true;
/**
* @property {boolean} bringToTop - Description.
* @default
*/
/**
* @property {boolean} bringToTop - If true when this Sprite is clicked or dragged it will automatically be bought to the top of the Group it is within.
* @default
*/
this.bringToTop = false;
/**
* @property {Description} snapOffset - Description.
* @default
*/
/**
* @property {Phaser.Point} snapOffset - A Point object that contains by how far the Sprite snap is offset.
* @default
*/
this.snapOffset = null;
/**
* @property {boolean} snapOnDrag - Description.
* @default
*/
/**
* @property {boolean} snapOnDrag - When the Sprite is dragged this controls if the center of the Sprite will snap to the pointer on drag or not.
* @default
*/
this.snapOnDrag = false;
/**
* @property {boolean} snapOnRelease - Description.
* @default
*/
/**
* @property {boolean} snapOnRelease - When the Sprite is dragged this controls if the Sprite will be snapped on release.
* @default
*/
this.snapOnRelease = false;
/**
* @property {number} snapX - Description.
* @default
*/
/**
* @property {number} snapX - When a Sprite has snapping enabled this holds the width of the snap grid.
* @default
*/
this.snapX = 0;
/**
* @property {number} snapY - Description.
* @default
*/
/**
* @property {number} snapY - When a Sprite has snapping enabled this holds the height of the snap grid.
* @default
*/
this.snapY = 0;
/**
* @property {number} pixelPerfect - Should we use pixel perfect hit detection? Warning: expensive. Only enable if you really need it!
* @default
*/
/**
* @property {number} pixelPerfect - Should we use pixel perfect hit detection? Warning: expensive. Only enable if you really need it!
* @default
*/
this.pixelPerfect = false;
/**
@ -145,13 +143,13 @@ Phaser.InputHandler = function (sprite) {
this.draggable = false;
/**
* @property {Description} boundsRect - A region of the game world within which the sprite is restricted during drag.
* @property {Phaser.Rectangle} boundsRect - A region of the game world within which the sprite is restricted during drag.
* @default
*/
this.boundsRect = null;
/**
* @property {Description} boundsSprite - A Sprite the bounds of which this sprite is restricted during drag.
* @property {Phaser.Sprite} boundsSprite - A Sprite the bounds of which this sprite is restricted during drag.
* @default
*/
this.boundsSprite = null;
@ -168,7 +166,7 @@ Phaser.InputHandler = function (sprite) {
* @property {Phaser.Point} _tempPoint - Description.
* @private
*/
this._tempPoint = new Phaser.Point;
this._tempPoint = new Phaser.Point();
this._pointerData = [];
@ -192,23 +190,23 @@ Phaser.InputHandler = function (sprite) {
Phaser.InputHandler.prototype = {
/**
* Description.
* @method Phaser.InputHandler#start
* @param {number} priority - Description.
* @param {boolean} useHandCursor - Description.
* @return {Phaser.Sprite} Description.
*/
start: function (priority, useHandCursor) {
/**
* Starts the Input Handler running. This is called automatically when you enable input on a Sprite, or can be called directly if you need to set a specific priority.
* @method Phaser.InputHandler#start
* @param {number} priority - Higher priority sprites take click priority over low-priority sprites when they are stacked on-top of each other.
* @param {boolean} useHandCursor - If true the Sprite will show the hand cursor on mouse-over (doesn't apply to mobile browsers)
* @return {Phaser.Sprite} The Sprite object to which the Input Handler is bound.
*/
start: function (priority, useHandCursor) {
priority = priority || 0;
if (typeof useHandCursor == 'undefined') { useHandCursor = false; }
priority = priority || 0;
if (typeof useHandCursor == 'undefined') { useHandCursor = false; }
// Turning on
if (this.enabled == false)
if (this.enabled === false)
{
// Register, etc
this.game.input.interactiveItems.add(this);
this.game.input.interactiveItems.add(this);
this.useHandCursor = useHandCursor;
this.priorityID = priority;
@ -231,29 +229,29 @@ Phaser.InputHandler.prototype = {
};
}
this.snapOffset = new Phaser.Point;
this.snapOffset = new Phaser.Point();
this.enabled = true;
// Create the signals the Input component will emit
if (this.sprite.events && this.sprite.events.onInputOver == null)
{
this.sprite.events.onInputOver = new Phaser.Signal;
this.sprite.events.onInputOut = new Phaser.Signal;
this.sprite.events.onInputDown = new Phaser.Signal;
this.sprite.events.onInputUp = new Phaser.Signal;
this.sprite.events.onDragStart = new Phaser.Signal;
this.sprite.events.onDragStop = new Phaser.Signal;
this.sprite.events.onInputOver = new Phaser.Signal();
this.sprite.events.onInputOut = new Phaser.Signal();
this.sprite.events.onInputDown = new Phaser.Signal();
this.sprite.events.onInputUp = new Phaser.Signal();
this.sprite.events.onDragStart = new Phaser.Signal();
this.sprite.events.onDragStop = new Phaser.Signal();
}
}
return this.sprite;
},
},
/**
* Description.
* @method Phaser.InputHandler#reset
*/
/**
* Resets the Input Handler and disables it.
* @method Phaser.InputHandler#reset
*/
reset: function () {
this.enabled = false;
@ -278,14 +276,14 @@ Phaser.InputHandler.prototype = {
}
},
/**
* Description.
* @method Phaser.InputHandler#stop
*/
stop: function () {
/**
* Stops the Input Handler from running.
* @method Phaser.InputHandler#stop
*/
stop: function () {
// Turning off
if (this.enabled == false)
if (this.enabled === false)
{
return;
}
@ -293,15 +291,15 @@ Phaser.InputHandler.prototype = {
{
// De-register, etc
this.enabled = false;
this.game.input.interactiveItems.remove(this);
this.game.input.interactiveItems.remove(this);
}
},
},
/**
* Clean up memory.
* @method Phaser.InputHandler#destroy
*/
/**
* Clean up memory.
* @method Phaser.InputHandler#destroy
*/
destroy: function () {
if (this.enabled)
@ -310,99 +308,99 @@ Phaser.InputHandler.prototype = {
this.game.input.interactiveItems.remove(this);
this.stop();
this.stop();
this.sprite = null;
this.sprite = null;
}
},
/**
/**
* The x coordinate of the Input pointer, relative to the top-left of the parent Sprite.
* This value is only set when the pointer is over this Sprite.
* @method Phaser.InputHandler#pointerX
* @param {Pointer} pointer
* @param {Phaser.Pointer} pointer
* @return {number} The x coordinate of the Input pointer.
*/
*/
pointerX: function (pointer) {
pointer = pointer || 0;
pointer = pointer || 0;
return this._pointerData[pointer].x;
},
/**
/**
* The y coordinate of the Input pointer, relative to the top-left of the parent Sprite
* This value is only set when the pointer is over this Sprite.
* @method Phaser.InputHandler#pointerY
* @param {Pointer} pointer
* @param {Phaser.Pointer} pointer
* @return {number} The y coordinate of the Input pointer.
*/
pointerY: function (pointer) {
pointer = pointer || 0;
pointer = pointer || 0;
return this._pointerData[pointer].y;
},
/**
/**
* If the Pointer is touching the touchscreen, or the mouse button is held down, isDown is set to true.
* @method Phaser.InputHandler#pointerDown
* @param {Pointer} pointer
* @param {Phaser.Pointer} pointer
* @return {boolean}
*/
pointerDown: function (pointer) {
pointer = pointer || 0;
pointer = pointer || 0;
return this._pointerData[pointer].isDown;
},
/**
/**
* If the Pointer is not touching the touchscreen, or the mouse button is up, isUp is set to true
* @method Phaser.InputHandler#pointerUp
* @param {Pointer} pointer
* @param {Phaser.Pointer} pointer
* @return {boolean}
*/
pointerUp: function (pointer) {
pointer = pointer || 0;
pointer = pointer || 0;
return this._pointerData[pointer].isUp;
},
/**
/**
* A timestamp representing when the Pointer first touched the touchscreen.
* @method Phaser.InputHandler#pointerTimeDown
* @param {Pointer} pointer
* @param {Phaser.Pointer} pointer
* @return {number}
*/
pointerTimeDown: function (pointer) {
pointer = pointer || 0;
pointer = pointer || 0;
return this._pointerData[pointer].timeDown;
},
/**
/**
* A timestamp representing when the Pointer left the touchscreen.
* @method Phaser.InputHandler#pointerTimeUp
* @param {Pointer} pointer
* @param {Phaser.Pointer} pointer
* @return {number}
*/
pointerTimeUp: function (pointer) {
pointer = pointer || 0;
pointer = pointer || 0;
return this._pointerData[pointer].timeUp;
},
/**
/**
* Is the Pointer over this Sprite?
* @method Phaser.InputHandler#pointerOver
* @param {number} [index] - The ID number of a Pointer to check. If you don't provide a number it will check all Pointers.
@ -432,13 +430,13 @@ Phaser.InputHandler.prototype = {
},
/**
/**
* Is the Pointer outside of this Sprite?
* @method Phaser.InputHandler#pointerOut
* @param {number} [index] - The ID number of a Pointer to check. If you don't provide a number it will check all Pointers.
* @return {boolean} True if the given pointer (if a index was given, or any pointer if not) is out of this object.
*/
pointerOut: function (pointer) {
pointerOut: function (index) {
if (this.enabled)
{
@ -462,52 +460,52 @@ Phaser.InputHandler.prototype = {
},
/**
/**
* A timestamp representing when the Pointer first touched the touchscreen.
* @method Phaser.InputHandler#pointerTimeOver
* @param {Pointer} pointer
* @param {Phaser.Pointer} pointer
* @return {number}
*/
pointerTimeOver: function (pointer) {
pointer = pointer || 0;
pointer = pointer || 0;
return this._pointerData[pointer].timeOver;
},
/**
/**
* A timestamp representing when the Pointer left the touchscreen.
* @method Phaser.InputHandler#pointerTimeOut
* @param {Pointer} pointer
* @param {Phaser.Pointer} pointer
* @return {number}
*/
pointerTimeOut: function (pointer) {
pointer = pointer || 0;
pointer = pointer || 0;
return this._pointerData[pointer].timeOut;
},
/**
/**
* Is this sprite being dragged by the mouse or not?
* @method Phaser.InputHandler#pointerTimeOut
* @param {Pointer} pointer
* @param {Phaser.Pointer} pointer
* @return {number}
*/
pointerDragged: function (pointer) {
pointer = pointer || 0;
pointer = pointer || 0;
return this._pointerData[pointer].isDragged;
},
/**
/**
* Checks if the given pointer is over this Sprite.
* @method Phaser.InputHandler#checkPointerOver
* @param {Pointer} pointer
* @param {Phaser.Pointer} pointer
* @return {boolean}
*/
checkPointerOver: function (pointer) {
@ -533,7 +531,7 @@ Phaser.InputHandler.prototype = {
},
/**
/**
* Runs a pixel perfect check against the given x/y coordinates of the Sprite this InputHandler is bound to.
* It compares the alpha value of the pixel and if >= InputHandler.pixelPerfectAlpha it returns true.
* @method Phaser.InputHandler#checkPixel
@ -565,14 +563,14 @@ Phaser.InputHandler.prototype = {
},
/**
/**
* Update.
* @method Phaser.InputHandler#update
* @param {Pointer} pointer
* @param {Phaser.Pointer} pointer
*/
update: function (pointer) {
if (this.enabled == false || this.sprite.visible == false || (this.sprite.group && this.sprite.group.visible == false))
if (this.enabled === false || this.sprite.visible === false || (this.sprite.group && this.sprite.group.visible === false))
{
this._pointerOutHandler(pointer);
return false;
@ -582,7 +580,7 @@ Phaser.InputHandler.prototype = {
{
return this.updateDrag(pointer);
}
else if (this._pointerData[pointer.id].isOver == true)
else if (this._pointerData[pointer.id].isOver === true)
{
if (this.checkPointerOver(pointer))
{
@ -598,15 +596,15 @@ Phaser.InputHandler.prototype = {
}
},
/**
* Description.
* @method Phaser.InputHandler#_pointerOverHandler
* @private
* @param {Pointer} pointer
*/
/**
* Internal method handling the pointer over event.
* @method Phaser.InputHandler#_pointerOverHandler
* @private
* @param {Phaser.Pointer} pointer
*/
_pointerOverHandler: function (pointer) {
if (this._pointerData[pointer.id].isOver == false)
if (this._pointerData[pointer.id].isOver === false)
{
this._pointerData[pointer.id].isOver = true;
this._pointerData[pointer.id].isOut = false;
@ -614,7 +612,7 @@ Phaser.InputHandler.prototype = {
this._pointerData[pointer.id].x = pointer.x - this.sprite.x;
this._pointerData[pointer.id].y = pointer.y - this.sprite.y;
if (this.useHandCursor && this._pointerData[pointer.id].isDragged == false)
if (this.useHandCursor && this._pointerData[pointer.id].isDragged === false)
{
this.game.stage.canvas.style.cursor = "pointer";
}
@ -623,19 +621,19 @@ Phaser.InputHandler.prototype = {
}
},
/**
* Description.
* @method Phaser.InputHandler#_pointerOutHandler
* @private
* @param {Pointer} pointer
*/
/**
* Internal method handling the pointer out event.
* @method Phaser.InputHandler#_pointerOutHandler
* @private
* @param {Phaser.Pointer} pointer
*/
_pointerOutHandler: function (pointer) {
this._pointerData[pointer.id].isOver = false;
this._pointerData[pointer.id].isOut = true;
this._pointerData[pointer.id].timeOut = this.game.time.now;
if (this.useHandCursor && this._pointerData[pointer.id].isDragged == false)
if (this.useHandCursor && this._pointerData[pointer.id].isDragged === false)
{
this.game.stage.canvas.style.cursor = "default";
}
@ -647,15 +645,15 @@ Phaser.InputHandler.prototype = {
},
/**
* Description.
* @method Phaser.InputHandler#_touchedHandler
* @private
* @param {Pointer} pointer
*/
/**
* Internal method handling the touched event.
* @method Phaser.InputHandler#_touchedHandler
* @private
* @param {Phaser.Pointer} pointer
*/
_touchedHandler: function (pointer) {
if (this._pointerData[pointer.id].isDown == false && this._pointerData[pointer.id].isOver == true)
if (this._pointerData[pointer.id].isDown === false && this._pointerData[pointer.id].isOver === true)
{
this._pointerData[pointer.id].isDown = true;
this._pointerData[pointer.id].isUp = false;
@ -663,7 +661,7 @@ Phaser.InputHandler.prototype = {
this.sprite.events.onInputDown.dispatch(this.sprite, pointer);
// Start drag
if (this.draggable && this.isDragged == false)
if (this.draggable && this.isDragged === false)
{
this.startDrag(pointer);
}
@ -671,7 +669,7 @@ Phaser.InputHandler.prototype = {
if (this.bringToTop)
{
this.sprite.bringToTop();
}
}
}
// Consume the event?
@ -679,12 +677,12 @@ Phaser.InputHandler.prototype = {
},
/**
* Description.
* @method Phaser.InputHandler#_releasedHandler
* @private
* @param {Pointer} pointer
*/
/**
* Internal method handling the pointer released event.
* @method Phaser.InputHandler#_releasedHandler
* @private
* @param {Phaser.Pointer} pointer
*/
_releasedHandler: function (pointer) {
// If was previously touched by this Pointer, check if still is AND still over this item
@ -719,10 +717,10 @@ Phaser.InputHandler.prototype = {
},
/**
/**
* Updates the Pointer drag on this Sprite.
* @method Phaser.InputHandler#updateDrag
* @param {Pointer} pointer
* @param {Phaser.Pointer} pointer
* @return {boolean}
*/
updateDrag: function (pointer) {
@ -763,79 +761,79 @@ Phaser.InputHandler.prototype = {
},
/**
/**
* Returns true if the pointer has entered the Sprite within the specified delay time (defaults to 500ms, half a second)
* @method Phaser.InputHandler#justOver
* @param {Pointer} pointer
* @param {Phaser.Pointer} pointer
* @param {number} delay - The time below which the pointer is considered as just over.
* @return {boolean}
*/
justOver: function (pointer, delay) {
pointer = pointer || 0;
delay = delay || 500;
pointer = pointer || 0;
delay = delay || 500;
return (this._pointerData[pointer].isOver && this.overDuration(pointer) < delay);
},
/**
/**
* Returns true if the pointer has left the Sprite within the specified delay time (defaults to 500ms, half a second)
* @method Phaser.InputHandler#justOut
* @param {Pointer} pointer
* @param {Phaser.Pointer} pointer
* @param {number} delay - The time below which the pointer is considered as just out.
* @return {boolean}
*/
justOut: function (pointer, delay) {
pointer = pointer || 0;
delay = delay || 500;
pointer = pointer || 0;
delay = delay || 500;
return (this._pointerData[pointer].isOut && (this.game.time.now - this._pointerData[pointer].timeOut < delay));
},
/**
/**
* Returns true if the pointer has entered the Sprite within the specified delay time (defaults to 500ms, half a second)
* @method Phaser.InputHandler#justPressed
* @param {Pointer} pointer
* @param {Phaser.Pointer} pointer
* @param {number} delay - The time below which the pointer is considered as just over.
* @return {boolean}
*/
justPressed: function (pointer, delay) {
pointer = pointer || 0;
delay = delay || 500;
pointer = pointer || 0;
delay = delay || 500;
return (this._pointerData[pointer].isDown && this.downDuration(pointer) < delay);
},
/**
/**
* Returns true if the pointer has left the Sprite within the specified delay time (defaults to 500ms, half a second)
* @method Phaser.InputHandler#justReleased
* @param {Pointer} pointer
* @param {Phaser.Pointer} pointer
* @param {number} delay - The time below which the pointer is considered as just out.
* @return {boolean}
*/
justReleased: function (pointer, delay) {
pointer = pointer || 0;
delay = delay || 500;
pointer = pointer || 0;
delay = delay || 500;
return (this._pointerData[pointer].isUp && (this.game.time.now - this._pointerData[pointer].timeUp < delay));
},
/**
/**
* If the pointer is currently over this Sprite this returns how long it has been there for in milliseconds.
* @method Phaser.InputHandler#overDuration
* @param {Pointer} pointer
* @param {Phaser.Pointer} pointer
* @return {number} The number of milliseconds the pointer has been over the Sprite, or -1 if not over.
*/
overDuration: function (pointer) {
pointer = pointer || 0;
pointer = pointer || 0;
if (this._pointerData[pointer].isOver)
{
@ -846,15 +844,15 @@ Phaser.InputHandler.prototype = {
},
/**
/**
* If the pointer is currently over this Sprite this returns how long it has been there for in milliseconds.
* @method Phaser.InputHandler#downDuration
* @param {Pointer} pointer
* @param {Phaser.Pointer} pointer
* @return {number} The number of milliseconds the pointer has been pressed down on the Sprite, or -1 if not over.
*/
downDuration: function (pointer) {
pointer = pointer || 0;
pointer = pointer || 0;
if (this._pointerData[pointer].isDown)
{
@ -865,25 +863,24 @@ Phaser.InputHandler.prototype = {
},
/**
/**
* Make this Sprite draggable by the mouse. You can also optionally set mouseStartDragCallback and mouseStopDragCallback
* @method Phaser.InputHandler#enableDrag
* @param lockCenter If false the Sprite will drag from where you click it minus the dragOffset. If true it will center itself to the tip of the mouse pointer.
* @param bringToTop If true the Sprite will be bought to the top of the rendering list in its current Group.
* @param pixelPerfect If true it will use a pixel perfect test to see if you clicked the Sprite. False uses the bounding box.
* @param alphaThreshold If using pixel perfect collision this specifies the alpha level from 0 to 255 above which a collision is processed (default 255)
* @param boundsRect If you want to restrict the drag of this sprite to a specific FlxRect, pass the FlxRect here, otherwise it's free to drag anywhere
* @param boundsSprite If you want to restrict the drag of this sprite to within the bounding box of another sprite, pass it here
* @param {boolean} [lockCenter=false] - If false the Sprite will drag from where you click it minus the dragOffset. If true it will center itself to the tip of the mouse pointer.
* @param {boolean} [bringToTop=false] - If true the Sprite will be bought to the top of the rendering list in its current Group.
* @param {boolean} [pixelPerfect=false] - If true it will use a pixel perfect test to see if you clicked the Sprite. False uses the bounding box.
* @param {boolean} [alphaThreshold=255] - If using pixel perfect collision this specifies the alpha level from 0 to 255 above which a collision is processed.
* @param {Phaser.Rectangle} [boundsRect=null] - If you want to restrict the drag of this sprite to a specific Rectangle, pass the Phaser.Rectangle here, otherwise it's free to drag anywhere.
* @param {Phaser.Sprite} [boundsSprite=null] - If you want to restrict the drag of this sprite to within the bounding box of another sprite, pass it here.
*/
enableDrag: function (lockCenter, bringToTop, pixelPerfect, alphaThreshold, boundsRect, boundsSprite) {
if (typeof lockCenter == 'undefined') { lockCenter = false; }
if (typeof bringToTop == 'undefined') { bringToTop = false; }
if (typeof pixelPerfect == 'undefined') { pixelPerfect = false; }
alphaThreshold = alphaThreshold || 255;
boundsRect = boundsRect || null;
boundsSprite = boundsSprite || null;
if (typeof alphaThreshold == 'undefined') { alphaThreshold = 255; }
if (typeof boundsRect == 'undefined') { boundsRect = null; }
if (typeof boundsSprite == 'undefined') { boundsSprite = null; }
this._dragPoint = new Phaser.Point();
this.draggable = true;
@ -906,7 +903,7 @@ Phaser.InputHandler.prototype = {
},
/**
/**
* Stops this sprite from being able to be dragged. If it is currently the target of an active drag it will be stopped immediately. Also disables any set callbacks.
* @method Phaser.InputHandler#disableDrag
*/
@ -926,9 +923,10 @@ Phaser.InputHandler.prototype = {
},
/**
/**
* Called by Pointer when drag starts on this Sprite. Should not usually be called directly.
* @method Phaser.InputHandler#startDrag
* @param {Phaser.Pointer} pointer
*/
startDrag: function (pointer) {
@ -957,9 +955,10 @@ Phaser.InputHandler.prototype = {
},
/**
/**
* Called by Pointer when drag is stopped on this Sprite. Should not usually be called directly.
* @method Phaser.InputHandler#stopDrag
* @param {Phaser.Pointer} pointer
*/
stopDrag: function (pointer) {
@ -976,37 +975,37 @@ Phaser.InputHandler.prototype = {
this.sprite.events.onDragStop.dispatch(this.sprite, pointer);
this.sprite.events.onInputUp.dispatch(this.sprite, pointer);
if (this.checkPointerOver(pointer) == false)
if (this.checkPointerOver(pointer) === false)
{
this._pointerOutHandler(pointer);
}
},
/**
/**
* Restricts this sprite to drag movement only on the given axis. Note: If both are set to false the sprite will never move!
* @method Phaser.InputHandler#setDragLock
* @param allowHorizontal To enable the sprite to be dragged horizontally set to true, otherwise false
* @param allowVertical To enable the sprite to be dragged vertically set to true, otherwise false
* @param {boolean} [allowHorizontal=true] - To enable the sprite to be dragged horizontally set to true, otherwise false.
* @param {boolean} [allowVertical=true] - To enable the sprite to be dragged vertically set to true, otherwise false.
*/
setDragLock: function (allowHorizontal, allowVertical) {
if (typeof allowHorizontal == 'undefined') { allowHorizontal = true; }
if (typeof allowVertical == 'undefined') { allowVertical = true; }
if (typeof allowVertical == 'undefined') { allowVertical = true; }
this.allowHorizontalDrag = allowHorizontal;
this.allowVerticalDrag = allowVertical;
},
/**
/**
* Make this Sprite snap to the given grid either during drag or when it's released.
* For example 16x16 as the snapX and snapY would make the sprite snap to every 16 pixels.
* @method Phaser.InputHandler#enableSnap
* @param snapX The width of the grid cell in pixels
* @param snapY The height of the grid cell in pixels
* @param onDrag If true the sprite will snap to the grid while being dragged
* @param onRelease If true the sprite will snap to the grid when released
* @param {number} snapX - The width of the grid cell to snap to.
* @param {number} snapY - The height of the grid cell to snap to.
* @param {boolean} [onDrag=true] - If true the sprite will snap to the grid while being dragged.
* @param {boolean} [onRelease=false] - If true the sprite will snap to the grid when released.
*/
enableSnap: function (snapX, snapY, onDrag, onRelease) {
@ -1020,7 +1019,7 @@ Phaser.InputHandler.prototype = {
},
/**
/**
* Stops the sprite from snapping to a grid during drag or release.
* @method Phaser.InputHandler#disableSnap
*/
@ -1031,7 +1030,7 @@ Phaser.InputHandler.prototype = {
},
/**
/**
* Bounds Rect check for the sprite drag
* @method Phaser.InputHandler#checkBoundsRect
*/
@ -1057,7 +1056,7 @@ Phaser.InputHandler.prototype = {
},
/**
/**
* Parent Sprite Bounds check for the sprite drag.
* @method Phaser.InputHandler#checkBoundsSprite
*/

View file

@ -13,87 +13,87 @@
*/
Phaser.Key = function (game, keycode) {
/**
* @property {Phaser.Game} game - A reference to the currently running game.
*/
this.game = game;
/**
* @property {Phaser.Game} game - A reference to the currently running game.
*/
this.game = game;
/**
* @property {boolean} isDown - The "down" state of the key.
* @default
*/
this.isDown = false;
/**
* @property {boolean} isDown - The "down" state of the key.
* @default
*/
this.isDown = false;
/**
* @property {boolean} isUp - The "up" state of the key.
* @default
*/
this.isUp = false;
/**
* @property {boolean} isUp - The "up" state of the key.
* @default
*/
this.isUp = false;
/**
* @property {boolean} altKey - The down state of the ALT key, if pressed at the same time as this key.
* @default
*/
this.altKey = false;
/**
* @property {boolean} altKey - The down state of the ALT key, if pressed at the same time as this key.
* @default
*/
this.altKey = false;
/**
* @property {boolean} ctrlKey - The down state of the CTRL key, if pressed at the same time as this key.
* @default
*/
this.ctrlKey = false;
/**
* @property {boolean} ctrlKey - The down state of the CTRL key, if pressed at the same time as this key.
* @default
*/
this.ctrlKey = false;
/**
* @property {boolean} shiftKey - The down state of the SHIFT key, if pressed at the same time as this key.
* @default
*/
this.shiftKey = false;
/**
* @property {boolean} shiftKey - The down state of the SHIFT key, if pressed at the same time as this key.
* @default
*/
this.shiftKey = false;
/**
* @property {number} timeDown - The timestamp when the key was last pressed down.
* @default
*/
this.timeDown = 0;
/**
* @property {number} timeDown - The timestamp when the key was last pressed down.
* @default
*/
this.timeDown = 0;
/**
* If the key is down this value holds the duration of that key press and is constantly updated.
* If the key is up it holds the duration of the previous down session.
* @property {number} duration - The number of milliseconds this key has been held down for.
* @default
*/
this.duration = 0;
/**
* If the key is down this value holds the duration of that key press and is constantly updated.
* If the key is up it holds the duration of the previous down session.
* @property {number} duration - The number of milliseconds this key has been held down for.
* @default
*/
this.duration = 0;
/**
* @property {number} timeUp - The timestamp when the key was last released.
* @default
*/
this.timeUp = 0;
/**
* @property {number} timeUp - The timestamp when the key was last released.
* @default
*/
this.timeUp = 0;
/**
* @property {number} repeats - If a key is held down this holds down the number of times the key has 'repeated'.
* @default
*/
this.repeats = 0;
/**
* @property {number} repeats - If a key is held down this holds down the number of times the key has 'repeated'.
* @default
*/
this.repeats = 0;
/**
* @property {number} keyCode - The keycode of this key.
*/
this.keyCode = keycode;
/**
* @property {number} keyCode - The keycode of this key.
*/
this.keyCode = keycode;
/**
* @property {Phaser.Signal} onDown - This Signal is dispatched every time this Key is pressed down. It is only dispatched once (until the key is released again).
*/
/**
* @property {Phaser.Signal} onDown - This Signal is dispatched every time this Key is pressed down. It is only dispatched once (until the key is released again).
*/
this.onDown = new Phaser.Signal();
/**
* @property {Phaser.Signal} onUp - This Signal is dispatched every time this Key is pressed down. It is only dispatched once (until the key is released again).
*/
/**
* @property {Phaser.Signal} onUp - This Signal is dispatched every time this Key is pressed down. It is only dispatched once (until the key is released again).
*/
this.onUp = new Phaser.Signal();
};
Phaser.Key.prototype = {
/**
/**
* Called automatically by Phaser.Keyboard.
* @method Phaser.Key#processKeyDown
* @param {KeyboardEvent} event.
@ -124,7 +124,7 @@ Phaser.Key.prototype = {
},
/**
/**
* Called automatically by Phaser.Keyboard.
* @method Phaser.Key#processKeyUp
* @param {KeyboardEvent} event.
@ -140,8 +140,8 @@ Phaser.Key.prototype = {
},
/**
* Returns the "just pressed" state of the Key. Just pressed is considered true if the key was pressed down within the duration given (default 250ms)
/**
* Returns the "just pressed" state of the Key. Just pressed is considered true if the key was pressed down within the duration given (default 250ms)
* @method Phaser.Key#justPressed
* @param {number} [duration=250] - The duration below which the key is considered as being just pressed.
* @return {boolean} True if the key is just pressed otherwise false.
@ -154,8 +154,8 @@ Phaser.Key.prototype = {
},
/**
* Returns the "just released" state of the Key. Just released is considered as being true if the key was released within the duration given (default 250ms)
/**
* Returns the "just released" state of the Key. Just released is considered as being true if the key was released within the duration given (default 250ms)
* @method Phaser.Key#justPressed
* @param {number} [duration=250] - The duration below which the key is considered as being just released.
* @return {boolean} True if the key is just released otherwise false.
@ -164,7 +164,7 @@ Phaser.Key.prototype = {
if (typeof duration === "undefined") { duration = 250; }
return (this.isDown == false && (this.game.time.now - this.timeUp < duration));
return (this.isDown === false && (this.game.time.now - this.timeUp < duration));
}

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
* @classdesc A Keyboard object Description.
* @constructor
* @param {Phaser.Game} game - A reference to the currently running game.
*/
Phaser.Keyboard = function (game) {
/**
* @property {Phaser.Game} game - Local reference to game.
*/
this.game = game;
/**
* @property {Description} _keys - Description.
* @private
*/
/**
* @property {Phaser.Game} game - Local reference to game.
*/
this.game = game;
/**
* @property {object} _keys - The object the key values are stored in.
* @private
*/
this._keys = {};
/**
* @property {Description} _hotkeys - Description.
* @property {object} _hotkeys - The object the hot keys are stored in.
* @private
*/
this._hotkeys = {};
/**
* @property {Description} _capture - Description.
* @private
*/
/**
* @property {object} _capture - The object the key capture values are stored in.
* @private
*/
this._capture = {};
/**
@ -72,7 +71,7 @@ Phaser.Keyboard = function (game) {
* @property {function} onUpCallback - This callback is invoked every time a key is released.
*/
this.onUpCallback = null;
};
Phaser.Keyboard.prototype = {
@ -134,10 +133,10 @@ Phaser.Keyboard.prototype = {
*/
createCursorKeys: function () {
return {
up: this.addKey(Phaser.Keyboard.UP),
down: this.addKey(Phaser.Keyboard.DOWN),
left: this.addKey(Phaser.Keyboard.LEFT),
return {
up: this.addKey(Phaser.Keyboard.UP),
down: this.addKey(Phaser.Keyboard.DOWN),
left: this.addKey(Phaser.Keyboard.LEFT),
right: this.addKey(Phaser.Keyboard.RIGHT)
}
@ -178,7 +177,7 @@ Phaser.Keyboard.prototype = {
},
/**
/**
* By default when a key is pressed Phaser will not stop the event from propagating up to the browser.
* There are some keys this can be annoying for, like the arrow keys or space bar, which make the browser window scroll.
* You can use addKeyCapture to consume the keyboard event for specific keys so it doesn't bubble up to the the browser.
@ -201,9 +200,9 @@ Phaser.Keyboard.prototype = {
}
},
/**
* Removes an existing key capture.
* @method Phaser.Keyboard#removeKeyCapture
/**
* Removes an existing key capture.
* @method Phaser.Keyboard#removeKeyCapture
* @param {number} keycode
*/
removeKeyCapture: function (keycode) {
@ -212,9 +211,9 @@ Phaser.Keyboard.prototype = {
},
/**
* Clear all set key captures.
* @method Phaser.Keyboard#clearCaptures
/**
* Clear all set key captures.
* @method Phaser.Keyboard#clearCaptures
*/
clearCaptures: function () {
@ -222,12 +221,12 @@ Phaser.Keyboard.prototype = {
},
/**
* Process the keydown event.
* @method Phaser.Keyboard#processKeyDown
/**
* Process the keydown event.
* @method Phaser.Keyboard#processKeyDown
* @param {KeyboardEvent} event
* @protected
*/
*/
processKeyDown: function (event) {
if (this.game.input.disabled || this.disabled)
@ -278,9 +277,9 @@ Phaser.Keyboard.prototype = {
},
/**
* Process the keyup event.
* @method Phaser.Keyboard#processKeyUp
/**
* Process the keyup event.
* @method Phaser.Keyboard#processKeyUp
* @param {KeyboardEvent} event
* @protected
*/
@ -324,9 +323,9 @@ Phaser.Keyboard.prototype = {
},
/**
* Reset the "isDown" state of all keys.
* @method Phaser.Keyboard#reset
/**
* Reset the "isDown" state of all keys.
* @method Phaser.Keyboard#reset
*/
reset: function () {
@ -390,7 +389,7 @@ Phaser.Keyboard.prototype = {
return this._keys[keycode].isDown;
}
return false;
return false;
}

View file

@ -16,33 +16,15 @@
*/
Phaser.MSPointer = function (game) {
/**
* @property {Phaser.Game} game - Local reference to game.
*/
this.game = game;
/**
* @property {Phaser.Game} callbackContext - Description.
*/
this.callbackContext = this.game;
/**
* @property {Description} mouseDownCallback - Description.
* @default
*/
this.mouseDownCallback = null;
/**
* @property {Description} mouseMoveCallback - Description.
* @default
*/
this.mouseMoveCallback = null;
/**
* @property {Description} mouseUpCallback - Description.
* @default
*/
this.mouseUpCallback = null;
/**
* @property {Phaser.Game} game - A reference to the currently running game.
*/
this.game = game;
/**
* @property {Object} callbackContext - The context under which callbacks are called (defaults to game).
*/
this.callbackContext = this.game;
/**
* You can disable all Input by setting disabled = true. While set all new input related events will be ignored.
@ -51,26 +33,20 @@ Phaser.MSPointer = function (game) {
this.disabled = false;
/**
* Description.
* @property {Description} _onMSPointerDown
* @property {function} _onMSPointerDown - Internal function to handle MSPointer events.
* @private
* @default
*/
this._onMSPointerDown = null;
/**
* Description.
* @property {Description} _onMSPointerMove
* @property {function} _onMSPointerMove - Internal function to handle MSPointer events.
* @private
* @default
*/
this._onMSPointerMove = null;
/**
* Description.
* @property {Description} _onMSPointerUp
* @property {function} _onMSPointerUp - Internal function to handle MSPointer events.
* @private
* @default
*/
this._onMSPointerUp = null;
@ -78,7 +54,7 @@ Phaser.MSPointer = function (game) {
Phaser.MSPointer.prototype = {
/**
/**
* Starts the event listeners running.
* @method Phaser.MSPointer#start
*/
@ -86,7 +62,7 @@ Phaser.MSPointer.prototype = {
var _this = this;
if (this.game.device.mspointer == true)
if (this.game.device.mspointer === true)
{
this._onMSPointerDown = function (event) {
return _this.onPointerDown(event);
@ -104,6 +80,11 @@ Phaser.MSPointer.prototype = {
this.game.renderer.view.addEventListener('MSPointerMove', this._onMSPointerMove, false);
this.game.renderer.view.addEventListener('MSPointerUp', this._onMSPointerUp, false);
// IE11+ uses non-prefix events
this.game.renderer.view.addEventListener('pointerDown', this._onMSPointerDown, false);
this.game.renderer.view.addEventListener('pointerMove', this._onMSPointerMove, false);
this.game.renderer.view.addEventListener('pointerUp', this._onMSPointerUp, false);
this.game.renderer.view.style['-ms-content-zooming'] = 'none';
this.game.renderer.view.style['-ms-touch-action'] = 'none';
@ -112,10 +93,10 @@ Phaser.MSPointer.prototype = {
},
/**
* Description.
* The function that handles the PointerDown event.
* @method Phaser.MSPointer#onPointerDown
* @param {Any} event
**/
* @param {PointerEvent} event
*/
onPointerDown: function (event) {
if (this.game.input.disabled || this.disabled)
@ -131,10 +112,10 @@ Phaser.MSPointer.prototype = {
},
/**
* Description.
* The function that handles the PointerMove event.
* @method Phaser.MSPointer#onPointerMove
* @param {Any} event
**/
* @param {PointerEvent } event
*/
onPointerMove: function (event) {
if (this.game.input.disabled || this.disabled)
@ -150,10 +131,10 @@ Phaser.MSPointer.prototype = {
},
/**
* Description.
* The function that handles the PointerUp event.
* @method Phaser.MSPointer#onPointerUp
* @param {Any} event
**/
* @param {PointerEvent} event
*/
onPointerUp: function (event) {
if (this.game.input.disabled || this.disabled)
@ -168,7 +149,7 @@ Phaser.MSPointer.prototype = {
},
/**
/**
* Stop the event listeners.
* @method Phaser.MSPointer#stop
*/
@ -178,6 +159,10 @@ Phaser.MSPointer.prototype = {
this.game.stage.canvas.removeEventListener('MSPointerMove', this._onMSPointerMove);
this.game.stage.canvas.removeEventListener('MSPointerUp', this._onMSPointerUp);
this.game.stage.canvas.removeEventListener('pointerDown', this._onMSPointerDown);
this.game.stage.canvas.removeEventListener('pointerMove', this._onMSPointerMove);
this.game.stage.canvas.removeEventListener('pointerUp', this._onMSPointerUp);
}
};

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
* @classdesc The Mouse class
* @constructor
* @param {Phaser.Game} game - A reference to the currently running game.
*/
Phaser.Mouse = function (game) {
/**
* @property {Phaser.Game} game - Local reference to game.
*/
this.game = game;
/**
* @property {Object} callbackContext - Description.
*/
this.callbackContext = this.game;
/**
* @property {Phaser.Game} game - A reference to the currently running game.
*/
this.game = game;
/**
* @property {Object} callbackContext - The context under which callbacks are called.
*/
this.callbackContext = this.game;
/**
* @property {function} mouseDownCallback - Description.
* @default
*/
this.mouseDownCallback = null;
/**
* @property {function} mouseMoveCallback - Description.
* @default
*/
this.mouseMoveCallback = null;
/**
* @property {function} mouseUpCallback - Description.
* @default
*/
this.mouseUpCallback = null;
/**
* @property {function} mouseDownCallback - A callback that can be fired when the mouse is pressed down.
*/
this.mouseDownCallback = null;
/**
* @property {function} mouseMoveCallback - A callback that can be fired when the mouse is moved while pressed down.
*/
this.mouseMoveCallback = null;
/**
* @property {function} mouseUpCallback - A callback that can be fired when the mouse is released from a pressed down state.
*/
this.mouseUpCallback = null;
/**
* @property {boolean} capture - If true the DOM mouse events will have event.preventDefault applied to them, if false they will propogate fully.
*/
this.capture = true;
/**
* @property {number} button- The type of click, either: Phaser.Mouse.NO_BUTTON, Phaser.Mouse.LEFT_BUTTON, Phaser.Mouse.MIDDLE_BUTTON or Phaser.Mouse.RIGHT_BUTTON.
* @default
*/
this.button = -1;
/**
* @property {number} button- The type of click, either: Phaser.Mouse.NO_BUTTON, Phaser.Mouse.LEFT_BUTTON, Phaser.Mouse.MIDDLE_BUTTON or Phaser.Mouse.RIGHT_BUTTON.
* @default
*/
this.button = -1;
/**
* You can disable all Input by setting disabled = true. While set all new input related events will be ignored.
* @property {boolean} disabled
* @property {boolean} disabled - You can disable all Input by setting disabled = true. While set all new input related events will be ignored.
* @default
*/
this.disabled = false;
/**
* If the mouse has been Pointer Locked successfully this will be set to true.
* @property {boolean} locked
* @property {boolean} locked - If the mouse has been Pointer Locked successfully this will be set to true.
* @default
*/
this.locked = false;
/**
* This event is dispatched when the browser enters or leaves pointer lock state.
* @property {Phaser.Signal} pointerLock
* @property {Phaser.Signal} pointerLock - This event is dispatched when the browser enters or leaves pointer lock state.
* @default
*/
this.pointerLock = new Phaser.Signal;
this.pointerLock = new Phaser.Signal();
/**
* The browser mouse event.
* @property {MouseEvent} event
* @property {MouseEvent} event - The browser mouse event.
*/
this.event;
this.event = null;
/**
* @property {function} _onMouseDown
* @property {function} _onMouseDown - Internal event handler reference.
* @private
*/
this._onMouseDown;
this._onMouseDown = null;
/**
* @property {function} _onMouseMove
* @property {function} _onMouseMove - Internal event handler reference.
* @private
*/
this._onMouseMove;
this._onMouseMove = null;
/**
* @property {function} _onMouseUp
* @property {function} _onMouseUp - Internal event handler reference.
* @private
*/
this._onMouseUp;
this._onMouseUp = null;
};
@ -105,6 +97,7 @@ Phaser.Mouse = function (game) {
* @type {number}
*/
Phaser.Mouse.NO_BUTTON = -1;
/**
* @constant
* @type {number}
@ -125,7 +118,7 @@ Phaser.Mouse.RIGHT_BUTTON = 2;
Phaser.Mouse.prototype = {
/**
/**
* Starts the event listeners running.
* @method Phaser.Mouse#start
*/
@ -133,7 +126,7 @@ Phaser.Mouse.prototype = {
var _this = this;
if (this.game.device.android && this.game.device.chrome == false)
if (this.game.device.android && this.game.device.chrome === false)
{
// Android stock browser fires mouse events even if you preventDefault on the touchStart, so ...
return;
@ -161,10 +154,10 @@ Phaser.Mouse.prototype = {
},
/**
* The internal method that handles the mouse down event from the browser.
* @method Phaser.Mouse#onMouseDown
* @param {MouseEvent} event
/**
* The internal method that handles the mouse down event from the browser.
* @method Phaser.Mouse#onMouseDown
* @param {MouseEvent} event - The native event from the browser. This gets stored in Mouse.event.
*/
onMouseDown: function (event) {
@ -193,10 +186,10 @@ Phaser.Mouse.prototype = {
},
/**
/**
* The internal method that handles the mouse move event from the browser.
* @method Phaser.Mouse#onMouseMove
* @param {MouseEvent} event
* @method Phaser.Mouse#onMouseMove
* @param {MouseEvent} event - The native event from the browser. This gets stored in Mouse.event.
*/
onMouseMove: function (event) {
@ -223,10 +216,10 @@ Phaser.Mouse.prototype = {
},
/**
/**
* The internal method that handles the mouse up event from the browser.
* @method Phaser.Mouse#onMouseUp
* @param {MouseEvent} event
* @method Phaser.Mouse#onMouseUp
* @param {MouseEvent} event - The native event from the browser. This gets stored in Mouse.event.
*/
onMouseUp: function (event) {
@ -237,7 +230,7 @@ Phaser.Mouse.prototype = {
event.preventDefault();
}
this.button = Phaser.Mouse.NO_BUTTON;
this.button = Phaser.Mouse.NO_BUTTON;
if (this.mouseUpCallback)
{
@ -259,7 +252,7 @@ Phaser.Mouse.prototype = {
* If the browser supports it you can request that the pointer be locked to the browser window.
* This is classically known as 'FPS controls', where the pointer can't leave the browser until the user presses an exit key.
* If the browser successfully enters a locked state the event Phaser.Mouse.pointerLock will be dispatched and the first parameter will be 'true'.
* @method Phaser.Mouse#requestPointerLock
* @method Phaser.Mouse#requestPointerLock
*/
requestPointerLock: function () {
@ -284,10 +277,10 @@ Phaser.Mouse.prototype = {
},
/**
* Internal pointerLockChange handler.
* @method Phaser.Mouse#pointerLockChange
* @param {MouseEvent} event
/**
* Internal pointerLockChange handler.
* @method Phaser.Mouse#pointerLockChange
* @param {pointerlockchange} event - The native event from the browser. This gets stored in Mouse.event.
*/
pointerLockChange: function (event) {
@ -297,20 +290,20 @@ Phaser.Mouse.prototype = {
{
// Pointer was successfully locked
this.locked = true;
this.pointerLock.dispatch(true);
this.pointerLock.dispatch(true, event);
}
else
{
// Pointer was unlocked
this.locked = false;
this.pointerLock.dispatch(false);
this.pointerLock.dispatch(false, event);
}
},
/**
* Internal release pointer lock handler.
* @method Phaser.Mouse#releasePointerLock
/**
* Internal release pointer lock handler.
* @method Phaser.Mouse#releasePointerLock
*/
releasePointerLock: function () {
@ -324,7 +317,7 @@ Phaser.Mouse.prototype = {
},
/**
/**
* Stop the event listeners.
* @method Phaser.Mouse#stop
*/

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.
* @constructor
* @param {Phaser.Game} game - A reference to the currently running game.
* @param {Description} id - Description.
* @param {number} id - The ID of the Pointer object within the game. Each game can have up to 10 active pointers.
*/
Phaser.Pointer = function (game, id) {
/**
* @property {Phaser.Game} game - Local reference to game.
* @property {Phaser.Game} game - A reference to the currently running game.
*/
this.game = game;
/**
* @property {Description} id - Description.
* @property {number} id - The ID of the Pointer object within the game. Each game can have up to 10 active pointers.
*/
this.id = id;
/**
* Local private variable to store the status of dispatching a hold event.
* @property {boolean} _holdSent
* @property {boolean} _holdSent - Local private variable to store the status of dispatching a hold event.
* @private
* @default
*/
this._holdSent = false;
/**
* Local private variable storing the short-term history of pointer movements.
* @property {array} _history
* @property {array} _history - Local private variable storing the short-term history of pointer movements.
* @private
*/
this._history = [];
/**
* Local private variable storing the time at which the next history drop should occur
* @property {number} _lastDrop
* @property {number} _lastDrop - Local private variable storing the time at which the next history drop should occur.
* @private
* @default
*/
this._nextDrop = 0;
/**
* Monitor events outside of a state reset loop.
* @property {boolean} _stateReset
* @private
* @default
*/
* @property {boolean} _stateReset - Monitor events outside of a state reset loop.
* @private
* @default
*/
this._stateReset = false;
/**
* Description.
* @property {boolean} withinGame
* @property {boolean} withinGame - true if the Pointer is within the game area, otherwise false.
*/
this.withinGame = false;
/**
* The horizontal coordinate of point relative to the viewport in pixels, excluding any scroll offset.
* @property {number} clientX
* @property {number} clientX - The horizontal coordinate of point relative to the viewport in pixels, excluding any scroll offset.
* @default
*/
this.clientX = -1;
/**
* The vertical coordinate of point relative to the viewport in pixels, excluding any scroll offset.
* @property {number} clientY
* @property {number} clientY - The vertical coordinate of point relative to the viewport in pixels, excluding any scroll offset.
* @default
*/
this.clientY = -1;
/**
* The horizontal coordinate of point relative to the viewport in pixels, including any scroll offset.
* @property {number} pageX
* @property {number} pageX - The horizontal coordinate of point relative to the viewport in pixels, including any scroll offset.
* @default
*/
this.pageX = -1;
/**
* The vertical coordinate of point relative to the viewport in pixels, including any scroll offset.
* @property {number} pageY
* @property {number} pageY - The vertical coordinate of point relative to the viewport in pixels, including any scroll offset.
* @default
*/
this.pageY = -1;
/**
* The horizontal coordinate of point relative to the screen in pixels.
* @property {number} screenX
* @property {number} screenX - The horizontal coordinate of point relative to the screen in pixels.
* @default
*/
this.screenX = -1;
/**
* The vertical coordinate of point relative to the screen in pixels.
* @property {number} screenY
* @property {number} screenY - The vertical coordinate of point relative to the screen in pixels.
* @default
*/
this.screenY = -1;
/**
* The horizontal coordinate of point relative to the game element. This value is automatically scaled based on game size.
* @property {number} x
* @property {number} x - The horizontal coordinate of point relative to the game element. This value is automatically scaled based on game size.
* @default
*/
this.x = -1;
/**
* The vertical coordinate of point relative to the game element. This value is automatically scaled based on game size.
* @property {number} y
* @property {number} y - The vertical coordinate of point relative to the game element. This value is automatically scaled based on game size.
* @default
*/
this.y = -1;
/**
* If the Pointer is a mouse this is true, otherwise false.
* @property {boolean} isMouse
* @type {boolean}
* @property {boolean} isMouse - If the Pointer is a mouse this is true, otherwise false.
* @default
*/
this.isMouse = false;
/**
* If the Pointer is touching the touchscreen, or the mouse button is held down, isDown is set to true.
* @property {boolean} isDown
* @property {boolean} isDown - If the Pointer is touching the touchscreen, or the mouse button is held down, isDown is set to true.
* @default
*/
this.isDown = false;
/**
* If the Pointer is not touching the touchscreen, or the mouse button is up, isUp is set to true.
* @property {boolean} isUp
* @property {boolean} isUp - If the Pointer is not touching the touchscreen, or the mouse button is up, isUp is set to true.
* @default
*/
this.isUp = true;
/**
* A timestamp representing when the Pointer first touched the touchscreen.
* @property {number} timeDown
* @property {number} timeDown - A timestamp representing when the Pointer first touched the touchscreen.
* @default
*/
this.timeDown = 0;
/**
* A timestamp representing when the Pointer left the touchscreen.
* @property {number} timeUp
* @property {number} timeUp - A timestamp representing when the Pointer left the touchscreen.
* @default
*/
this.timeUp = 0;
/**
* A timestamp representing when the Pointer was last tapped or clicked.
* @property {number} previousTapTime
* @property {number} previousTapTime - A timestamp representing when the Pointer was last tapped or clicked.
* @default
*/
this.previousTapTime = 0;
/**
* The total number of times this Pointer has been touched to the touchscreen.
* @property {number} totalTouches
* @property {number} totalTouches - The total number of times this Pointer has been touched to the touchscreen.
* @default
*/
this.totalTouches = 0;
/**
* The number of miliseconds since the last click.
* @property {number} msSinceLastClick
* @property {number} msSinceLastClick - The number of miliseconds since the last click.
* @default
*/
this.msSinceLastClick = Number.MAX_VALUE;
/**
* The Game Object this Pointer is currently over / touching / dragging.
* @property {Any} targetObject
* @property {any} targetObject - The Game Object this Pointer is currently over / touching / dragging.
* @default
*/
this.targetObject = null;
/**
* An active pointer is one that is currently pressed down on the display. A Mouse is always active.
* @property {boolean} active
* @property {boolean} active - An active pointer is one that is currently pressed down on the display. A Mouse is always active.
* @default
*/
this.active = false;
/**
* A Phaser.Point object containing the current x/y values of the pointer on the display.
* @property {Phaser.Point} position
* @property {Phaser.Point} position - A Phaser.Point object containing the current x/y values of the pointer on the display.
*/
this.position = new Phaser.Point();
/**
* A Phaser.Point object containing the x/y values of the pointer when it was last in a down state on the display.
* @property {Phaser.Point} positionDown
* @property {Phaser.Point} positionDown - A Phaser.Point object containing the x/y values of the pointer when it was last in a down state on the display.
*/
this.positionDown = new Phaser.Point();
@ -207,7 +182,7 @@ Phaser.Pointer = function (game, id) {
*/
this.circle = new Phaser.Circle(0, 0, 44);
if (id == 0)
if (id === 0)
{
this.isMouse = true;
}
@ -216,7 +191,7 @@ Phaser.Pointer = function (game, id) {
Phaser.Pointer.prototype = {
/**
/**
* Called when the Pointer is pressed onto the touchscreen.
* @method Phaser.Pointer#start
* @param {Any} event
@ -232,7 +207,7 @@ Phaser.Pointer.prototype = {
}
// Fix to stop rogue browser plugins from blocking the visibility state event
if (this.game.paused == true && this.game.stage.scale.incorrectOrientation == false)
if (this.game.paused === true && this.game.stage.scale.incorrectOrientation === false)
{
this.game.paused = false;
return this;
@ -255,7 +230,7 @@ Phaser.Pointer.prototype = {
// x and y are the old values here?
this.positionDown.setTo(this.x, this.y);
if (this.game.input.multiInputOverride == Phaser.Input.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.Input.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.Input.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers == 0))
if (this.game.input.multiInputOverride == Phaser.Input.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.Input.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.Input.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers === 0))
{
this.game.input.x = this.x;
this.game.input.y = this.y;
@ -267,7 +242,7 @@ Phaser.Pointer.prototype = {
this._stateReset = false;
this.totalTouches++;
if (this.isMouse == false)
if (this.isMouse === false)
{
this.game.input.currentPointers++;
}
@ -281,17 +256,17 @@ Phaser.Pointer.prototype = {
},
/**
* Description.
/**
* Called internall by the Input Manager.
* @method Phaser.Pointer#update
*/
update: function () {
if (this.active)
{
if (this._holdSent == false && this.duration >= this.game.input.holdRate)
if (this._holdSent === false && this.duration >= this.game.input.holdRate)
{
if (this.game.input.multiInputOverride == Phaser.Input.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.Input.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.Input.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers == 0))
if (this.game.input.multiInputOverride == Phaser.Input.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.Input.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.Input.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers === 0))
{
this.game.input.onHold.dispatch(this);
}
@ -318,10 +293,10 @@ Phaser.Pointer.prototype = {
},
/**
* Called when the Pointer is moved
/**
* Called when the Pointer is moved.
* @method Phaser.Pointer#move
* @param {Any} event
* @param {MouseEvent|PointerEvent|TouchEvent} event - The event passed up from the input handler.
*/
move: function (event) {
@ -351,7 +326,7 @@ Phaser.Pointer.prototype = {
this.circle.x = this.x;
this.circle.y = this.y;
if (this.game.input.multiInputOverride == Phaser.Input.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.Input.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.Input.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers == 0))
if (this.game.input.multiInputOverride == Phaser.Input.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.Input.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.Input.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers === 0))
{
this.game.input.activePointer = this;
this.game.input.x = this.x;
@ -368,9 +343,9 @@ Phaser.Pointer.prototype = {
}
// Easy out if we're dragging something and it still exists
if (this.targetObject !== null && this.targetObject.isDragged == true)
if (this.targetObject !== null && this.targetObject.isDragged === true)
{
if (this.targetObject.update(this) == false)
if (this.targetObject.update(this) === false)
{
this.targetObject = null;
}
@ -388,7 +363,7 @@ Phaser.Pointer.prototype = {
{
var currentNode = this.game.input.interactiveItems.next;
do
do
{
// If the object is using pixelPerfect checks, or has a higher InputManager.PriorityID OR if the priority ID is the same as the current highest AND it has a higher renderOrderID, then set it to the top
if (currentNode.pixelPerfect || currentNode.priorityID > this._highestInputPriorityID || (currentNode.priorityID == this._highestInputPriorityID && currentNode.sprite.renderOrderID > this._highestRenderOrderID))
@ -433,7 +408,7 @@ Phaser.Pointer.prototype = {
{
// Same target as before, so update it
// console.log("Same target as before, so update it");
if (this._highestRenderObject.update(this) == false)
if (this._highestRenderObject.update(this) === false)
{
this.targetObject = null;
}
@ -455,10 +430,10 @@ Phaser.Pointer.prototype = {
},
/**
/**
* Called when the Pointer leaves the target area.
* @method Phaser.Pointer#leave
* @param {Any} event
* @param {MouseEvent|PointerEvent|TouchEvent} event - The event passed up from the input handler.
*/
leave: function (event) {
@ -467,10 +442,10 @@ Phaser.Pointer.prototype = {
},
/**
/**
* Called when the Pointer leaves the touchscreen.
* @method Phaser.Pointer#stop
* @param {Any} event
* @param {MouseEvent|PointerEvent|TouchEvent} event - The event passed up from the input handler.
*/
stop: function (event) {
@ -482,7 +457,7 @@ Phaser.Pointer.prototype = {
this.timeUp = this.game.time.now;
if (this.game.input.multiInputOverride == Phaser.Input.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.Input.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.Input.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers == 0))
if (this.game.input.multiInputOverride == Phaser.Input.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.Input.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.Input.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers === 0))
{
this.game.input.onUp.dispatch(this, event);
@ -515,7 +490,7 @@ Phaser.Pointer.prototype = {
this.isDown = false;
this.isUp = true;
if (this.isMouse == false)
if (this.isMouse === false)
{
this.game.input.currentPointers--;
}
@ -524,7 +499,7 @@ Phaser.Pointer.prototype = {
{
var currentNode = this.game.input.interactiveItems.next;
do
do
{
if (currentNode)
{
@ -546,11 +521,13 @@ Phaser.Pointer.prototype = {
},
/**
/**
* The Pointer is considered justPressed if the time it was pressed onto the touchscreen or clicked is less than justPressedRate.
* Note that calling justPressed doesn't reset the pressed status of the Pointer, it will return `true` for as long as the duration is valid.
* If you wish to check if the Pointer was pressed down just once then see the Sprite.events.onInputDown event.
* @method Phaser.Pointer#justPressed
* @param {number} [duration]
* @return {boolean}
* @param {number} [duration] - The time to check against. If none given it will use InputManager.justPressedRate.
* @return {boolean} true if the Pointer was pressed down within the duration given.
*/
justPressed: function (duration) {
@ -560,11 +537,13 @@ Phaser.Pointer.prototype = {
},
/**
/**
* The Pointer is considered justReleased if the time it left the touchscreen is less than justReleasedRate.
* Note that calling justReleased doesn't reset the pressed status of the Pointer, it will return `true` for as long as the duration is valid.
* If you wish to check if the Pointer was released just once then see the Sprite.events.onInputUp event.
* @method Phaser.Pointer#justReleased
* @param {number} [duration]
* @return {boolean}
* @param {number} [duration] - The time to check against. If none given it will use InputManager.justReleasedRate.
* @return {boolean} true if the Pointer was released within the duration given.
*/
justReleased: function (duration) {
@ -574,13 +553,13 @@ Phaser.Pointer.prototype = {
},
/**
/**
* Resets the Pointer properties. Called by InputManager.reset when you perform a State change.
* @method Phaser.Pointer#reset
*/
reset: function () {
if (this.isMouse == false)
if (this.isMouse === false)
{
this.active = false;
}
@ -600,15 +579,6 @@ Phaser.Pointer.prototype = {
this.targetObject = null;
},
/**
* Returns a string representation of this object.
* @method Phaser.Pointer#toString
* @return {string} A string representation of the instance.
**/
toString: function () {
return "[{Pointer (id=" + this.id + " identifer=" + this.identifier + " active=" + this.active + " duration=" + this.duration + " withinGame=" + this.withinGame + " x=" + this.x + " y=" + this.y + " clientX=" + this.clientX + " clientY=" + this.clientY + " screenX=" + this.screenX + " screenY=" + this.screenY + " pageX=" + this.pageX + " pageY=" + this.pageY + ")}]";
}
};
@ -644,7 +614,7 @@ Object.defineProperty(Phaser.Pointer.prototype, "worldX", {
get: function () {
return this.game.world.camera.x + this.x;
return this.game.world.camera.x + this.x;
}
@ -660,7 +630,7 @@ Object.defineProperty(Phaser.Pointer.prototype, "worldY", {
get: function () {
return this.game.world.camera.y + this.y;
return this.game.world.camera.y + this.y;
}

View file

@ -15,70 +15,102 @@
Phaser.Touch = function (game) {
/**
* @property {Phaser.Game} game - Local reference to game.
* @property {Phaser.Game} game - A reference to the currently running game.
*/
this.game = game;
/**
* You can disable all Input by setting disabled = true. While set all new input related events will be ignored.
* @method Phaser.Touch#disabled
* @property {boolean} disabled - You can disable all Touch events by setting disabled = true. While set all new touch events will be ignored.
* @return {boolean}
*/
this.disabled = false;
/**
* @property {Phaser.Game} callbackContext - Description.
* @property {Object} callbackContext - The context under which callbacks are called.
*/
this.callbackContext = this.game;
/**
* @property {Phaser.Game} touchStartCallback - Description.
* @default
* @property {function} touchStartCallback - A callback that can be fired on a touchStart event.
*/
this.touchStartCallback = null;
/**
* @property {Phaser.Game} touchMoveCallback - Description.
* @default
* @property {function} touchMoveCallback - A callback that can be fired on a touchMove event.
*/
this.touchMoveCallback = null;
/**
* @property {Phaser.Game} touchEndCallback - Description.
* @default
* @property {function} touchEndCallback - A callback that can be fired on a touchEnd event.
*/
this.touchEndCallback = null;
/**
* @property {Phaser.Game} touchEnterCallback - Description.
* @default
* @property {function} touchEnterCallback - A callback that can be fired on a touchEnter event.
*/
this.touchEnterCallback = null;
/**
* @property {Phaser.Game} touchLeaveCallback - Description.
* @default
* @property {function} touchLeaveCallback - A callback that can be fired on a touchLeave event.
*/
this.touchLeaveCallback = null;
/**
* @property {Description} touchCancelCallback - Description.
* @default
* @property {function} touchCancelCallback - A callback that can be fired on a touchCancel event.
*/
this.touchCancelCallback = null;
/**
* @property {boolean} preventDefault - Description.
* @property {boolean} preventDefault - If true the TouchEvent will have prevent.default called on it.
* @default
*/
this.preventDefault = true;
/**
* @property {TouchEvent} event - The browser touch event.
*/
this.event = null;
/**
* @property {function} _onTouchStart - Internal event handler reference.
* @private
*/
this._onTouchStart = null;
/**
* @property {function} _onTouchMove - Internal event handler reference.
* @private
*/
this._onTouchMove = null;
/**
* @property {function} _onTouchEnd - Internal event handler reference.
* @private
*/
this._onTouchEnd = null;
/**
* @property {function} _onTouchEnter - Internal event handler reference.
* @private
*/
this._onTouchEnter = null;
/**
* @property {function} _onTouchLeave - Internal event handler reference.
* @private
*/
this._onTouchLeave = null;
/**
* @property {function} _onTouchCancel - Internal event handler reference.
* @private
*/
this._onTouchCancel = null;
/**
* @property {function} _onTouchMove - Internal event handler reference.
* @private
*/
this._onTouchMove = null;
};
@ -144,12 +176,14 @@ Phaser.Touch.prototype = {
},
/**
* Description.
* The internal method that handles the touchstart event from the browser.
* @method Phaser.Touch#onTouchStart
* @param {Any} event
* @param {TouchEvent} event - The native event from the browser. This gets stored in Touch.event.
*/
onTouchStart: function (event) {
this.event = event;
if (this.touchStartCallback)
{
this.touchStartCallback.call(this.callbackContext, event);
@ -179,10 +213,12 @@ Phaser.Touch.prototype = {
* Touch cancel - touches that were disrupted (perhaps by moving into a plugin or browser chrome).
* Occurs for example on iOS when you put down 4 fingers and the app selector UI appears.
* @method Phaser.Touch#onTouchCancel
* @param {Any} event
* @param {TouchEvent} event - The native event from the browser. This gets stored in Touch.event.
*/
onTouchCancel: function (event) {
this.event = event;
if (this.touchCancelCallback)
{
this.touchCancelCallback.call(this.callbackContext, event);
@ -211,10 +247,12 @@ Phaser.Touch.prototype = {
* For touch enter and leave its a list of the touch points that have entered or left the target.
* Doesn't appear to be supported by most browsers on a canvas element yet.
* @method Phaser.Touch#onTouchEnter
* @param {Any} event
* @param {TouchEvent} event - The native event from the browser. This gets stored in Touch.event.
*/
onTouchEnter: function (event) {
this.event = event;
if (this.touchEnterCallback)
{
this.touchEnterCallback.call(this.callbackContext, event);
@ -230,10 +268,12 @@ Phaser.Touch.prototype = {
event.preventDefault();
}
/*
for (var i = 0; i < event.changedTouches.length; i++)
{
//console.log('touch enter');
}
*/
},
@ -241,10 +281,12 @@ Phaser.Touch.prototype = {
* For touch enter and leave its a list of the touch points that have entered or left the target.
* Doesn't appear to be supported by most browsers on a canvas element yet.
* @method Phaser.Touch#onTouchLeave
* @param {Any} event
*/
* @param {TouchEvent} event - The native event from the browser. This gets stored in Touch.event.
*/
onTouchLeave: function (event) {
this.event = event;
if (this.touchLeaveCallback)
{
this.touchLeaveCallback.call(this.callbackContext, event);
@ -255,20 +297,24 @@ Phaser.Touch.prototype = {
event.preventDefault();
}
/*
for (var i = 0; i < event.changedTouches.length; i++)
{
//console.log('touch leave');
}
*/
},
/**
* Description.
* The handler for the touchmove events.
* @method Phaser.Touch#onTouchMove
* @param {Any} event
* @param {TouchEvent} event - The native event from the browser. This gets stored in Touch.event.
*/
onTouchMove: function (event) {
this.event = event;
if (this.touchMoveCallback)
{
this.touchMoveCallback.call(this.callbackContext, event);
@ -287,12 +333,14 @@ Phaser.Touch.prototype = {
},
/**
* Description.
* The handler for the touchend events.
* @method Phaser.Touch#onTouchEnd
* @param {Any} event
* @param {TouchEvent} event - The native event from the browser. This gets stored in Touch.event.
*/
onTouchEnd: function (event) {
this.event = event;
if (this.touchEndCallback)
{
this.touchEndCallback.call(this.callbackContext, event);

View file

@ -588,7 +588,7 @@ Phaser.Cache.prototype = {
*/
getFrame: function (key) {
if (this._images[key] && this._images[key].spriteSheet == false)
if (this._images[key] && this._images[key].spriteSheet === false)
{
return this._images[key].frame;
}
@ -692,7 +692,7 @@ Phaser.Cache.prototype = {
*/
isSoundReady: function (key) {
return (this._sounds[key] && this._sounds[key].decoded && this.game.sound.touchLocked == false);
return (this._sounds[key] && this._sounds[key].decoded && this.game.sound.touchLocked === false);
},

View file

@ -149,7 +149,7 @@ Phaser.Loader.prototype = {
this.preloadSprite = { sprite: sprite, direction: direction, width: sprite.width, height: sprite.height, crop: null };
if (direction == 0)
if (direction === 0)
{
// Horizontal crop
this.preloadSprite.crop = new Phaser.Rectangle(0, 0, 1, sprite.height);
@ -247,7 +247,7 @@ Phaser.Loader.prototype = {
if (typeof overwrite === "undefined") { overwrite = false; }
if (overwrite || this.checkKeyExists(key) == false)
if (overwrite || this.checkKeyExists(key) === false)
{
this.addToFileList('image', key, url);
}
@ -268,7 +268,7 @@ Phaser.Loader.prototype = {
if (typeof overwrite === "undefined") { overwrite = false; }
if (overwrite || this.checkKeyExists(key) == false)
if (overwrite || this.checkKeyExists(key) === false)
{
this.addToFileList('text', key, url);
}
@ -1085,7 +1085,7 @@ Phaser.Loader.prototype = {
if (this.preloadSprite !== null)
{
if (this.preloadSprite.direction == 0)
if (this.preloadSprite.direction === 0)
{
this.preloadSprite.crop.width = Math.floor((this.preloadSprite.width / 100) * this.progress);
}

View file

@ -134,7 +134,7 @@ Phaser.Math = {
if (typeof start === "undefined") { start = 0; }
if (gap == 0) {
if (gap === 0) {
return input;
}
@ -160,7 +160,7 @@ Phaser.Math = {
if (typeof start === "undefined") { start = 0; }
if (gap == 0) {
if (gap === 0) {
return input;
}
@ -186,7 +186,7 @@ Phaser.Math = {
if (typeof start === "undefined") { start = 0; }
if (gap == 0) {
if (gap === 0) {
return input;
}
@ -238,7 +238,7 @@ Phaser.Math = {
* e.g.
* 2000/7 ~= 285.714285714285714285714 ~= (bin)100011101.1011011011011011
*
* roundTo(2000/7,3) == 0
* roundTo(2000/7,3) === 0
* roundTo(2000/7,2) == 300
* roundTo(2000/7,1) == 290
* roundTo(2000/7,0) == 286
@ -844,7 +844,7 @@ Phaser.Math = {
var l = length;
if ((l == 0) || (l > objects.length - startIndex))
if ((l === 0) || (l > objects.length - startIndex))
{
l = objects.length - startIndex;
}
@ -972,7 +972,7 @@ Phaser.Math = {
* @param {number} x2
* @param {number} y2
* @return {number} The distance between this Point object and the destination Point object.
**/
*/
distance: function (x1, y1, x2, y2) {
var dx = x1 - x2;
@ -991,7 +991,7 @@ Phaser.Math = {
* @param {number} x2
* @param {number} y2
* @return {number} The distance between this Point object and the destination Point object.
**/
*/
distanceRounded: function (x1, y1, x2, y2) {
return Math.round(Phaser.Math.distance(x1, y1, x2, y2));

View file

@ -136,7 +136,7 @@ Phaser.Particles.Arcade.Emitter = function (game, x, y, maxParticles) {
this.angularDrag = 0;
/**
* How often a particle is emitted in ms (if emitter is started with Explode == false).
* How often a particle is emitted in ms (if emitter is started with Explode === false).
* @property {boolean} frequency
* @default
*/

View file

@ -104,7 +104,7 @@ GridBroadphase.prototype.getCollisionPairs = function(world){
}
} else if(si instanceof Plane){
// Put in all bins for now
if(bi.angle == 0){
if(bi.angle === 0){
var y = bi.position[1];
for(var j=0; j!==Nbins && ymin+binsizeY*(j-1)<y; j++){
for(var k=0; k<nx; k++){

View file

@ -194,7 +194,7 @@
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); }
iscs.sort(comp);
@ -226,7 +226,7 @@
ps = PolyK._getPoints(ps, ind1, ind0);
i0.flag = i1.flag = false;
iscs.splice(0,2);
if(iscs.length == 0) pgs.push(ps);
if(iscs.length === 0) pgs.push(ps);
}
else { dir++; iscs.reverse(); }
if(dir>1) break;
@ -402,7 +402,7 @@
var day = (a1.y-a2.y), dby = (b1.y-b2.y);
var Den = dax*dby - day*dbx;
if (Den == 0) return null; // parallel
if (Den === 0) return null; // parallel
var A = (a1.x * a2.y - a1.y * a2.x);
var B = (b1.x * b2.y - b1.y * b2.x);
@ -424,7 +424,7 @@
var day = (a1.y-a2.y), dby = (b1.y-b2.y);
var Den = dax*dby - day*dbx;
if (Den == 0) return null; // parallel
if (Den === 0) return null; // parallel
var A = (a1.x * a2.y - a1.y * a2.x);
var B = (b1.x * b2.y - b1.y * b2.x);

View file

@ -167,7 +167,7 @@ function Body(options){
* var kinematicBody = new Body();
* kinematicBody.motionState = Body.KINEMATIC;
*/
this.motionState = this.mass == 0 ? Body.STATIC : Body.DYNAMIC;
this.motionState = this.mass === 0 ? Body.STATIC : Body.DYNAMIC;
/**
* Bounding circle radius

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);
if (this._mapData.length == 0)
if (this._mapData.length === 0)
{
return;
}
@ -448,12 +448,12 @@ Phaser.Physics.Arcade.prototype = {
*/
collideGroupVsTilemapLayer: function (group, tilemapLayer, collideCallback, processCallback, callbackContext) {
if (group.length == 0)
if (group.length === 0)
{
return;
}
if (group.length == 0)
if (group.length === 0)
{
return;
}
@ -521,7 +521,7 @@ Phaser.Physics.Arcade.prototype = {
*/
collideSpriteVsGroup: function (sprite, group, collideCallback, processCallback, callbackContext) {
if (group.length == 0)
if (group.length === 0)
{
return;
}
@ -563,7 +563,7 @@ Phaser.Physics.Arcade.prototype = {
*/
collideGroupVsGroup: function (group1, group2, collideCallback, processCallback, callbackContext) {
if (group1.length == 0 || group2.length == 0)
if (group1.length === 0 || group2.length === 0)
{
return;
}
@ -620,7 +620,7 @@ Phaser.Physics.Arcade.prototype = {
{
this._maxOverlap = body1.deltaAbsX() + body2.deltaAbsX() + this.OVERLAP_BIAS;
if (body1.deltaX() == 0 && body2.deltaX() == 0)
if (body1.deltaX() === 0 && body2.deltaX() === 0)
{
// They overlap but neither of them are moving
body1.embedded = true;
@ -631,7 +631,7 @@ Phaser.Physics.Arcade.prototype = {
// Body1 is moving right and/or Body2 is moving left
this._overlap = body1.x + body1.width - body2.x;
if ((this._overlap > this._maxOverlap) || body1.allowCollision.right == false || body2.allowCollision.left == false)
if ((this._overlap > this._maxOverlap) || body1.allowCollision.right === false || body2.allowCollision.left === false)
{
this._overlap = 0;
}
@ -646,7 +646,7 @@ Phaser.Physics.Arcade.prototype = {
// Body1 is moving left and/or Body2 is moving right
this._overlap = body1.x - body2.width - body2.x;
if ((-this._overlap > this._maxOverlap) || body1.allowCollision.left == false || body2.allowCollision.right == false)
if ((-this._overlap > this._maxOverlap) || body1.allowCollision.left === false || body2.allowCollision.right === false)
{
this._overlap = 0;
}
@ -728,7 +728,7 @@ Phaser.Physics.Arcade.prototype = {
{
this._maxOverlap = body1.deltaAbsY() + body2.deltaAbsY() + this.OVERLAP_BIAS;
if (body1.deltaY() == 0 && body2.deltaY() == 0)
if (body1.deltaY() === 0 && body2.deltaY() === 0)
{
// They overlap but neither of them are moving
body1.embedded = true;
@ -739,7 +739,7 @@ Phaser.Physics.Arcade.prototype = {
// Body1 is moving down and/or Body2 is moving up
this._overlap = body1.y + body1.height - body2.y;
if ((this._overlap > this._maxOverlap) || body1.allowCollision.down == false || body2.allowCollision.up == false)
if ((this._overlap > this._maxOverlap) || body1.allowCollision.down === false || body2.allowCollision.up === false)
{
this._overlap = 0;
}
@ -754,7 +754,7 @@ Phaser.Physics.Arcade.prototype = {
// Body1 is moving up and/or Body2 is moving down
this._overlap = body1.y - body2.height - body2.y;
if ((-this._overlap > this._maxOverlap) || body1.allowCollision.up == false || body2.allowCollision.down == false)
if ((-this._overlap > this._maxOverlap) || body1.allowCollision.up === false || body2.allowCollision.down === false)
{
this._overlap = 0;
}
@ -852,7 +852,7 @@ Phaser.Physics.Arcade.prototype = {
separateTileX: function (body, tile, separate) {
// Can't separate two immovable objects (tiles are always immovable)
if (body.immovable || body.deltaX() == 0 || Phaser.Rectangle.intersects(body.hullX, tile) == false)
if (body.immovable || body.deltaX() === 0 || Phaser.Rectangle.intersects(body.hullX, tile) === false)
{
return false;
}
@ -867,8 +867,8 @@ Phaser.Physics.Arcade.prototype = {
// Moving left
this._overlap = tile.right - body.hullX.x;
// if ((this._overlap > this._maxOverlap) || body.allowCollision.left == false || tile.tile.collideRight == false)
if (body.allowCollision.left == false || tile.tile.collideRight == false)
// if ((this._overlap > this._maxOverlap) || body.allowCollision.left === false || tile.tile.collideRight === false)
if (body.allowCollision.left === false || tile.tile.collideRight === false)
{
this._overlap = 0;
}
@ -882,8 +882,8 @@ Phaser.Physics.Arcade.prototype = {
// Moving right
this._overlap = body.hullX.right - tile.x;
// if ((this._overlap > this._maxOverlap) || body.allowCollision.right == false || tile.tile.collideLeft == false)
if (body.allowCollision.right == false || tile.tile.collideLeft == false)
// if ((this._overlap > this._maxOverlap) || body.allowCollision.right === false || tile.tile.collideLeft === false)
if (body.allowCollision.right === false || tile.tile.collideLeft === false)
{
this._overlap = 0;
}
@ -907,7 +907,7 @@ Phaser.Physics.Arcade.prototype = {
body.x = body.x - this._overlap;
}
if (body.bounce.x == 0)
if (body.bounce.x === 0)
{
body.velocity.x = 0;
}
@ -938,7 +938,7 @@ Phaser.Physics.Arcade.prototype = {
separateTileY: function (body, tile, separate) {
// Can't separate two immovable objects (tiles are always immovable)
if (body.immovable || body.deltaY() == 0 || Phaser.Rectangle.intersects(body.hullY, tile) == false)
if (body.immovable || body.deltaY() === 0 || Phaser.Rectangle.intersects(body.hullY, tile) === false)
{
return false;
}
@ -953,8 +953,8 @@ Phaser.Physics.Arcade.prototype = {
// Moving up
this._overlap = tile.bottom - body.hullY.y;
// if ((this._overlap > this._maxOverlap) || body.allowCollision.up == false || tile.tile.collideDown == false)
if (body.allowCollision.up == false || tile.tile.collideDown == false)
// if ((this._overlap > this._maxOverlap) || body.allowCollision.up === false || tile.tile.collideDown === false)
if (body.allowCollision.up === false || tile.tile.collideDown === false)
{
this._overlap = 0;
}
@ -968,8 +968,8 @@ Phaser.Physics.Arcade.prototype = {
// Moving down
this._overlap = body.hullY.bottom - tile.y;
// if ((this._overlap > this._maxOverlap) || body.allowCollision.down == false || tile.tile.collideUp == false)
if (body.allowCollision.down == false || tile.tile.collideUp == false)
// if ((this._overlap > this._maxOverlap) || body.allowCollision.down === false || tile.tile.collideUp === false)
if (body.allowCollision.down === false || tile.tile.collideUp === false)
{
this._overlap = 0;
}
@ -993,7 +993,7 @@ Phaser.Physics.Arcade.prototype = {
body.y = body.y - this._overlap;
}
if (body.bounce.y == 0)
if (body.bounce.y === 0)
{
body.velocity.y = 0;
}

View file

@ -380,7 +380,7 @@ Phaser.Physics.Arcade.Body.prototype = {
this.updateHulls();
}
if (this.skipQuadTree == false && this.allowCollision.none == false && this.sprite.visible && this.sprite.alive)
if (this.skipQuadTree === false && this.allowCollision.none === false && this.sprite.visible && this.sprite.alive)
{
this.quadTreeIDs = [];
this.quadTreeIndex = -1;
@ -582,7 +582,7 @@ Object.defineProperty(Phaser.Physics.Arcade.Body.prototype, "bottom", {
* The sum of the y and height properties. Changing the bottom property of a Rectangle object has no effect on the x, y and width properties, but does change the height property.
* @method bottom
* @return {number}
**/
*/
get: function () {
return this.y + this.height;
},
@ -591,7 +591,7 @@ Object.defineProperty(Phaser.Physics.Arcade.Body.prototype, "bottom", {
* The sum of the y and height properties. Changing the bottom property of a Rectangle object has no effect on the x, y and width properties, but does change the height property.
* @method bottom
* @param {number} value
**/
*/
set: function (value) {
if (value <= this.y)
@ -618,7 +618,7 @@ Object.defineProperty(Phaser.Physics.Arcade.Body.prototype, "right", {
* However it does affect the width property.
* @method right
* @return {number}
**/
*/
get: function () {
return this.x + this.width;
},
@ -628,7 +628,7 @@ Object.defineProperty(Phaser.Physics.Arcade.Body.prototype, "right", {
* However it does affect the width property.
* @method right
* @param {number} value
**/
*/
set: function (value) {
if (value <= this.x)

View file

@ -166,7 +166,7 @@ PIXI.DisplayObjectContainer.prototype.addChildAt = function(child, index)
updateLast = updateLast.parent;
}
}
else if(index == 0)
else if(index === 0)
{
previousObject = this;
}

View file

@ -296,7 +296,7 @@ spine.Animation.prototype = {
spine.binarySearch = function (values, target, step) {
var low = 0;
var high = Math.floor(values.length / step) - 2;
if (high == 0) return step;
if (high === 0) return step;
var current = high >>> 1;
while (true) {
if (values[(current + 1) * step] <= target)
@ -368,7 +368,7 @@ spine.Curves.prototype = {
var lastY = y - dfy;
return lastY + (y - lastY) * (percent - lastX) / (x - lastX);
}
if (i == 0) break;
if (i === 0) break;
i--;
dfx += ddfx;
dfy += ddfy;
@ -711,7 +711,7 @@ spine.Skeleton.prototype = {
},
/** @return May return null. */
getRootBone: function () {
return this.bones.length == 0 ? null : this.bones[0];
return this.bones.length === 0 ? null : this.bones[0];
},
/** @return May be null. */
findBone: function (boneName) {
@ -983,7 +983,7 @@ spine.AnimationState.prototype = {
entry.loop = loop;
if (!delay || delay <= 0) {
var previousAnimation = this.queue.length == 0 ? this.current : this.queue[this.queue.length - 1].animation;
var previousAnimation = this.queue.length === 0 ? this.current : this.queue[this.queue.length - 1].animation;
if (previousAnimation != null)
delay = previousAnimation.duration - this.data.getMix(previousAnimation, animation) + (delay || 0);
else
@ -1232,7 +1232,7 @@ spine.Atlas = function (atlasText, textureLoader) {
var line = reader.readLine();
if (line == null) break;
line = reader.trim(line);
if (line.length == 0)
if (line.length === 0)
page = null;
else if (!page) {
page = new spine.AtlasPage();
@ -1421,7 +1421,7 @@ spine.AtlasReader.prototype = {
for (; i < 3; i++) {
var comma = line.indexOf(",", lastMatch);
if (comma == -1) {
if (i == 0) throw "Invalid line: " + line;
if (i === 0) throw "Invalid line: " + line;
break;
}
tuple[i] = this.trim(line.substr(lastMatch, comma - lastMatch));

View file

@ -29,25 +29,25 @@ PIXI.CrossHatchFilter = function()
" gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);",
" ",
" if (lum < 1.00) {",
" if (mod(gl_FragCoord.x + gl_FragCoord.y, 10.0) == 0.0) {",
" if (mod(gl_FragCoord.x + gl_FragCoord.y, 10.0) === 0.0) {",
" gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);",
" }",
" }",
" ",
" if (lum < 0.75) {",
" if (mod(gl_FragCoord.x - gl_FragCoord.y, 10.0) == 0.0) {",
" if (mod(gl_FragCoord.x - gl_FragCoord.y, 10.0) === 0.0) {",
" gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);",
" }",
" }",
" ",
" if (lum < 0.50) {",
" if (mod(gl_FragCoord.x + gl_FragCoord.y - 5.0, 10.0) == 0.0) {",
" if (mod(gl_FragCoord.x + gl_FragCoord.y - 5.0, 10.0) === 0.0) {",
" gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);",
" }",
" }",
" ",
" if (lum < 0.3) {",
" if (mod(gl_FragCoord.x - gl_FragCoord.y - 5.0, 10.0) == 0.0) {",
" if (mod(gl_FragCoord.x - gl_FragCoord.y - 5.0, 10.0) === 0.0) {",
" gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);",
" }",
" }",

View file

@ -113,7 +113,7 @@ PIXI.AssetLoader.prototype.onAssetLoaded = function()
this.dispatchEvent({type: "onProgress", content: this});
if(this.onProgress) this.onProgress();
if(this.loadCount == 0)
if(this.loadCount === 0)
{
this.dispatchEvent({type: "onComplete", content: this});
if(this.onComplete) this.onComplete();

View file

@ -75,7 +75,7 @@ PIXI.Graphics.prototype.constructor = PIXI.Graphics;
*/
PIXI.Graphics.prototype.lineStyle = function(lineWidth, color, alpha)
{
if(this.currentPath.points.length == 0)this.graphicsData.pop();
if(this.currentPath.points.length === 0)this.graphicsData.pop();
this.lineWidth = lineWidth || 0;
this.lineColor = color || 0;
@ -96,7 +96,7 @@ PIXI.Graphics.prototype.lineStyle = function(lineWidth, color, alpha)
*/
PIXI.Graphics.prototype.moveTo = function(x, y)
{
if(this.currentPath.points.length == 0)this.graphicsData.pop();
if(this.currentPath.points.length === 0)this.graphicsData.pop();
this.currentPath = this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha,
fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling, points:[], type:PIXI.Graphics.POLY};
@ -157,7 +157,7 @@ PIXI.Graphics.prototype.endFill = function()
*/
PIXI.Graphics.prototype.drawRect = function( x, y, width, height )
{
if(this.currentPath.points.length == 0)this.graphicsData.pop();
if(this.currentPath.points.length === 0)this.graphicsData.pop();
this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha,
fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling,
@ -177,7 +177,7 @@ PIXI.Graphics.prototype.drawRect = function( x, y, width, height )
*/
PIXI.Graphics.prototype.drawCircle = function( x, y, radius)
{
if(this.currentPath.points.length == 0)this.graphicsData.pop();
if(this.currentPath.points.length === 0)this.graphicsData.pop();
this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha,
fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling,
@ -198,7 +198,7 @@ PIXI.Graphics.prototype.drawCircle = function( x, y, radius)
*/
PIXI.Graphics.prototype.drawElipse = function( x, y, width, height)
{
if(this.currentPath.points.length == 0)this.graphicsData.pop();
if(this.currentPath.points.length === 0)this.graphicsData.pop();
this.currentPath = {lineWidth:this.lineWidth, lineColor:this.lineColor, lineAlpha:this.lineAlpha,
fillColor:this.fillColor, fillAlpha:this.fillAlpha, fill:this.filling,

View file

@ -9,7 +9,7 @@ PIXI._batchs = [];
*/
PIXI._getBatch = function(gl)
{
if(PIXI._batchs.length == 0)
if(PIXI._batchs.length === 0)
{
return new PIXI.WebGLBatch(gl);
}
@ -189,7 +189,7 @@ PIXI.WebGLBatch.prototype.remove = function(sprite)
{
this.size--;
if(this.size == 0)
if(this.size === 0)
{
sprite.batch = null;
sprite.__prev = null;
@ -522,7 +522,7 @@ PIXI.WebGLBatch.prototype.render = function(start, end)
this.dirty = false;
}
if (this.size == 0)return;
if (this.size === 0)return;
this.update();
var gl = this.gl;

View file

@ -280,7 +280,7 @@ PIXI.WebGLGraphics.buildLine = function(graphicsData, webGLData)
var wrap = true;
var points = graphicsData.points;
if(points.length == 0)return;
if(points.length === 0)return;
// if the line width is an odd number add 0.5 to align to a whole pixel
if(graphicsData.lineWidth%2)

View file

@ -775,7 +775,7 @@ PIXI.WebGLRenderGroup.prototype.removeObject = function(displayObject)
// ok so.. check to see if you adjacent batchs should be joined.
// TODO may optimise?
if(index == 0 || index == this.batchs.length-1)
if(index === 0 || index == this.batchs.length-1)
{
// wha - eva! just get of the empty batch!
this.batchs.splice(index, 1);
@ -848,7 +848,7 @@ PIXI.WebGLRenderGroup.prototype.initTilingSprite = function(sprite)
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, sprite._indexBuffer);
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, sprite.indices, gl.STATIC_DRAW);
// return ( (x > 0) && ((x & (x - 1)) == 0) );
// return ( (x > 0) && ((x & (x - 1)) === 0) );
if(sprite.texture.baseTexture._glTexture)
{

View file

@ -111,7 +111,7 @@ PIXI.WebGLRenderer.prototype.constructor = PIXI.WebGLRenderer;
*/
PIXI.WebGLRenderer.getBatch = function()
{
if(PIXI._batchs.length == 0)
if(PIXI._batchs.length === 0)
{
return new PIXI.WebGLBatch(PIXI.WebGLRenderer.gl);
}

View file

@ -432,7 +432,7 @@ Phaser.Sound.prototype = {
// console.log(this.name + ' play ' + marker + ' position ' + position + ' volume ' + volume + ' loop ' + loop, 'force', forceRestart);
if (this.isPlaying == true && forceRestart == false && this.override == false)
if (this.isPlaying === true && forceRestart === false && this.override === false)
{
// Use Restart instead
return;
@ -517,7 +517,7 @@ Phaser.Sound.prototype = {
this._sound.connect(this.gainNode);
this.totalDuration = this._sound.buffer.duration;
if (this.duration == 0)
if (this.duration === 0)
{
// console.log('duration reset');
this.duration = this.totalDuration;
@ -552,7 +552,7 @@ Phaser.Sound.prototype = {
{
this.pendingPlayback = true;
if (this.game.cache.getSound(this.key) && this.game.cache.getSound(this.key).isDecoding == false)
if (this.game.cache.getSound(this.key) && this.game.cache.getSound(this.key).isDecoding === false)
{
this.game.sound.decode(this.key, this);
}
@ -576,7 +576,7 @@ Phaser.Sound.prototype = {
// This doesn't become available until you call play(), wonderful ...
this.totalDuration = this._sound.duration;
if (this.duration == 0)
if (this.duration === 0)
{
this.duration = this.totalDuration;
this.durationMS = this.totalDuration * 1000;

View file

@ -101,7 +101,7 @@ Phaser.SoundManager.prototype = {
*/
boot: function () {
if (this.game.device.iOS && this.game.device.webAudio == false)
if (this.game.device.iOS && this.game.device.webAudio === false)
{
this.channels = 1;
}
@ -123,7 +123,7 @@ Phaser.SoundManager.prototype = {
if (window['PhaserGlobal'])
{
// Check to see if all audio playback is disabled (i.e. handled by a 3rd party class)
if (window['PhaserGlobal'].disableAudio == true)
if (window['PhaserGlobal'].disableAudio === true)
{
this.usingWebAudio = false;
this.noAudio = true;
@ -131,7 +131,7 @@ Phaser.SoundManager.prototype = {
}
// Check if the Web Audio API is disabled (for testing Audio Tag playback during development)
if (window['PhaserGlobal'].disableWebAudio == true)
if (window['PhaserGlobal'].disableWebAudio === true)
{
this.usingWebAudio = false;
this.usingAudioTag = true;
@ -183,13 +183,13 @@ Phaser.SoundManager.prototype = {
*/
unlock: function () {
if (this.touchLocked == false)
if (this.touchLocked === false)
{
return;
}
// Global override (mostly for Audio Tag testing)
if (this.game.device.webAudio == false || (window['PhaserGlobal'] && window['PhaserGlobal'].disableWebAudio == true))
if (this.game.device.webAudio === false || (window['PhaserGlobal'] && window['PhaserGlobal'].disableWebAudio === true))
{
// Create an Audio tag?
this.touchLocked = false;
@ -404,7 +404,7 @@ Object.defineProperty(Phaser.SoundManager.prototype, "mute", {
}
else
{
if (this._muted == false)
if (this._muted === false)
{
return;
}

View file

@ -348,7 +348,7 @@ Phaser.StageScaleMode.prototype = {
if (typeof orientationImage !== 'undefined')
{
if (orientationImage == null || this.game.cache.checkImageKey(orientationImage) == false)
if (orientationImage == null || this.game.cache.checkImageKey(orientationImage) === false)
{
orientationImage = '__default';
}
@ -411,7 +411,7 @@ Phaser.StageScaleMode.prototype = {
this.incorrectOrientation = true;
this.enterIncorrectOrientation.dispatch();
if (this.orientationSprite && this.orientationSprite.visible == false)
if (this.orientationSprite && this.orientationSprite.visible === false)
{
this.orientationSprite.visible = true;
this.game.world.visible = false;
@ -488,9 +488,9 @@ Phaser.StageScaleMode.prototype = {
refresh: function () {
// We can't do anything about the status bars in iPads, web apps or desktops
if (this.game.device.iPad == false && this.game.device.webApp == false && this.game.device.desktop == false)
if (this.game.device.iPad === false && this.game.device.webApp === false && this.game.device.desktop === false)
{
if (this.game.device.android && this.game.device.chrome == false)
if (this.game.device.android && this.game.device.chrome === false)
{
window.scrollTo(0, 1);
}
@ -526,9 +526,9 @@ Phaser.StageScaleMode.prototype = {
force = false;
}
if (this.game.device.iPad == false && this.game.device.webApp == false && this.game.device.desktop == false)
if (this.game.device.iPad === false && this.game.device.webApp === false && this.game.device.desktop === false)
{
if (this.game.device.android && this.game.device.chrome == false)
if (this.game.device.android && this.game.device.chrome === false)
{
window.scrollTo(0, 1);
}
@ -545,7 +545,7 @@ Phaser.StageScaleMode.prototype = {
// Set minimum height of content to new window height
document.documentElement['style'].minHeight = window.innerHeight + 'px';
if (this.incorrectOrientation == true)
if (this.incorrectOrientation === true)
{
this.setMaximum();
}
@ -571,7 +571,7 @@ Phaser.StageScaleMode.prototype = {
*/
setSize: function () {
if (this.incorrectOrientation == false)
if (this.incorrectOrientation === false)
{
if (this.maxWidth && this.width > this.maxWidth)
{
@ -601,7 +601,7 @@ Phaser.StageScaleMode.prototype = {
if (this.pageAlignHorizontally)
{
if (this.width < window.innerWidth && this.incorrectOrientation == false)
if (this.width < window.innerWidth && this.incorrectOrientation === false)
{
this.margin.x = Math.round((window.innerWidth - this.width) / 2);
this.game.canvas.style.marginLeft = this.margin.x + 'px';
@ -615,7 +615,7 @@ Phaser.StageScaleMode.prototype = {
if (this.pageAlignVertically)
{
if (this.height < window.innerHeight && this.incorrectOrientation == false)
if (this.height < window.innerHeight && this.incorrectOrientation === false)
{
this.margin.y = Math.round((window.innerHeight - this.height) / 2);
this.game.canvas.style.marginTop = this.margin.y + 'px';
@ -723,7 +723,7 @@ Object.defineProperty(Phaser.StageScaleMode.prototype, "isFullScreen", {
Object.defineProperty(Phaser.StageScaleMode.prototype, "isPortrait", {
get: function () {
return this.orientation == 0 || this.orientation == 180;
return this.orientation === 0 || this.orientation == 180;
}
});

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.
* @method bottom
* @return {number}
**/
*/
get: function () {
return this.y + this.height;
}
@ -205,7 +205,7 @@ Object.defineProperty(Phaser.Tile.prototype, "right", {
* However it does affect the width property.
* @method right
* @return {number}
**/
*/
get: function () {
return this.x + this.width;
}

View file

@ -433,7 +433,7 @@ Phaser.TilemapLayer.prototype.getTiles = function (x, y, width, height, collides
sx = _tile.width * this.scale.x;
sy = _tile.height * this.scale.y;
if (collides == false || (collides && _tile.collideNone == false))
if (collides === false || (collides && _tile.collideNone === false))
{
// convert tile coordinates back to camera space for return
var _wx = this._unfixX( wx*sx ) / tileWidth;

View file

@ -34,7 +34,7 @@ Phaser.TilemapParser = {
}
// Zero or smaller than tile sizes?
if (width == 0 || height == 0 || width < tileWidth || height < tileHeight || total === 0)
if (width === 0 || height === 0 || width < tileWidth || height < tileHeight || total === 0)
{
console.warn("Phaser.TilemapParser.tileSet: width/height zero or width/height < given tileWidth/tileHeight");
return null;
@ -103,7 +103,7 @@ Phaser.TilemapParser = {
output[i][c] = parseInt(column[c]);
}
if (width == 0)
if (width === 0)
{
width = column.length;
}
@ -155,7 +155,7 @@ Phaser.TilemapParser = {
for (var t = 0; t < json.layers[i].data.length; t++)
{
if (c == 0)
if (c === 0)
{
row = [];
}

View file

@ -98,7 +98,7 @@ Phaser.Timer.prototype = {
for (var i = 0, len = this.events.length; i < len; i++)
{
if (this.events[i].dispatched == false && seconds >= this.events[i].delay)
if (this.events[i].dispatched === false && seconds >= this.events[i].delay)
{
this.events[i].dispatched = true;
// this.events[i].callback.apply(this.events[i].callbackContext, this.events[i].args);

View file

@ -326,7 +326,7 @@ Phaser.Utils.Debug.prototype = {
upColor = upColor || 'rgba(255,0,0,0.5)';
color = color || 'rgb(255,255,255)';
if (hideIfUp == true && pointer.isUp == true)
if (hideIfUp === true && pointer.isUp === true)
{
return;
}