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
+60 -73
View File
@@ -5,32 +5,32 @@
*/
/**
* Constructor for Phaser Input.
* Phaser.Input is the Input Manager for all types of Input across Phaser, including mouse, keyboard, touch and MSPointer.
* The Input manager is updated automatically by the core game loop.
*
* @class Phaser.Input
* @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;
}
});
+246 -247
View File
@@ -5,131 +5,129 @@
*/
/**
* Constructor for Phaser InputHandler.
* The Input Handler is bound to a specific Sprite and is responsible for managing all Input events on that Sprite.
* @class Phaser.InputHandler
* @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
*/
+69 -69
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));
}
+38 -39
View File
@@ -5,36 +5,35 @@
*/
/**
* Phaser - Keyboard constructor.
* The Keyboard class handles looking after keyboard input for your game. It will recognise and respond to key presses and dispatch the required events.
*
* @class Phaser.Keyboard
* @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;
}
+33 -48
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);
}
};
+66 -73
View File
@@ -5,98 +5,90 @@
*/
/**
* Phaser - Mouse constructor.
* Phaser.Mouse is responsible for handling all aspects of mouse interaction with the browser. It captures and processes mouse events.
*
* @class Phaser.Mouse
* @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
*/
+70 -100
View File
@@ -11,192 +11,167 @@
* @classdesc A Pointer object is used by the Mouse, Touch and MSPoint managers and represents a single finger on the touch screen.
* @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;
}
+75 -27
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);