mirror of
https://github.com/wassname/phaser.git
synced 2026-09-09 11:28:47 +08:00
Tidying up and trying to fix more stupid TypeScript errors.
This commit is contained in:
@@ -1,608 +0,0 @@
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
/// <reference path="../_definitions.ts" />
|
||||
/**
|
||||
* Phaser - Components - InputHandler
|
||||
*
|
||||
* Input detection component
|
||||
*/
|
||||
(function (Components) {
|
||||
var InputHandler = (function () {
|
||||
/**
|
||||
* Sprite Input component constructor
|
||||
* @param parent The Sprite using this Input component
|
||||
*/
|
||||
function InputHandler(parent) {
|
||||
/**
|
||||
* The PriorityID controls which Sprite receives an Input event first if they should overlap.
|
||||
*/
|
||||
this.priorityID = 0;
|
||||
/**
|
||||
* The index of this Input component entry in the Game.Input manager.
|
||||
*/
|
||||
this.indexID = 0;
|
||||
this.isDragged = false;
|
||||
this.dragPixelPerfect = false;
|
||||
this.allowHorizontalDrag = true;
|
||||
this.allowVerticalDrag = true;
|
||||
this.bringToTop = false;
|
||||
this.snapOnDrag = false;
|
||||
this.snapOnRelease = false;
|
||||
this.snapX = 0;
|
||||
this.snapY = 0;
|
||||
/**
|
||||
* Is this sprite allowed to be dragged by the mouse? true = yes, false = no
|
||||
* @default false
|
||||
*/
|
||||
this.draggable = false;
|
||||
/**
|
||||
* A region of the game world within which the sprite is restricted during drag
|
||||
* @default null
|
||||
*/
|
||||
this.boundsRect = null;
|
||||
/**
|
||||
* An Sprite the bounds of which this sprite is restricted during drag
|
||||
* @default null
|
||||
*/
|
||||
this.boundsSprite = null;
|
||||
/**
|
||||
* If this object is set to consume the pointer event then it will stop all propogation from this object on.
|
||||
* For example if you had a stack of 6 sprites with the same priority IDs and one consumed the event, none of the others would receive it.
|
||||
* @type {Boolean}
|
||||
*/
|
||||
this.consumePointerEvent = false;
|
||||
this.game = parent.game;
|
||||
this._parent = parent;
|
||||
this.enabled = false;
|
||||
}
|
||||
/**
|
||||
* 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.
|
||||
* @type {number}
|
||||
*/
|
||||
InputHandler.prototype.pointerX = function (pointer) {
|
||||
if (typeof pointer === "undefined") { 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.
|
||||
* @type {number}
|
||||
*/
|
||||
InputHandler.prototype.pointerY = function (pointer) {
|
||||
if (typeof pointer === "undefined") { 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
|
||||
* @property isDown
|
||||
* @type {Boolean}
|
||||
**/
|
||||
InputHandler.prototype.pointerDown = function (pointer) {
|
||||
if (typeof pointer === "undefined") { 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
|
||||
* @property isUp
|
||||
* @type {Boolean}
|
||||
**/
|
||||
InputHandler.prototype.pointerUp = function (pointer) {
|
||||
if (typeof pointer === "undefined") { pointer = 0; }
|
||||
return this._pointerData[pointer].isUp;
|
||||
};
|
||||
|
||||
/**
|
||||
* A timestamp representing when the Pointer first touched the touchscreen.
|
||||
* @property timeDown
|
||||
* @type {Number}
|
||||
**/
|
||||
InputHandler.prototype.pointerTimeDown = function (pointer) {
|
||||
if (typeof pointer === "undefined") { pointer = 0; }
|
||||
return this._pointerData[pointer].timeDown;
|
||||
};
|
||||
|
||||
/**
|
||||
* A timestamp representing when the Pointer left the touchscreen.
|
||||
* @property timeUp
|
||||
* @type {Number}
|
||||
**/
|
||||
InputHandler.prototype.pointerTimeUp = function (pointer) {
|
||||
if (typeof pointer === "undefined") { pointer = 0; }
|
||||
return this._pointerData[pointer].timeUp;
|
||||
};
|
||||
|
||||
/**
|
||||
* Is the Pointer over this Sprite
|
||||
* @property isOver
|
||||
* @type {Boolean}
|
||||
**/
|
||||
InputHandler.prototype.pointerOver = function (pointer) {
|
||||
if (typeof pointer === "undefined") { pointer = 0; }
|
||||
return this._pointerData[pointer].isOver;
|
||||
};
|
||||
|
||||
/**
|
||||
* Is the Pointer outside of this Sprite
|
||||
* @property isOut
|
||||
* @type {Boolean}
|
||||
**/
|
||||
InputHandler.prototype.pointerOut = function (pointer) {
|
||||
if (typeof pointer === "undefined") { pointer = 0; }
|
||||
return this._pointerData[pointer].isOut;
|
||||
};
|
||||
|
||||
/**
|
||||
* A timestamp representing when the Pointer first touched the touchscreen.
|
||||
* @property timeDown
|
||||
* @type {Number}
|
||||
**/
|
||||
InputHandler.prototype.pointerTimeOver = function (pointer) {
|
||||
if (typeof pointer === "undefined") { pointer = 0; }
|
||||
return this._pointerData[pointer].timeOver;
|
||||
};
|
||||
|
||||
/**
|
||||
* A timestamp representing when the Pointer left the touchscreen.
|
||||
* @property timeUp
|
||||
* @type {Number}
|
||||
**/
|
||||
InputHandler.prototype.pointerTimeOut = function (pointer) {
|
||||
if (typeof pointer === "undefined") { pointer = 0; }
|
||||
return this._pointerData[pointer].timeOut;
|
||||
};
|
||||
|
||||
/**
|
||||
* Is this sprite being dragged by the mouse or not?
|
||||
* @default false
|
||||
*/
|
||||
InputHandler.prototype.pointerDragged = function (pointer) {
|
||||
if (typeof pointer === "undefined") { pointer = 0; }
|
||||
return this._pointerData[pointer].isDragged;
|
||||
};
|
||||
|
||||
InputHandler.prototype.start = function (priority, checkBody, useHandCursor) {
|
||||
if (typeof priority === "undefined") { priority = 0; }
|
||||
if (typeof checkBody === "undefined") { checkBody = false; }
|
||||
if (typeof useHandCursor === "undefined") { useHandCursor = false; }
|
||||
if (this.enabled == false) {
|
||||
// Register, etc
|
||||
this.checkBody = checkBody;
|
||||
this.useHandCursor = useHandCursor;
|
||||
this.priorityID = priority;
|
||||
|
||||
this._pointerData = [];
|
||||
|
||||
for (var i = 0; i < 10; i++) {
|
||||
this._pointerData.push({ id: i, x: 0, y: 0, isDown: false, isUp: false, isOver: false, isOut: false, timeOver: 0, timeOut: 0, timeDown: 0, timeUp: 0, downDuration: 0, isDragged: false });
|
||||
}
|
||||
|
||||
this.snapOffset = new Phaser.Point();
|
||||
this.enabled = true;
|
||||
|
||||
this.game.input.addGameObject(this._parent);
|
||||
|
||||
if (this._parent.events.onInputOver == null) {
|
||||
this._parent.events.onInputOver = new Phaser.Signal();
|
||||
this._parent.events.onInputOut = new Phaser.Signal();
|
||||
this._parent.events.onInputDown = new Phaser.Signal();
|
||||
this._parent.events.onInputUp = new Phaser.Signal();
|
||||
this._parent.events.onDragStart = new Phaser.Signal();
|
||||
this._parent.events.onDragStop = new Phaser.Signal();
|
||||
}
|
||||
}
|
||||
|
||||
return this._parent;
|
||||
};
|
||||
|
||||
InputHandler.prototype.reset = function () {
|
||||
this.enabled = false;
|
||||
|
||||
for (var i = 0; i < 10; i++) {
|
||||
this._pointerData[i] = { id: i, x: 0, y: 0, isDown: false, isUp: false, isOver: false, isOut: false, timeOver: 0, timeOut: 0, timeDown: 0, timeUp: 0, downDuration: 0, isDragged: false };
|
||||
}
|
||||
};
|
||||
|
||||
InputHandler.prototype.stop = function () {
|
||||
if (this.enabled == false) {
|
||||
return;
|
||||
} else {
|
||||
// De-register, etc
|
||||
this.enabled = false;
|
||||
this.game.input.removeGameObject(this.indexID);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Clean up memory.
|
||||
*/
|
||||
InputHandler.prototype.destroy = function () {
|
||||
if (this.enabled) {
|
||||
this.enabled = false;
|
||||
this.game.input.removeGameObject(this.indexID);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks if the given pointer is over this Sprite. All checks are done in world coordinates.
|
||||
*/
|
||||
InputHandler.prototype.checkPointerOver = function (pointer) {
|
||||
if (this.enabled == false || this._parent.visible == false) {
|
||||
return false;
|
||||
} else {
|
||||
return Phaser.SpriteUtils.overlapsXY(this._parent, pointer.worldX, pointer.worldY);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Update
|
||||
*/
|
||||
InputHandler.prototype.update = function (pointer) {
|
||||
if (this.enabled == false || this._parent.visible == false) {
|
||||
this._pointerOutHandler(pointer);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.draggable && this._draggedPointerID == pointer.id) {
|
||||
return this.updateDrag(pointer);
|
||||
} else if (this._pointerData[pointer.id].isOver == true) {
|
||||
if (Phaser.SpriteUtils.overlapsXY(this._parent, pointer.worldX, pointer.worldY)) {
|
||||
this._pointerData[pointer.id].x = pointer.x - this._parent.x;
|
||||
this._pointerData[pointer.id].y = pointer.y - this._parent.y;
|
||||
return true;
|
||||
} else {
|
||||
this._pointerOutHandler(pointer);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
InputHandler.prototype._pointerOverHandler = function (pointer) {
|
||||
if (this._pointerData[pointer.id].isOver == false) {
|
||||
this._pointerData[pointer.id].isOver = true;
|
||||
this._pointerData[pointer.id].isOut = false;
|
||||
this._pointerData[pointer.id].timeOver = this.game.time.now;
|
||||
this._pointerData[pointer.id].x = pointer.x - this._parent.x;
|
||||
this._pointerData[pointer.id].y = pointer.y - this._parent.y;
|
||||
|
||||
if (this.useHandCursor && this._pointerData[pointer.id].isDragged == false) {
|
||||
this.game.stage.canvas.style.cursor = "pointer";
|
||||
}
|
||||
|
||||
this._parent.events.onInputOver.dispatch(this._parent, pointer);
|
||||
}
|
||||
};
|
||||
|
||||
InputHandler.prototype._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) {
|
||||
this.game.stage.canvas.style.cursor = "default";
|
||||
}
|
||||
|
||||
this._parent.events.onInputOut.dispatch(this._parent, pointer);
|
||||
};
|
||||
|
||||
InputHandler.prototype._touchedHandler = function (pointer) {
|
||||
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;
|
||||
this._pointerData[pointer.id].timeDown = this.game.time.now;
|
||||
|
||||
//console.log('touchedHandler: ' + Date.now());
|
||||
this._parent.events.onInputDown.dispatch(this._parent, pointer);
|
||||
|
||||
if (this.draggable && this.isDragged == false) {
|
||||
this.startDrag(pointer);
|
||||
}
|
||||
|
||||
if (this.bringToTop) {
|
||||
this._parent.bringToTop();
|
||||
//this._parent.game.world.group.bringToTop(this._parent);
|
||||
}
|
||||
}
|
||||
|
||||
// Consume the event?
|
||||
return this.consumePointerEvent;
|
||||
};
|
||||
|
||||
InputHandler.prototype._releasedHandler = function (pointer) {
|
||||
if (this._pointerData[pointer.id].isDown && pointer.isUp) {
|
||||
this._pointerData[pointer.id].isDown = false;
|
||||
this._pointerData[pointer.id].isUp = true;
|
||||
this._pointerData[pointer.id].timeUp = this.game.time.now;
|
||||
this._pointerData[pointer.id].downDuration = this._pointerData[pointer.id].timeUp - this._pointerData[pointer.id].timeDown;
|
||||
|
||||
if (Phaser.SpriteUtils.overlapsXY(this._parent, pointer.worldX, pointer.worldY)) {
|
||||
//console.log('releasedHandler: ' + Date.now());
|
||||
this._parent.events.onInputUp.dispatch(this._parent, pointer);
|
||||
} else {
|
||||
if (this.useHandCursor) {
|
||||
this.game.stage.canvas.style.cursor = "default";
|
||||
}
|
||||
}
|
||||
|
||||
if (this.draggable && this.isDragged && this._draggedPointerID == pointer.id) {
|
||||
this.stopDrag(pointer);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the Pointer drag on this Sprite.
|
||||
*/
|
||||
InputHandler.prototype.updateDrag = function (pointer) {
|
||||
if (pointer.isUp) {
|
||||
this.stopDrag(pointer);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.allowHorizontalDrag) {
|
||||
this._parent.x = pointer.x + this._dragPoint.x + this.dragOffset.x;
|
||||
}
|
||||
|
||||
if (this.allowVerticalDrag) {
|
||||
this._parent.y = pointer.y + this._dragPoint.y + this.dragOffset.y;
|
||||
}
|
||||
|
||||
if (this.boundsRect) {
|
||||
this.checkBoundsRect();
|
||||
}
|
||||
|
||||
if (this.boundsSprite) {
|
||||
this.checkBoundsSprite();
|
||||
}
|
||||
|
||||
if (this.snapOnDrag) {
|
||||
this._parent.x = Math.floor(this._parent.x / this.snapX) * this.snapX;
|
||||
this._parent.y = Math.floor(this._parent.y / this.snapY) * this.snapY;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns true if the pointer has entered the Sprite within the specified delay time (defaults to 500ms, half a second)
|
||||
* @param delay The time below which the pointer is considered as just over.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
InputHandler.prototype.justOver = function (pointer, delay) {
|
||||
if (typeof pointer === "undefined") { pointer = 0; }
|
||||
if (typeof delay === "undefined") { 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)
|
||||
* @param delay The time below which the pointer is considered as just out.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
InputHandler.prototype.justOut = function (pointer, delay) {
|
||||
if (typeof pointer === "undefined") { pointer = 0; }
|
||||
if (typeof delay === "undefined") { 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)
|
||||
* @param delay The time below which the pointer is considered as just over.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
InputHandler.prototype.justPressed = function (pointer, delay) {
|
||||
if (typeof pointer === "undefined") { pointer = 0; }
|
||||
if (typeof delay === "undefined") { 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)
|
||||
* @param delay The time below which the pointer is considered as just out.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
InputHandler.prototype.justReleased = function (pointer, delay) {
|
||||
if (typeof pointer === "undefined") { pointer = 0; }
|
||||
if (typeof delay === "undefined") { 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.
|
||||
* @returns {number} The number of milliseconds the pointer has been over the Sprite, or -1 if not over.
|
||||
*/
|
||||
InputHandler.prototype.overDuration = function (pointer) {
|
||||
if (typeof pointer === "undefined") { pointer = 0; }
|
||||
if (this._pointerData[pointer].isOver) {
|
||||
return this.game.time.now - this._pointerData[pointer].timeOver;
|
||||
}
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
/**
|
||||
* If the pointer is currently over this Sprite this returns how long it has been there for in milliseconds.
|
||||
* @returns {number} The number of milliseconds the pointer has been pressed down on the Sprite, or -1 if not over.
|
||||
*/
|
||||
InputHandler.prototype.downDuration = function (pointer) {
|
||||
if (typeof pointer === "undefined") { pointer = 0; }
|
||||
if (this._pointerData[pointer].isDown) {
|
||||
return this.game.time.now - this._pointerData[pointer].timeDown;
|
||||
}
|
||||
|
||||
return -1;
|
||||
};
|
||||
|
||||
/**
|
||||
* Make this Sprite draggable by the mouse. You can also optionally set mouseStartDragCallback and mouseStopDragCallback
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
InputHandler.prototype.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; }
|
||||
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;
|
||||
this.bringToTop = bringToTop;
|
||||
|
||||
this.dragOffset = new Phaser.Point();
|
||||
this.dragFromCenter = lockCenter;
|
||||
this.dragPixelPerfect = pixelPerfect;
|
||||
this.dragPixelPerfectAlpha = alphaThreshold;
|
||||
|
||||
if (boundsRect) {
|
||||
this.boundsRect = boundsRect;
|
||||
}
|
||||
|
||||
if (boundsSprite) {
|
||||
this.boundsSprite = boundsSprite;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
InputHandler.prototype.disableDrag = function () {
|
||||
if (this._pointerData) {
|
||||
for (var i = 0; i < 10; i++) {
|
||||
this._pointerData[i].isDragged = false;
|
||||
}
|
||||
}
|
||||
|
||||
this.draggable = false;
|
||||
this.isDragged = false;
|
||||
this._draggedPointerID = -1;
|
||||
};
|
||||
|
||||
/**
|
||||
* Called by Pointer when drag starts on this Sprite. Should not usually be called directly.
|
||||
*/
|
||||
InputHandler.prototype.startDrag = function (pointer) {
|
||||
this.isDragged = true;
|
||||
this._draggedPointerID = pointer.id;
|
||||
this._pointerData[pointer.id].isDragged = true;
|
||||
|
||||
if (this.dragFromCenter) {
|
||||
this._parent.transform.centerOn(pointer.worldX, pointer.worldY);
|
||||
this._dragPoint.setTo(this._parent.x - pointer.x, this._parent.y - pointer.y);
|
||||
} else {
|
||||
this._dragPoint.setTo(this._parent.x - pointer.x, this._parent.y - pointer.y);
|
||||
}
|
||||
|
||||
this.updateDrag(pointer);
|
||||
|
||||
if (this.bringToTop) {
|
||||
this._parent.bringToTop();
|
||||
}
|
||||
|
||||
this._parent.events.onDragStart.dispatch(this._parent, pointer);
|
||||
};
|
||||
|
||||
/**
|
||||
* Called by Pointer when drag is stopped on this Sprite. Should not usually be called directly.
|
||||
*/
|
||||
InputHandler.prototype.stopDrag = function (pointer) {
|
||||
this.isDragged = false;
|
||||
this._draggedPointerID = -1;
|
||||
this._pointerData[pointer.id].isDragged = false;
|
||||
|
||||
if (this.snapOnRelease) {
|
||||
this._parent.x = Math.floor(this._parent.x / this.snapX) * this.snapX;
|
||||
this._parent.y = Math.floor(this._parent.y / this.snapY) * this.snapY;
|
||||
}
|
||||
|
||||
this._parent.events.onDragStop.dispatch(this._parent, pointer);
|
||||
this._parent.events.onInputUp.dispatch(this._parent, pointer);
|
||||
};
|
||||
|
||||
/**
|
||||
* Restricts this sprite to drag movement only on the given axis. Note: If both are set to false the sprite will never move!
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
InputHandler.prototype.setDragLock = function (allowHorizontal, allowVertical) {
|
||||
if (typeof allowHorizontal === "undefined") { allowHorizontal = 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.
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
InputHandler.prototype.enableSnap = function (snapX, snapY, onDrag, onRelease) {
|
||||
if (typeof onDrag === "undefined") { onDrag = true; }
|
||||
if (typeof onRelease === "undefined") { onRelease = false; }
|
||||
this.snapOnDrag = onDrag;
|
||||
this.snapOnRelease = onRelease;
|
||||
this.snapX = snapX;
|
||||
this.snapY = snapY;
|
||||
};
|
||||
|
||||
/**
|
||||
* Stops the sprite from snapping to a grid during drag or release.
|
||||
*/
|
||||
InputHandler.prototype.disableSnap = function () {
|
||||
this.snapOnDrag = false;
|
||||
this.snapOnRelease = false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Bounds Rect check for the sprite drag
|
||||
*/
|
||||
InputHandler.prototype.checkBoundsRect = function () {
|
||||
if (this._parent.x < this.boundsRect.left) {
|
||||
this._parent.x = this.boundsRect.x;
|
||||
} else if ((this._parent.x + this._parent.width) > this.boundsRect.right) {
|
||||
this._parent.x = this.boundsRect.right - this._parent.width;
|
||||
}
|
||||
|
||||
if (this._parent.y < this.boundsRect.top) {
|
||||
this._parent.y = this.boundsRect.top;
|
||||
} else if ((this._parent.y + this._parent.height) > this.boundsRect.bottom) {
|
||||
this._parent.y = this.boundsRect.bottom - this._parent.height;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Parent Sprite Bounds check for the sprite drag
|
||||
*/
|
||||
InputHandler.prototype.checkBoundsSprite = function () {
|
||||
if (this._parent.x < this.boundsSprite.x) {
|
||||
this._parent.x = this.boundsSprite.x;
|
||||
} else if ((this._parent.x + this._parent.width) > (this.boundsSprite.x + this.boundsSprite.width)) {
|
||||
this._parent.x = (this.boundsSprite.x + this.boundsSprite.width) - this._parent.width;
|
||||
}
|
||||
|
||||
if (this._parent.y < this.boundsSprite.y) {
|
||||
this._parent.y = this.boundsSprite.y;
|
||||
} else if ((this._parent.y + this._parent.height) > (this.boundsSprite.y + this.boundsSprite.height)) {
|
||||
this._parent.y = (this.boundsSprite.y + this.boundsSprite.height) - this._parent.height;
|
||||
}
|
||||
};
|
||||
return InputHandler;
|
||||
})();
|
||||
Components.InputHandler = InputHandler;
|
||||
})(Phaser.Components || (Phaser.Components = {}));
|
||||
var Components = Phaser.Components;
|
||||
})(Phaser || (Phaser = {}));
|
||||
@@ -1,661 +0,0 @@
|
||||
/// <reference path="../_definitions.ts" />
|
||||
/**
|
||||
* Phaser - InputManager
|
||||
*
|
||||
* A game specific Input manager that looks after the mouse, keyboard and touch objects.
|
||||
* This is updated by the core game loop.
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var InputManager = (function () {
|
||||
function InputManager(game) {
|
||||
/**
|
||||
* 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.
|
||||
* @type {number}
|
||||
*/
|
||||
this.pollRate = 0;
|
||||
this._pollCounter = 0;
|
||||
/**
|
||||
* A vector object representing the previous position of the Pointer.
|
||||
* @property vector
|
||||
* @type {Vec2}
|
||||
**/
|
||||
this._oldPosition = null;
|
||||
/**
|
||||
* X coordinate of the most recent Pointer event
|
||||
* @type {Number}
|
||||
* @private
|
||||
*/
|
||||
this._x = 0;
|
||||
/**
|
||||
* X coordinate of the most recent Pointer event
|
||||
* @type {Number}
|
||||
* @private
|
||||
*/
|
||||
this._y = 0;
|
||||
/**
|
||||
* You can disable all Input by setting Input.disabled = true. While set all new input related events will be ignored.
|
||||
* If you need to disable just one type of input, for example mouse, use Input.mouse.disabled = true instead
|
||||
* @type {Boolean}
|
||||
*/
|
||||
this.disabled = false;
|
||||
/**
|
||||
* Controls the expected behaviour when using a mouse and touch together on a multi-input device
|
||||
*/
|
||||
this.multiInputOverride = InputManager.MOUSE_TOUCH_COMBINE;
|
||||
/**
|
||||
* Phaser.Gestures handler
|
||||
* @type {Gestures}
|
||||
*/
|
||||
//public gestures: Gestures;
|
||||
/**
|
||||
* A vector object representing the current position of the Pointer.
|
||||
* @property vector
|
||||
* @type {Vec2}
|
||||
**/
|
||||
this.position = null;
|
||||
/**
|
||||
* A vector object representing the speed of the Pointer. Only really useful in single Pointer games,
|
||||
* otherwise see the Pointer objects directly.
|
||||
* @property vector
|
||||
* @type {Vec2}
|
||||
**/
|
||||
this.speed = null;
|
||||
/**
|
||||
* 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 circle
|
||||
* @type {Circle}
|
||||
**/
|
||||
this.circle = null;
|
||||
/**
|
||||
* 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.
|
||||
* @type {Vec2}
|
||||
*/
|
||||
this.scale = null;
|
||||
/**
|
||||
* The maximum number of Pointers allowed to be active at any one time.
|
||||
* For lots of games it's useful to set this to 1
|
||||
* @type {Number}
|
||||
*/
|
||||
this.maxPointers = 10;
|
||||
/**
|
||||
* The current number of active Pointers.
|
||||
* @type {Number}
|
||||
*/
|
||||
this.currentPointers = 0;
|
||||
/**
|
||||
* The number of milliseconds that the Pointer has to be pressed down and then released to be considered a tap or click
|
||||
* @property tapRate
|
||||
* @type {Number}
|
||||
**/
|
||||
this.tapRate = 200;
|
||||
/**
|
||||
* The number of milliseconds between taps of the same Pointer for it to be considered a double tap / click
|
||||
* @property doubleTapRate
|
||||
* @type {Number}
|
||||
**/
|
||||
this.doubleTapRate = 300;
|
||||
/**
|
||||
* The number of milliseconds that the Pointer has to be pressed down for it to fire a onHold event
|
||||
* @property holdRate
|
||||
* @type {Number}
|
||||
**/
|
||||
this.holdRate = 2000;
|
||||
/**
|
||||
* The number of milliseconds below which the Pointer is considered justPressed
|
||||
* @property justPressedRate
|
||||
* @type {Number}
|
||||
**/
|
||||
this.justPressedRate = 200;
|
||||
/**
|
||||
* The number of milliseconds below which the Pointer is considered justReleased
|
||||
* @property justReleasedRate
|
||||
* @type {Number}
|
||||
**/
|
||||
this.justReleasedRate = 200;
|
||||
/**
|
||||
* Sets if the Pointer objects should record a history of x/y coordinates they have passed through.
|
||||
* The history is cleared each time the Pointer is pressed down.
|
||||
* The history is updated at the rate specified in Input.pollRate
|
||||
* @property recordPointerHistory
|
||||
* @type {Boolean}
|
||||
**/
|
||||
this.recordPointerHistory = false;
|
||||
/**
|
||||
* The rate in milliseconds at which the Pointer objects should update their tracking history
|
||||
* @property recordRate
|
||||
* @type {Number}
|
||||
*/
|
||||
this.recordRate = 100;
|
||||
/**
|
||||
* The total number of entries that can be recorded into the Pointer objects tracking history.
|
||||
* If the Pointer is tracking one event every 100ms, then a trackLimit of 100 would store the last 10 seconds worth of history.
|
||||
* @property recordLimit
|
||||
* @type {Number}
|
||||
*/
|
||||
this.recordLimit = 100;
|
||||
/**
|
||||
* A Pointer object
|
||||
* @property pointer3
|
||||
* @type {Pointer}
|
||||
**/
|
||||
this.pointer3 = null;
|
||||
/**
|
||||
* A Pointer object
|
||||
* @property pointer4
|
||||
* @type {Pointer}
|
||||
**/
|
||||
this.pointer4 = null;
|
||||
/**
|
||||
* A Pointer object
|
||||
* @property pointer5
|
||||
* @type {Pointer}
|
||||
**/
|
||||
this.pointer5 = null;
|
||||
/**
|
||||
* A Pointer object
|
||||
* @property pointer6
|
||||
* @type {Pointer}
|
||||
**/
|
||||
this.pointer6 = null;
|
||||
/**
|
||||
* A Pointer object
|
||||
* @property pointer7
|
||||
* @type {Pointer}
|
||||
**/
|
||||
this.pointer7 = null;
|
||||
/**
|
||||
* A Pointer object
|
||||
* @property pointer8
|
||||
* @type {Pointer}
|
||||
**/
|
||||
this.pointer8 = null;
|
||||
/**
|
||||
* A Pointer object
|
||||
* @property pointer9
|
||||
* @type {Pointer}
|
||||
**/
|
||||
this.pointer9 = null;
|
||||
/**
|
||||
* A Pointer object
|
||||
* @property pointer10
|
||||
* @type {Pointer}
|
||||
**/
|
||||
this.pointer10 = null;
|
||||
/**
|
||||
* The most recently active Pointer object.
|
||||
* When you've limited max pointers to 1 this will accurately be either the first finger touched or mouse.
|
||||
* @property activePointer
|
||||
* @type {Pointer}
|
||||
**/
|
||||
this.activePointer = null;
|
||||
this.inputObjects = [];
|
||||
this.totalTrackedObjects = 0;
|
||||
this.game = game;
|
||||
|
||||
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.gestures = new Gestures(this.game);
|
||||
this.onDown = new Phaser.Signal();
|
||||
this.onUp = new Phaser.Signal();
|
||||
this.onTap = new Phaser.Signal();
|
||||
this.onHold = new Phaser.Signal();
|
||||
|
||||
this.scale = new Phaser.Vec2(1, 1);
|
||||
this.speed = new Phaser.Vec2();
|
||||
this.position = new Phaser.Vec2();
|
||||
this._oldPosition = new Phaser.Vec2();
|
||||
this.circle = new Phaser.Circle(0, 0, 44);
|
||||
|
||||
this.activePointer = this.mousePointer;
|
||||
this.currentPointers = 0;
|
||||
|
||||
this.hitCanvas = document.createElement('canvas');
|
||||
this.hitCanvas.width = 1;
|
||||
this.hitCanvas.height = 1;
|
||||
this.hitContext = this.hitCanvas.getContext('2d');
|
||||
}
|
||||
Object.defineProperty(InputManager.prototype, "camera", {
|
||||
get: /**
|
||||
* The camera being used for mouse and touch based pointers to calculate their world coordinates.
|
||||
* This is only ever the camera set by the most recently active Pointer.
|
||||
* If you need to know exactly which camera a specific Pointer is over then see Pointer.camera instead.
|
||||
* @property camera
|
||||
* @type {Camera}
|
||||
**/
|
||||
function () {
|
||||
return this.activePointer.camera;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
Object.defineProperty(InputManager.prototype, "x", {
|
||||
get: /**
|
||||
* The X coordinate of the most recently active pointer.
|
||||
* This value takes game scaling into account automatically. See Pointer.screenX/clientX for source values.
|
||||
* @property x
|
||||
* @type {Number}
|
||||
**/
|
||||
function () {
|
||||
return this._x;
|
||||
},
|
||||
set: function (value) {
|
||||
this._x = Math.floor(value);
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
|
||||
Object.defineProperty(InputManager.prototype, "y", {
|
||||
get: /**
|
||||
* The Y coordinate of the most recently active pointer.
|
||||
* This value takes game scaling into account automatically. See Pointer.screenY/clientY for source values.
|
||||
* @property y
|
||||
* @type {Number}
|
||||
**/
|
||||
function () {
|
||||
return this._y;
|
||||
},
|
||||
set: function (value) {
|
||||
this._y = Math.floor(value);
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Add a new Pointer object to the Input Manager. By default Input creates 2 pointer objects for you. If you need more
|
||||
* use this to create a new one, up to a maximum of 10.
|
||||
* @method addPointer
|
||||
* @return {Pointer} A reference to the new Pointer object
|
||||
**/
|
||||
InputManager.prototype.addPointer = function () {
|
||||
var next = 0;
|
||||
|
||||
for (var i = 10; i > 0; i--) {
|
||||
if (this['pointer' + i] === null) {
|
||||
next = i;
|
||||
}
|
||||
}
|
||||
|
||||
if (next == 0) {
|
||||
throw new Error("You can only have 10 Pointer objects");
|
||||
return null;
|
||||
} else {
|
||||
this['pointer' + next] = new Phaser.Pointer(this.game, next);
|
||||
return this['pointer' + next];
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Starts the Input Manager running
|
||||
* @method start
|
||||
**/
|
||||
InputManager.prototype.boot = function () {
|
||||
this.mouse.start();
|
||||
this.keyboard.start();
|
||||
this.touch.start();
|
||||
this.mspointer.start();
|
||||
|
||||
//this.gestures.start();
|
||||
this.mousePointer.active = true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds a new game object to be tracked by the Input Manager. Called by the Sprite.Input component, should not usually be called directly.
|
||||
* @method addGameObject
|
||||
**/
|
||||
InputManager.prototype.addGameObject = function (object) {
|
||||
for (var i = 0; i < this.inputObjects.length; i++) {
|
||||
if (this.inputObjects[i] == null) {
|
||||
this.inputObjects[i] = object;
|
||||
object.input.indexID = i;
|
||||
this.totalTrackedObjects++;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// If we got this far we need to push a new entry into the array
|
||||
object.input.indexID = this.inputObjects.length;
|
||||
|
||||
this.inputObjects.push(object);
|
||||
|
||||
this.totalTrackedObjects++;
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes a game object from the Input Manager. Called by the Sprite.Input component, should not usually be called directly.
|
||||
* @method removeGameObject
|
||||
**/
|
||||
InputManager.prototype.removeGameObject = function (index) {
|
||||
if (this.inputObjects[index]) {
|
||||
this.inputObjects[index] = null;
|
||||
}
|
||||
};
|
||||
|
||||
Object.defineProperty(InputManager.prototype, "pollLocked", {
|
||||
get: function () {
|
||||
return (this.pollRate > 0 && this._pollCounter < this.pollRate);
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
/**
|
||||
* Updates the Input Manager. Called by the core Game loop.
|
||||
* @method update
|
||||
**/
|
||||
InputManager.prototype.update = function () {
|
||||
if (this.pollRate > 0 && this._pollCounter < this.pollRate) {
|
||||
this._pollCounter++;
|
||||
return;
|
||||
}
|
||||
|
||||
this.speed.x = this.position.x - this._oldPosition.x;
|
||||
this.speed.y = this.position.y - this._oldPosition.y;
|
||||
|
||||
this._oldPosition.copyFrom(this.position);
|
||||
|
||||
this.mousePointer.update();
|
||||
this.pointer1.update();
|
||||
this.pointer2.update();
|
||||
|
||||
if (this.pointer3) {
|
||||
this.pointer3.update();
|
||||
}
|
||||
if (this.pointer4) {
|
||||
this.pointer4.update();
|
||||
}
|
||||
if (this.pointer5) {
|
||||
this.pointer5.update();
|
||||
}
|
||||
if (this.pointer6) {
|
||||
this.pointer6.update();
|
||||
}
|
||||
if (this.pointer7) {
|
||||
this.pointer7.update();
|
||||
}
|
||||
if (this.pointer8) {
|
||||
this.pointer8.update();
|
||||
}
|
||||
if (this.pointer9) {
|
||||
this.pointer9.update();
|
||||
}
|
||||
if (this.pointer10) {
|
||||
this.pointer10.update();
|
||||
}
|
||||
|
||||
this._pollCounter = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Reset all of the Pointers and Input states
|
||||
* @method reset
|
||||
* @param hard {Boolean} A soft reset (hard = false) won't reset any signals that might be bound. A hard reset will.
|
||||
**/
|
||||
InputManager.prototype.reset = function (hard) {
|
||||
if (typeof hard === "undefined") { hard = false; }
|
||||
this.keyboard.reset();
|
||||
|
||||
this.mousePointer.reset();
|
||||
|
||||
for (var i = 1; i <= 10; i++) {
|
||||
if (this['pointer' + i]) {
|
||||
this['pointer' + i].reset();
|
||||
}
|
||||
}
|
||||
|
||||
this.currentPointers = 0;
|
||||
|
||||
this.game.stage.canvas.style.cursor = "default";
|
||||
|
||||
if (hard == true) {
|
||||
this.onDown.dispose();
|
||||
this.onUp.dispose();
|
||||
this.onTap.dispose();
|
||||
this.onHold.dispose();
|
||||
|
||||
this.onDown = new Phaser.Signal();
|
||||
this.onUp = new Phaser.Signal();
|
||||
this.onTap = new Phaser.Signal();
|
||||
this.onHold = new Phaser.Signal();
|
||||
|
||||
for (var i = 0; i < this.totalTrackedObjects; i++) {
|
||||
if (this.inputObjects[i] && this.inputObjects[i].input) {
|
||||
this.inputObjects[i].input.reset();
|
||||
}
|
||||
}
|
||||
|
||||
this.inputObjects.length = 0;
|
||||
this.totalTrackedObjects = 0;
|
||||
}
|
||||
|
||||
this._pollCounter = 0;
|
||||
};
|
||||
|
||||
InputManager.prototype.resetSpeed = function (x, y) {
|
||||
this._oldPosition.setTo(x, y);
|
||||
this.speed.setTo(0, 0);
|
||||
};
|
||||
|
||||
Object.defineProperty(InputManager.prototype, "totalInactivePointers", {
|
||||
get: /**
|
||||
* Get the total number of inactive Pointers
|
||||
* @method totalInactivePointers
|
||||
* @return {Number} The number of Pointers currently inactive
|
||||
**/
|
||||
function () {
|
||||
return 10 - this.currentPointers;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
Object.defineProperty(InputManager.prototype, "totalActivePointers", {
|
||||
get: /**
|
||||
* Recalculates the total number of active Pointers
|
||||
* @method totalActivePointers
|
||||
* @return {Number} The number of Pointers currently active
|
||||
**/
|
||||
function () {
|
||||
this.currentPointers = 0;
|
||||
|
||||
for (var i = 1; i <= 10; i++) {
|
||||
if (this['pointer' + i] && this['pointer' + i].active) {
|
||||
this.currentPointers++;
|
||||
}
|
||||
}
|
||||
|
||||
return this.currentPointers;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
/**
|
||||
* Find the first free Pointer object and start it, passing in the event data.
|
||||
* @method startPointer
|
||||
* @param {Any} event The event data from the Touch event
|
||||
* @return {Pointer} The Pointer object that was started or null if no Pointer object is available
|
||||
**/
|
||||
InputManager.prototype.startPointer = function (event) {
|
||||
if (this.maxPointers < 10 && this.totalActivePointers == this.maxPointers) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (this.pointer1.active == false) {
|
||||
return this.pointer1.start(event);
|
||||
} else if (this.pointer2.active == false) {
|
||||
return this.pointer2.start(event);
|
||||
} else {
|
||||
for (var i = 3; i <= 10; i++) {
|
||||
if (this['pointer' + i] && this['pointer' + i].active == false) {
|
||||
return this['pointer' + i].start(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the matching Pointer object, passing in the event data.
|
||||
* @method updatePointer
|
||||
* @param {Any} event The event data from the Touch event
|
||||
* @return {Pointer} The Pointer object that was updated or null if no Pointer object is available
|
||||
**/
|
||||
InputManager.prototype.updatePointer = function (event) {
|
||||
if (this.pointer1.active && this.pointer1.identifier == event.identifier) {
|
||||
return this.pointer1.move(event);
|
||||
} else if (this.pointer2.active && this.pointer2.identifier == event.identifier) {
|
||||
return this.pointer2.move(event);
|
||||
} else {
|
||||
for (var i = 3; i <= 10; i++) {
|
||||
if (this['pointer' + i] && this['pointer' + i].active && this['pointer' + i].identifier == event.identifier) {
|
||||
return this['pointer' + i].move(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Stops the matching Pointer object, passing in the event data.
|
||||
* @method stopPointer
|
||||
* @param {Any} event The event data from the Touch event
|
||||
* @return {Pointer} The Pointer object that was stopped or null if no Pointer object is available
|
||||
**/
|
||||
InputManager.prototype.stopPointer = function (event) {
|
||||
if (this.pointer1.active && this.pointer1.identifier == event.identifier) {
|
||||
return this.pointer1.stop(event);
|
||||
} else if (this.pointer2.active && this.pointer2.identifier == event.identifier) {
|
||||
return this.pointer2.stop(event);
|
||||
} else {
|
||||
for (var i = 3; i <= 10; i++) {
|
||||
if (this['pointer' + i] && this['pointer' + i].active && this['pointer' + i].identifier == event.identifier) {
|
||||
return this['pointer' + i].stop(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the next Pointer object whos active property matches the given state
|
||||
* @method getPointer
|
||||
* @param {Boolean} state The state the Pointer should be in (false for inactive, true for active)
|
||||
* @return {Pointer} A Pointer object or null if no Pointer object matches the requested state.
|
||||
**/
|
||||
InputManager.prototype.getPointer = function (state) {
|
||||
if (typeof state === "undefined") { state = false; }
|
||||
if (this.pointer1.active == state) {
|
||||
return this.pointer1;
|
||||
} else if (this.pointer2.active == state) {
|
||||
return this.pointer2;
|
||||
} else {
|
||||
for (var i = 3; i <= 10; i++) {
|
||||
if (this['pointer' + i] && this['pointer' + i].active == state) {
|
||||
return this['pointer' + i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the Pointer object whos identified property matches the given identifier value
|
||||
* @method getPointerFromIdentifier
|
||||
* @param {Number} identifier The Pointer.identifier value to search for
|
||||
* @return {Pointer} A Pointer object or null if no Pointer object matches the requested identifier.
|
||||
**/
|
||||
InputManager.prototype.getPointerFromIdentifier = function (identifier) {
|
||||
if (this.pointer1.identifier == identifier) {
|
||||
return this.pointer1;
|
||||
} else if (this.pointer2.identifier == identifier) {
|
||||
return this.pointer2;
|
||||
} else {
|
||||
for (var i = 3; i <= 10; i++) {
|
||||
if (this['pointer' + i] && this['pointer' + i].identifier == identifier) {
|
||||
return this['pointer' + i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
Object.defineProperty(InputManager.prototype, "worldX", {
|
||||
get: function () {
|
||||
if (this.camera) {
|
||||
return (this.camera.worldView.x - this.camera.screenView.x) + this.x;
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
Object.defineProperty(InputManager.prototype, "worldY", {
|
||||
get: function () {
|
||||
if (this.camera) {
|
||||
return (this.camera.worldView.y - this.camera.screenView.y) + this.y;
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
/**
|
||||
* Get the distance between two Pointer objects
|
||||
* @method getDistance
|
||||
* @param {Pointer} pointer1
|
||||
* @param {Pointer} pointer2
|
||||
**/
|
||||
InputManager.prototype.getDistance = function (pointer1, pointer2) {
|
||||
return Phaser.Vec2Utils.distance(pointer1.position, pointer2.position);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the angle between two Pointer objects
|
||||
* @method getAngle
|
||||
* @param {Pointer} pointer1
|
||||
* @param {Pointer} pointer2
|
||||
**/
|
||||
InputManager.prototype.getAngle = function (pointer1, pointer2) {
|
||||
return Phaser.Vec2Utils.angle(pointer1.position, pointer2.position);
|
||||
};
|
||||
|
||||
InputManager.prototype.pixelPerfectCheck = function (sprite, pointer, alpha) {
|
||||
if (typeof alpha === "undefined") { alpha = 255; }
|
||||
this.hitContext.clearRect(0, 0, 1, 1);
|
||||
|
||||
return true;
|
||||
};
|
||||
InputManager.MOUSE_OVERRIDES_TOUCH = 0;
|
||||
|
||||
InputManager.TOUCH_OVERRIDES_MOUSE = 1;
|
||||
|
||||
InputManager.MOUSE_TOUCH_COMBINE = 2;
|
||||
return InputManager;
|
||||
})();
|
||||
Phaser.InputManager = InputManager;
|
||||
})(Phaser || (Phaser = {}));
|
||||
@@ -1,260 +0,0 @@
|
||||
/// <reference path="../_definitions.ts" />
|
||||
/**
|
||||
* Phaser - Keyboard
|
||||
*
|
||||
* The Keyboard class handles keyboard interactions with the game and the resulting events.
|
||||
* The avoid stealing all browser input we don't use event.preventDefault. If you would like to trap a specific key however
|
||||
* then use the addKeyCapture() method.
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var Keyboard = (function () {
|
||||
function Keyboard(game) {
|
||||
this._keys = {};
|
||||
this._capture = {};
|
||||
/**
|
||||
* You can disable all Input by setting disabled = true. While set all new input related events will be ignored.
|
||||
* @type {Boolean}
|
||||
*/
|
||||
this.disabled = false;
|
||||
this.game = game;
|
||||
}
|
||||
Keyboard.prototype.start = function () {
|
||||
var _this = this;
|
||||
this._onKeyDown = function (event) {
|
||||
return _this.onKeyDown(event);
|
||||
};
|
||||
this._onKeyUp = function (event) {
|
||||
return _this.onKeyUp(event);
|
||||
};
|
||||
|
||||
document.body.addEventListener('keydown', this._onKeyDown, false);
|
||||
document.body.addEventListener('keyup', this._onKeyUp, false);
|
||||
};
|
||||
|
||||
Keyboard.prototype.stop = function () {
|
||||
document.body.removeEventListener('keydown', this._onKeyDown);
|
||||
document.body.removeEventListener('keyup', this._onKeyUp);
|
||||
};
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* Pass in either a single keycode or an array of keycodes.
|
||||
* @param {Any} keycode
|
||||
*/
|
||||
Keyboard.prototype.addKeyCapture = function (keycode) {
|
||||
if (typeof keycode === 'object') {
|
||||
for (var i = 0; i < keycode.length; i++) {
|
||||
this._capture[keycode[i]] = true;
|
||||
}
|
||||
} else {
|
||||
this._capture[keycode] = true;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Number} keycode
|
||||
*/
|
||||
Keyboard.prototype.removeKeyCapture = function (keycode) {
|
||||
delete this._capture[keycode];
|
||||
};
|
||||
|
||||
Keyboard.prototype.clearCaptures = function () {
|
||||
this._capture = {};
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {KeyboardEvent} event
|
||||
*/
|
||||
Keyboard.prototype.onKeyDown = function (event) {
|
||||
if (this.game.input.disabled || this.disabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._capture[event.keyCode]) {
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
if (!this._keys[event.keyCode]) {
|
||||
this._keys[event.keyCode] = { isDown: true, timeDown: this.game.time.now, timeUp: 0 };
|
||||
} else {
|
||||
this._keys[event.keyCode].isDown = true;
|
||||
this._keys[event.keyCode].timeDown = this.game.time.now;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {KeyboardEvent} event
|
||||
*/
|
||||
Keyboard.prototype.onKeyUp = function (event) {
|
||||
if (this.game.input.disabled || this.disabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._capture[event.keyCode]) {
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
if (!this._keys[event.keyCode]) {
|
||||
this._keys[event.keyCode] = { isDown: false, timeDown: 0, timeUp: this.game.time.now };
|
||||
} else {
|
||||
this._keys[event.keyCode].isDown = false;
|
||||
this._keys[event.keyCode].timeUp = this.game.time.now;
|
||||
}
|
||||
};
|
||||
|
||||
Keyboard.prototype.reset = function () {
|
||||
for (var key in this._keys) {
|
||||
this._keys[key].isDown = false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Number} keycode
|
||||
* @param {Number} [duration]
|
||||
* @return {Boolean}
|
||||
*/
|
||||
Keyboard.prototype.justPressed = function (keycode, duration) {
|
||||
if (typeof duration === "undefined") { duration = 250; }
|
||||
if (this._keys[keycode] && this._keys[keycode].isDown === true && (this.game.time.now - this._keys[keycode].timeDown < duration)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Number} keycode
|
||||
* @param {Number} [duration]
|
||||
* @return {Boolean}
|
||||
*/
|
||||
Keyboard.prototype.justReleased = function (keycode, duration) {
|
||||
if (typeof duration === "undefined") { duration = 250; }
|
||||
if (this._keys[keycode] && this._keys[keycode].isDown === false && (this.game.time.now - this._keys[keycode].timeUp < duration)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Number} keycode
|
||||
* @return {Boolean}
|
||||
*/
|
||||
Keyboard.prototype.isDown = function (keycode) {
|
||||
if (this._keys[keycode]) {
|
||||
return this._keys[keycode].isDown;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
Keyboard.A = "A".charCodeAt(0);
|
||||
Keyboard.B = "B".charCodeAt(0);
|
||||
Keyboard.C = "C".charCodeAt(0);
|
||||
Keyboard.D = "D".charCodeAt(0);
|
||||
Keyboard.E = "E".charCodeAt(0);
|
||||
Keyboard.F = "F".charCodeAt(0);
|
||||
Keyboard.G = "G".charCodeAt(0);
|
||||
Keyboard.H = "H".charCodeAt(0);
|
||||
Keyboard.I = "I".charCodeAt(0);
|
||||
Keyboard.J = "J".charCodeAt(0);
|
||||
Keyboard.K = "K".charCodeAt(0);
|
||||
Keyboard.L = "L".charCodeAt(0);
|
||||
Keyboard.M = "M".charCodeAt(0);
|
||||
Keyboard.N = "N".charCodeAt(0);
|
||||
Keyboard.O = "O".charCodeAt(0);
|
||||
Keyboard.P = "P".charCodeAt(0);
|
||||
Keyboard.Q = "Q".charCodeAt(0);
|
||||
Keyboard.R = "R".charCodeAt(0);
|
||||
Keyboard.S = "S".charCodeAt(0);
|
||||
Keyboard.T = "T".charCodeAt(0);
|
||||
Keyboard.U = "U".charCodeAt(0);
|
||||
Keyboard.V = "V".charCodeAt(0);
|
||||
Keyboard.W = "W".charCodeAt(0);
|
||||
Keyboard.X = "X".charCodeAt(0);
|
||||
Keyboard.Y = "Y".charCodeAt(0);
|
||||
Keyboard.Z = "Z".charCodeAt(0);
|
||||
|
||||
Keyboard.ZERO = "0".charCodeAt(0);
|
||||
Keyboard.ONE = "1".charCodeAt(0);
|
||||
Keyboard.TWO = "2".charCodeAt(0);
|
||||
Keyboard.THREE = "3".charCodeAt(0);
|
||||
Keyboard.FOUR = "4".charCodeAt(0);
|
||||
Keyboard.FIVE = "5".charCodeAt(0);
|
||||
Keyboard.SIX = "6".charCodeAt(0);
|
||||
Keyboard.SEVEN = "7".charCodeAt(0);
|
||||
Keyboard.EIGHT = "8".charCodeAt(0);
|
||||
Keyboard.NINE = "9".charCodeAt(0);
|
||||
|
||||
Keyboard.NUMPAD_0 = 96;
|
||||
Keyboard.NUMPAD_1 = 97;
|
||||
Keyboard.NUMPAD_2 = 98;
|
||||
Keyboard.NUMPAD_3 = 99;
|
||||
Keyboard.NUMPAD_4 = 100;
|
||||
Keyboard.NUMPAD_5 = 101;
|
||||
Keyboard.NUMPAD_6 = 102;
|
||||
Keyboard.NUMPAD_7 = 103;
|
||||
Keyboard.NUMPAD_8 = 104;
|
||||
Keyboard.NUMPAD_9 = 105;
|
||||
Keyboard.NUMPAD_MULTIPLY = 106;
|
||||
Keyboard.NUMPAD_ADD = 107;
|
||||
Keyboard.NUMPAD_ENTER = 108;
|
||||
Keyboard.NUMPAD_SUBTRACT = 109;
|
||||
Keyboard.NUMPAD_DECIMAL = 110;
|
||||
Keyboard.NUMPAD_DIVIDE = 111;
|
||||
|
||||
Keyboard.F1 = 112;
|
||||
Keyboard.F2 = 113;
|
||||
Keyboard.F3 = 114;
|
||||
Keyboard.F4 = 115;
|
||||
Keyboard.F5 = 116;
|
||||
Keyboard.F6 = 117;
|
||||
Keyboard.F7 = 118;
|
||||
Keyboard.F8 = 119;
|
||||
Keyboard.F9 = 120;
|
||||
Keyboard.F10 = 121;
|
||||
Keyboard.F11 = 122;
|
||||
Keyboard.F12 = 123;
|
||||
Keyboard.F13 = 124;
|
||||
Keyboard.F14 = 125;
|
||||
Keyboard.F15 = 126;
|
||||
|
||||
Keyboard.COLON = 186;
|
||||
Keyboard.EQUALS = 187;
|
||||
Keyboard.UNDERSCORE = 189;
|
||||
Keyboard.QUESTION_MARK = 191;
|
||||
Keyboard.TILDE = 192;
|
||||
Keyboard.OPEN_BRACKET = 219;
|
||||
Keyboard.BACKWARD_SLASH = 220;
|
||||
Keyboard.CLOSED_BRACKET = 221;
|
||||
Keyboard.QUOTES = 222;
|
||||
|
||||
Keyboard.BACKSPACE = 8;
|
||||
Keyboard.TAB = 9;
|
||||
Keyboard.CLEAR = 12;
|
||||
Keyboard.ENTER = 13;
|
||||
Keyboard.SHIFT = 16;
|
||||
Keyboard.CONTROL = 17;
|
||||
Keyboard.ALT = 18;
|
||||
Keyboard.CAPS_LOCK = 20;
|
||||
Keyboard.ESC = 27;
|
||||
Keyboard.SPACEBAR = 32;
|
||||
Keyboard.PAGE_UP = 33;
|
||||
Keyboard.PAGE_DOWN = 34;
|
||||
Keyboard.END = 35;
|
||||
Keyboard.HOME = 36;
|
||||
Keyboard.LEFT = 37;
|
||||
Keyboard.UP = 38;
|
||||
Keyboard.RIGHT = 39;
|
||||
Keyboard.DOWN = 40;
|
||||
Keyboard.INSERT = 45;
|
||||
Keyboard.DELETE = 46;
|
||||
Keyboard.HELP = 47;
|
||||
Keyboard.NUM_LOCK = 144;
|
||||
return Keyboard;
|
||||
})();
|
||||
Phaser.Keyboard = Keyboard;
|
||||
})(Phaser || (Phaser = {}));
|
||||
@@ -1,110 +0,0 @@
|
||||
/// <reference path="../_definitions.ts" />
|
||||
/**
|
||||
* Phaser - MSPointer
|
||||
*
|
||||
* The MSPointer class handles touch interactions with the game and the resulting Pointer objects.
|
||||
* It will work only in Internet Explorer 10 and Windows Store or Windows Phone 8 apps using JavaScript.
|
||||
* http://msdn.microsoft.com/en-us/library/ie/hh673557(v=vs.85).aspx
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var MSPointer = (function () {
|
||||
/**
|
||||
* Constructor
|
||||
* @param {Game} game.
|
||||
* @return {MSPointer} This object.
|
||||
*/
|
||||
function MSPointer(game) {
|
||||
/**
|
||||
* You can disable all Input by setting disabled = true. While set all new input related events will be ignored.
|
||||
* @type {Boolean}
|
||||
*/
|
||||
this.disabled = false;
|
||||
this.game = game;
|
||||
}
|
||||
/**
|
||||
* Starts the event listeners running
|
||||
* @method start
|
||||
*/
|
||||
MSPointer.prototype.start = function () {
|
||||
var _this = this;
|
||||
if (this.game.device.mspointer == true) {
|
||||
this._onMSPointerDown = function (event) {
|
||||
return _this.onPointerDown(event);
|
||||
};
|
||||
this._onMSPointerMove = function (event) {
|
||||
return _this.onPointerMove(event);
|
||||
};
|
||||
this._onMSPointerUp = function (event) {
|
||||
return _this.onPointerUp(event);
|
||||
};
|
||||
|
||||
this.game.stage.canvas.addEventListener('MSPointerDown', this._onMSPointerDown, false);
|
||||
this.game.stage.canvas.addEventListener('MSPointerMove', this._onMSPointerMove, false);
|
||||
this.game.stage.canvas.addEventListener('MSPointerUp', this._onMSPointerUp, false);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @method onPointerDown
|
||||
* @param {Any} event
|
||||
**/
|
||||
MSPointer.prototype.onPointerDown = function (event) {
|
||||
if (this.game.input.disabled || this.disabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
event.identifier = event.pointerId;
|
||||
|
||||
this.game.input.startPointer(event);
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @method onPointerMove
|
||||
* @param {Any} event
|
||||
**/
|
||||
MSPointer.prototype.onPointerMove = function (event) {
|
||||
if (this.game.input.disabled || this.disabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
event.identifier = event.pointerId;
|
||||
|
||||
this.game.input.updatePointer(event);
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @method onPointerUp
|
||||
* @param {Any} event
|
||||
**/
|
||||
MSPointer.prototype.onPointerUp = function (event) {
|
||||
if (this.game.input.disabled || this.disabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
event.identifier = event.pointerId;
|
||||
|
||||
this.game.input.stopPointer(event);
|
||||
};
|
||||
|
||||
/**
|
||||
* Stop the event listeners
|
||||
* @method stop
|
||||
*/
|
||||
MSPointer.prototype.stop = function () {
|
||||
if (this.game.device.mspointer == true) {
|
||||
this.game.stage.canvas.removeEventListener('MSPointerDown', this._onMSPointerDown);
|
||||
this.game.stage.canvas.removeEventListener('MSPointerMove', this._onMSPointerMove);
|
||||
this.game.stage.canvas.removeEventListener('MSPointerUp', this._onMSPointerUp);
|
||||
}
|
||||
};
|
||||
return MSPointer;
|
||||
})();
|
||||
Phaser.MSPointer = MSPointer;
|
||||
})(Phaser || (Phaser = {}));
|
||||
@@ -1,114 +0,0 @@
|
||||
/// <reference path="../_definitions.ts" />
|
||||
/**
|
||||
* Phaser - Mouse
|
||||
*
|
||||
* The Mouse class handles mouse interactions with the game and the resulting events.
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var Mouse = (function () {
|
||||
function Mouse(game) {
|
||||
/**
|
||||
* You can disable all Input by setting disabled = true. While set all new input related events will be ignored.
|
||||
* @type {Boolean}
|
||||
*/
|
||||
this.disabled = false;
|
||||
this.mouseDownCallback = null;
|
||||
this.mouseMoveCallback = null;
|
||||
this.mouseUpCallback = null;
|
||||
this.game = game;
|
||||
this.callbackContext = this.game;
|
||||
}
|
||||
/**
|
||||
* Starts the event listeners running
|
||||
* @method start
|
||||
*/
|
||||
Mouse.prototype.start = function () {
|
||||
var _this = this;
|
||||
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;
|
||||
}
|
||||
|
||||
this._onMouseDown = function (event) {
|
||||
return _this.onMouseDown(event);
|
||||
};
|
||||
this._onMouseMove = function (event) {
|
||||
return _this.onMouseMove(event);
|
||||
};
|
||||
this._onMouseUp = function (event) {
|
||||
return _this.onMouseUp(event);
|
||||
};
|
||||
|
||||
this.game.stage.canvas.addEventListener('mousedown', this._onMouseDown, true);
|
||||
this.game.stage.canvas.addEventListener('mousemove', this._onMouseMove, true);
|
||||
this.game.stage.canvas.addEventListener('mouseup', this._onMouseUp, true);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {MouseEvent} event
|
||||
*/
|
||||
Mouse.prototype.onMouseDown = function (event) {
|
||||
if (this.mouseDownCallback) {
|
||||
this.mouseDownCallback.call(this.callbackContext, event);
|
||||
}
|
||||
|
||||
if (this.game.input.disabled || this.disabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
event['identifier'] = 0;
|
||||
|
||||
this.game.input.mousePointer.start(event);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {MouseEvent} event
|
||||
*/
|
||||
Mouse.prototype.onMouseMove = function (event) {
|
||||
if (this.mouseMoveCallback) {
|
||||
this.mouseMoveCallback.call(this.callbackContext, event);
|
||||
}
|
||||
|
||||
if (this.game.input.disabled || this.disabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
event['identifier'] = 0;
|
||||
|
||||
this.game.input.mousePointer.move(event);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {MouseEvent} event
|
||||
*/
|
||||
Mouse.prototype.onMouseUp = function (event) {
|
||||
if (this.mouseUpCallback) {
|
||||
this.mouseUpCallback.call(this.callbackContext, event);
|
||||
}
|
||||
|
||||
if (this.game.input.disabled || this.disabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
event['identifier'] = 0;
|
||||
|
||||
this.game.input.mousePointer.stop(event);
|
||||
};
|
||||
|
||||
/**
|
||||
* Stop the event listeners
|
||||
* @method stop
|
||||
*/
|
||||
Mouse.prototype.stop = function () {
|
||||
this.game.stage.canvas.removeEventListener('mousedown', this._onMouseDown);
|
||||
this.game.stage.canvas.removeEventListener('mousemove', this._onMouseMove);
|
||||
this.game.stage.canvas.removeEventListener('mouseup', this._onMouseUp);
|
||||
};
|
||||
Mouse.LEFT_BUTTON = 0;
|
||||
Mouse.MIDDLE_BUTTON = 1;
|
||||
Mouse.RIGHT_BUTTON = 2;
|
||||
return Mouse;
|
||||
})();
|
||||
Phaser.Mouse = Mouse;
|
||||
})(Phaser || (Phaser = {}));
|
||||
@@ -1,543 +0,0 @@
|
||||
/// <reference path="../_definitions.ts" />
|
||||
/**
|
||||
* Phaser - Pointer
|
||||
*
|
||||
* A Pointer object is used by the Touch and MSPoint managers and represents a single finger on the touch screen.
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var Pointer = (function () {
|
||||
/**
|
||||
* Constructor
|
||||
* @param {Phaser.Game} game.
|
||||
* @return {Phaser.Pointer} This object.
|
||||
*/
|
||||
function Pointer(game, id) {
|
||||
/**
|
||||
* Local private variable to store the status of dispatching a hold event
|
||||
* @property _holdSent
|
||||
* @type {Boolean}
|
||||
* @private
|
||||
*/
|
||||
this._holdSent = false;
|
||||
/**
|
||||
* Local private variable storing the short-term history of pointer movements
|
||||
* @property _history
|
||||
* @type {Array}
|
||||
* @private
|
||||
*/
|
||||
this._history = [];
|
||||
/**
|
||||
* Local private variable storing the time at which the next history drop should occur
|
||||
* @property _lastDrop
|
||||
* @type {Number}
|
||||
* @private
|
||||
*/
|
||||
this._nextDrop = 0;
|
||||
// Monitor events outside of a state reset loop
|
||||
this._stateReset = false;
|
||||
/**
|
||||
* A Vector object containing the initial position when the Pointer was engaged with the screen.
|
||||
* @property positionDown
|
||||
* @type {Vec2}
|
||||
**/
|
||||
this.positionDown = null;
|
||||
/**
|
||||
* A Vector object containing the current position of the Pointer on the screen.
|
||||
* @property position
|
||||
* @type {Vec2}
|
||||
**/
|
||||
this.position = null;
|
||||
/**
|
||||
* A Circle object centered on the x/y screen coordinates of the Pointer.
|
||||
* Default size of 44px (Apple's recommended "finger tip" size)
|
||||
* @property circle
|
||||
* @type {Circle}
|
||||
**/
|
||||
this.circle = null;
|
||||
/**
|
||||
*
|
||||
* @property withinGame
|
||||
* @type {Boolean}
|
||||
*/
|
||||
this.withinGame = false;
|
||||
/**
|
||||
* The horizontal coordinate of point relative to the viewport in pixels, excluding any scroll offset
|
||||
* @property clientX
|
||||
* @type {Number}
|
||||
*/
|
||||
this.clientX = -1;
|
||||
/**
|
||||
* The vertical coordinate of point relative to the viewport in pixels, excluding any scroll offset
|
||||
* @property clientY
|
||||
* @type {Number}
|
||||
*/
|
||||
this.clientY = -1;
|
||||
/**
|
||||
* The horizontal coordinate of point relative to the viewport in pixels, including any scroll offset
|
||||
* @property pageX
|
||||
* @type {Number}
|
||||
*/
|
||||
this.pageX = -1;
|
||||
/**
|
||||
* The vertical coordinate of point relative to the viewport in pixels, including any scroll offset
|
||||
* @property pageY
|
||||
* @type {Number}
|
||||
*/
|
||||
this.pageY = -1;
|
||||
/**
|
||||
* The horizontal coordinate of point relative to the screen in pixels
|
||||
* @property screenX
|
||||
* @type {Number}
|
||||
*/
|
||||
this.screenX = -1;
|
||||
/**
|
||||
* The vertical coordinate of point relative to the screen in pixels
|
||||
* @property screenY
|
||||
* @type {Number}
|
||||
*/
|
||||
this.screenY = -1;
|
||||
/**
|
||||
* The horizontal coordinate of point relative to the game element. This value is automatically scaled based on game size.
|
||||
* @property x
|
||||
* @type {Number}
|
||||
*/
|
||||
this.x = -1;
|
||||
/**
|
||||
* The vertical coordinate of point relative to the game element. This value is automatically scaled based on game size.
|
||||
* @property y
|
||||
* @type {Number}
|
||||
*/
|
||||
this.y = -1;
|
||||
/**
|
||||
* If the Pointer is a mouse this is true, otherwise false
|
||||
* @property isMouse
|
||||
* @type {Boolean}
|
||||
**/
|
||||
this.isMouse = false;
|
||||
/**
|
||||
* If the Pointer is touching the touchscreen, or the mouse button is held down, isDown is set to true
|
||||
* @property isDown
|
||||
* @type {Boolean}
|
||||
**/
|
||||
this.isDown = false;
|
||||
/**
|
||||
* If the Pointer is not touching the touchscreen, or the mouse button is up, isUp is set to true
|
||||
* @property isUp
|
||||
* @type {Boolean}
|
||||
**/
|
||||
this.isUp = true;
|
||||
/**
|
||||
* A timestamp representing when the Pointer first touched the touchscreen.
|
||||
* @property timeDown
|
||||
* @type {Number}
|
||||
**/
|
||||
this.timeDown = 0;
|
||||
/**
|
||||
* A timestamp representing when the Pointer left the touchscreen.
|
||||
* @property timeUp
|
||||
* @type {Number}
|
||||
**/
|
||||
this.timeUp = 0;
|
||||
/**
|
||||
* A timestamp representing when the Pointer was last tapped or clicked
|
||||
* @property previousTapTime
|
||||
* @type {Number}
|
||||
**/
|
||||
this.previousTapTime = 0;
|
||||
/**
|
||||
* The total number of times this Pointer has been touched to the touchscreen
|
||||
* @property totalTouches
|
||||
* @type {Number}
|
||||
**/
|
||||
this.totalTouches = 0;
|
||||
/**
|
||||
* The number of miliseconds since the last click
|
||||
* @property msSinceLastClick
|
||||
* @type {Number}
|
||||
**/
|
||||
this.msSinceLastClick = Number.MAX_VALUE;
|
||||
/**
|
||||
* The Game Object this Pointer is currently over / touching / dragging.
|
||||
* @property targetObject
|
||||
* @type {Any}
|
||||
**/
|
||||
this.targetObject = null;
|
||||
/**
|
||||
* The top-most Camera that this Pointer is over (if any, null if none).
|
||||
* If the Pointer is over several cameras that are stacked on-top of each other this is only ever set to the top-most rendered camera.
|
||||
* @property camera
|
||||
* @type {Phaser.Camera}
|
||||
**/
|
||||
this.camera = null;
|
||||
this.game = game;
|
||||
|
||||
this.id = id;
|
||||
this.active = false;
|
||||
this.position = new Phaser.Vec2();
|
||||
this.positionDown = new Phaser.Vec2();
|
||||
this.circle = new Phaser.Circle(0, 0, 44);
|
||||
|
||||
if (id == 0) {
|
||||
this.isMouse = true;
|
||||
}
|
||||
}
|
||||
Object.defineProperty(Pointer.prototype, "duration", {
|
||||
get: /**
|
||||
* How long the Pointer has been depressed on the touchscreen. If not currently down it returns -1.
|
||||
* @property duration
|
||||
* @type {Number}
|
||||
**/
|
||||
function () {
|
||||
if (this.isUp) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return this.game.time.now - this.timeDown;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
Object.defineProperty(Pointer.prototype, "worldX", {
|
||||
get: /**
|
||||
* Gets the X value of this Pointer in world coordinates based on the given camera.
|
||||
* @param {Camera} [camera]
|
||||
*/
|
||||
function () {
|
||||
if (this.camera) {
|
||||
return (this.camera.worldView.x - this.camera.screenView.x) + this.x;
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
Object.defineProperty(Pointer.prototype, "worldY", {
|
||||
get: /**
|
||||
* Gets the Y value of this Pointer in world coordinates based on the given camera.
|
||||
* @param {Camera} [camera]
|
||||
*/
|
||||
function () {
|
||||
if (this.camera) {
|
||||
return (this.camera.worldView.y - this.camera.screenView.y) + this.y;
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
|
||||
/**
|
||||
* Called when the Pointer is pressed onto the touchscreen
|
||||
* @method start
|
||||
* @param {Any} event
|
||||
*/
|
||||
Pointer.prototype.start = function (event) {
|
||||
this.identifier = event.identifier;
|
||||
this.target = event.target;
|
||||
|
||||
if (event.button) {
|
||||
this.button = event.button;
|
||||
}
|
||||
|
||||
if (this.game.paused == true && this.game.stage.scale.incorrectOrientation == false) {
|
||||
this.game.stage.resumeGame();
|
||||
return this;
|
||||
}
|
||||
|
||||
this._history.length = 0;
|
||||
|
||||
this.active = true;
|
||||
this.withinGame = true;
|
||||
this.isDown = true;
|
||||
this.isUp = false;
|
||||
|
||||
// Work out how long it has been since the last click
|
||||
this.msSinceLastClick = this.game.time.now - this.timeDown;
|
||||
|
||||
this.timeDown = this.game.time.now;
|
||||
|
||||
this._holdSent = false;
|
||||
|
||||
// This sets the x/y and other local values
|
||||
this.move(event);
|
||||
|
||||
// x and y are the old values here?
|
||||
this.positionDown.setTo(this.x, this.y);
|
||||
|
||||
if (this.game.input.multiInputOverride == Phaser.InputManager.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.InputManager.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.InputManager.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers == 0)) {
|
||||
//this.game.input.x = this.x * this.game.input.scale.x;
|
||||
//this.game.input.y = this.y * this.game.input.scale.y;
|
||||
this.game.input.x = this.x;
|
||||
this.game.input.y = this.y;
|
||||
this.game.input.position.setTo(this.x, this.y);
|
||||
this.game.input.onDown.dispatch(this);
|
||||
this.game.input.resetSpeed(this.x, this.y);
|
||||
}
|
||||
|
||||
this._stateReset = false;
|
||||
this.totalTouches++;
|
||||
|
||||
if (this.isMouse == false) {
|
||||
this.game.input.currentPointers++;
|
||||
}
|
||||
|
||||
if (this.targetObject !== null) {
|
||||
this.targetObject.input._touchedHandler(this);
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
Pointer.prototype.update = function () {
|
||||
if (this.active) {
|
||||
if (this._holdSent == false && this.duration >= this.game.input.holdRate) {
|
||||
if (this.game.input.multiInputOverride == Phaser.InputManager.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.InputManager.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.InputManager.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers == 0)) {
|
||||
this.game.input.onHold.dispatch(this);
|
||||
}
|
||||
|
||||
this._holdSent = true;
|
||||
}
|
||||
|
||||
if (this.game.input.recordPointerHistory && this.game.time.now >= this._nextDrop) {
|
||||
this._nextDrop = this.game.time.now + this.game.input.recordRate;
|
||||
this._history.push({ x: this.position.x, y: this.position.y });
|
||||
|
||||
if (this._history.length > this.game.input.recordLimit) {
|
||||
this._history.shift();
|
||||
}
|
||||
}
|
||||
|
||||
// Check which camera they are over
|
||||
this.camera = this.game.world.cameras.getCameraUnderPoint(this.x, this.y);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Called when the Pointer is moved on the touchscreen
|
||||
* @method move
|
||||
* @param {Any} event
|
||||
*/
|
||||
Pointer.prototype.move = function (event) {
|
||||
if (this.game.input.pollLocked) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.button) {
|
||||
this.button = event.button;
|
||||
}
|
||||
|
||||
this.clientX = event.clientX;
|
||||
this.clientY = event.clientY;
|
||||
this.pageX = event.pageX;
|
||||
this.pageY = event.pageY;
|
||||
this.screenX = event.screenX;
|
||||
this.screenY = event.screenY;
|
||||
|
||||
this.x = (this.pageX - this.game.stage.offset.x) * this.game.input.scale.x;
|
||||
this.y = (this.pageY - this.game.stage.offset.y) * this.game.input.scale.y;
|
||||
|
||||
this.position.setTo(this.x, this.y);
|
||||
this.circle.x = this.x;
|
||||
this.circle.y = this.y;
|
||||
|
||||
if (this.game.input.multiInputOverride == Phaser.InputManager.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.InputManager.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.InputManager.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers == 0)) {
|
||||
this.game.input.activePointer = this;
|
||||
this.game.input.x = this.x;
|
||||
this.game.input.y = this.y;
|
||||
this.game.input.position.setTo(this.game.input.x, this.game.input.y);
|
||||
this.game.input.circle.x = this.game.input.x;
|
||||
this.game.input.circle.y = this.game.input.y;
|
||||
}
|
||||
|
||||
if (this.game.paused) {
|
||||
return this;
|
||||
}
|
||||
|
||||
if (this.targetObject !== null && this.targetObject.input && this.targetObject.input.isDragged == true) {
|
||||
if (this.targetObject.input.update(this) == false) {
|
||||
this.targetObject = null;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
// Work out which object is on the top
|
||||
this._highestRenderOrderID = -1;
|
||||
this._highestRenderObject = -1;
|
||||
this._highestInputPriorityID = -1;
|
||||
|
||||
for (var i = 0; i < this.game.input.totalTrackedObjects; i++) {
|
||||
if (this.game.input.inputObjects[i] && this.game.input.inputObjects[i].input && this.game.input.inputObjects[i].input.checkPointerOver(this)) {
|
||||
if (this.game.input.inputObjects[i].input.priorityID > this._highestInputPriorityID || (this.game.input.inputObjects[i].input.priorityID == this._highestInputPriorityID && this.game.input.inputObjects[i].renderOrderID > this._highestRenderOrderID)) {
|
||||
this._highestRenderOrderID = this.game.input.inputObjects[i].renderOrderID;
|
||||
this._highestRenderObject = i;
|
||||
this._highestInputPriorityID = this.game.input.inputObjects[i].input.priorityID;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this._highestRenderObject == -1) {
|
||||
if (this.targetObject !== null) {
|
||||
this.targetObject.input._pointerOutHandler(this);
|
||||
this.targetObject = null;
|
||||
}
|
||||
} else {
|
||||
if (this.targetObject == null) {
|
||||
// And now set the new one
|
||||
this.targetObject = this.game.input.inputObjects[this._highestRenderObject];
|
||||
this.targetObject.input._pointerOverHandler(this);
|
||||
} else {
|
||||
if (this.targetObject == this.game.input.inputObjects[this._highestRenderObject]) {
|
||||
if (this.targetObject.input.update(this) == false) {
|
||||
this.targetObject = null;
|
||||
}
|
||||
} else {
|
||||
// The target has changed, so tell the old one we've left it
|
||||
this.targetObject.input._pointerOutHandler(this);
|
||||
|
||||
// And now set the new one
|
||||
this.targetObject = this.game.input.inputObjects[this._highestRenderObject];
|
||||
this.targetObject.input._pointerOverHandler(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Called when the Pointer leaves the target area
|
||||
* @method leave
|
||||
* @param {Any} event
|
||||
*/
|
||||
Pointer.prototype.leave = function (event) {
|
||||
this.withinGame = false;
|
||||
this.move(event);
|
||||
};
|
||||
|
||||
/**
|
||||
* Called when the Pointer leaves the touchscreen
|
||||
* @method stop
|
||||
* @param {Any} event
|
||||
*/
|
||||
Pointer.prototype.stop = function (event) {
|
||||
if (this._stateReset) {
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
|
||||
this.timeUp = this.game.time.now;
|
||||
|
||||
if (this.game.input.multiInputOverride == Phaser.InputManager.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.InputManager.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.InputManager.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers == 0)) {
|
||||
this.game.input.onUp.dispatch(this);
|
||||
|
||||
if (this.duration >= 0 && this.duration <= this.game.input.tapRate) {
|
||||
if (this.timeUp - this.previousTapTime < this.game.input.doubleTapRate) {
|
||||
// Yes, let's dispatch the signal then with the 2nd parameter set to true
|
||||
this.game.input.onTap.dispatch(this, true);
|
||||
} else {
|
||||
// Wasn't a double-tap, so dispatch a single tap signal
|
||||
this.game.input.onTap.dispatch(this, false);
|
||||
}
|
||||
|
||||
this.previousTapTime = this.timeUp;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.id > 0) {
|
||||
this.active = false;
|
||||
}
|
||||
|
||||
this.withinGame = false;
|
||||
this.isDown = false;
|
||||
this.isUp = true;
|
||||
|
||||
if (this.isMouse == false) {
|
||||
this.game.input.currentPointers--;
|
||||
}
|
||||
|
||||
for (var i = 0; i < this.game.input.totalTrackedObjects; i++) {
|
||||
if (this.game.input.inputObjects[i] && this.game.input.inputObjects[i].input && this.game.input.inputObjects[i].input.enabled) {
|
||||
this.game.input.inputObjects[i].input._releasedHandler(this);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.targetObject) {
|
||||
this.targetObject.input._releasedHandler(this);
|
||||
}
|
||||
|
||||
this.targetObject = null;
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* The Pointer is considered justPressed if the time it was pressed onto the touchscreen or clicked is less than justPressedRate
|
||||
* @method justPressed
|
||||
* @param {Number} [duration].
|
||||
* @return {Boolean}
|
||||
*/
|
||||
Pointer.prototype.justPressed = function (duration) {
|
||||
if (typeof duration === "undefined") { duration = this.game.input.justPressedRate; }
|
||||
if (this.isDown === true && (this.timeDown + duration) > this.game.time.now) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* The Pointer is considered justReleased if the time it left the touchscreen is less than justReleasedRate
|
||||
* @method justReleased
|
||||
* @param {Number} [duration].
|
||||
* @return {Boolean}
|
||||
*/
|
||||
Pointer.prototype.justReleased = function (duration) {
|
||||
if (typeof duration === "undefined") { duration = this.game.input.justReleasedRate; }
|
||||
if (this.isUp === true && (this.timeUp + duration) > this.game.time.now) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Resets the Pointer properties. Called by InputManager.reset when you perform a State change.
|
||||
* @method reset
|
||||
*/
|
||||
Pointer.prototype.reset = function () {
|
||||
if (this.isMouse == false) {
|
||||
this.active = false;
|
||||
}
|
||||
|
||||
this.identifier = null;
|
||||
this.isDown = false;
|
||||
this.isUp = true;
|
||||
this.totalTouches = 0;
|
||||
this._holdSent = false;
|
||||
this._history.length = 0;
|
||||
this._stateReset = true;
|
||||
|
||||
if (this.targetObject && this.targetObject.input) {
|
||||
this.targetObject.input._releasedHandler(this);
|
||||
}
|
||||
|
||||
this.targetObject = null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a string representation of this object.
|
||||
* @method toString
|
||||
* @return {String} a string representation of the instance.
|
||||
**/
|
||||
Pointer.prototype.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 + ")}]";
|
||||
};
|
||||
return Pointer;
|
||||
})();
|
||||
Phaser.Pointer = Pointer;
|
||||
})(Phaser || (Phaser = {}));
|
||||
@@ -1,219 +0,0 @@
|
||||
/// <reference path="../_definitions.ts" />
|
||||
/**
|
||||
* Phaser - Touch
|
||||
*
|
||||
* The Touch class handles touch interactions with the game and the resulting Pointer objects.
|
||||
* http://www.w3.org/TR/touch-events/
|
||||
* https://developer.mozilla.org/en-US/docs/DOM/TouchList
|
||||
* http://www.html5rocks.com/en/mobile/touchandmouse/
|
||||
* Note: Android 2.x only supports 1 touch event at once, no multi-touch
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var Touch = (function () {
|
||||
/**
|
||||
* Constructor
|
||||
* @param {Game} game.
|
||||
* @return {Touch} This object.
|
||||
*/
|
||||
function Touch(game) {
|
||||
/**
|
||||
* You can disable all Input by setting disabled = true. While set all new input related events will be ignored.
|
||||
* @type {Boolean}
|
||||
*/
|
||||
this.disabled = false;
|
||||
this.touchStartCallback = null;
|
||||
this.touchMoveCallback = null;
|
||||
this.touchEndCallback = null;
|
||||
this.touchEnterCallback = null;
|
||||
this.touchLeaveCallback = null;
|
||||
this.touchCancelCallback = null;
|
||||
this.game = game;
|
||||
this.callbackContext = this.game;
|
||||
}
|
||||
/**
|
||||
* Starts the event listeners running
|
||||
* @method start
|
||||
*/
|
||||
Touch.prototype.start = function () {
|
||||
var _this = this;
|
||||
if (this.game.device.touch) {
|
||||
this._onTouchStart = function (event) {
|
||||
return _this.onTouchStart(event);
|
||||
};
|
||||
this._onTouchMove = function (event) {
|
||||
return _this.onTouchMove(event);
|
||||
};
|
||||
this._onTouchEnd = function (event) {
|
||||
return _this.onTouchEnd(event);
|
||||
};
|
||||
this._onTouchEnter = function (event) {
|
||||
return _this.onTouchEnter(event);
|
||||
};
|
||||
this._onTouchLeave = function (event) {
|
||||
return _this.onTouchLeave(event);
|
||||
};
|
||||
this._onTouchCancel = function (event) {
|
||||
return _this.onTouchCancel(event);
|
||||
};
|
||||
this._documentTouchMove = function (event) {
|
||||
return _this.consumeTouchMove(event);
|
||||
};
|
||||
|
||||
this.game.stage.canvas.addEventListener('touchstart', this._onTouchStart, false);
|
||||
this.game.stage.canvas.addEventListener('touchmove', this._onTouchMove, false);
|
||||
this.game.stage.canvas.addEventListener('touchend', this._onTouchEnd, false);
|
||||
this.game.stage.canvas.addEventListener('touchenter', this._onTouchEnter, false);
|
||||
this.game.stage.canvas.addEventListener('touchleave', this._onTouchLeave, false);
|
||||
this.game.stage.canvas.addEventListener('touchcancel', this._onTouchCancel, false);
|
||||
|
||||
document.addEventListener('touchmove', this._documentTouchMove, false);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Prevent iOS bounce-back (doesn't work?)
|
||||
* @method consumeTouchMove
|
||||
* @param {Any} event
|
||||
**/
|
||||
Touch.prototype.consumeTouchMove = function (event) {
|
||||
event.preventDefault();
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @method onTouchStart
|
||||
* @param {Any} event
|
||||
**/
|
||||
Touch.prototype.onTouchStart = function (event) {
|
||||
if (this.touchStartCallback) {
|
||||
this.touchStartCallback.call(this.callbackContext, event);
|
||||
}
|
||||
|
||||
if (this.game.input.disabled || this.disabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
for (var i = 0; i < event.changedTouches.length; i++) {
|
||||
this.game.input.startPointer(event.changedTouches[i]);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 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 onTouchCancel
|
||||
* @param {Any} event
|
||||
**/
|
||||
Touch.prototype.onTouchCancel = function (event) {
|
||||
if (this.touchCancelCallback) {
|
||||
this.touchCancelCallback.call(this.callbackContext, event);
|
||||
}
|
||||
|
||||
if (this.game.input.disabled || this.disabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
for (var i = 0; i < event.changedTouches.length; i++) {
|
||||
this.game.input.stopPointer(event.changedTouches[i]);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 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 yet
|
||||
* @method onTouchEnter
|
||||
* @param {Any} event
|
||||
**/
|
||||
Touch.prototype.onTouchEnter = function (event) {
|
||||
if (this.touchEnterCallback) {
|
||||
this.touchEnterCallback.call(this.callbackContext, event);
|
||||
}
|
||||
|
||||
if (this.game.input.disabled || this.disabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
for (var i = 0; i < event.changedTouches.length; i++) {
|
||||
//console.log('touch enter');
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 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 yet
|
||||
* @method onTouchLeave
|
||||
* @param {Any} event
|
||||
**/
|
||||
Touch.prototype.onTouchLeave = function (event) {
|
||||
if (this.touchLeaveCallback) {
|
||||
this.touchLeaveCallback.call(this.callbackContext, event);
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
for (var i = 0; i < event.changedTouches.length; i++) {
|
||||
//console.log('touch leave');
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @method onTouchMove
|
||||
* @param {Any} event
|
||||
**/
|
||||
Touch.prototype.onTouchMove = function (event) {
|
||||
if (this.touchMoveCallback) {
|
||||
this.touchMoveCallback.call(this.callbackContext, event);
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
for (var i = 0; i < event.changedTouches.length; i++) {
|
||||
this.game.input.updatePointer(event.changedTouches[i]);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @method onTouchEnd
|
||||
* @param {Any} event
|
||||
**/
|
||||
Touch.prototype.onTouchEnd = function (event) {
|
||||
if (this.touchEndCallback) {
|
||||
this.touchEndCallback.call(this.callbackContext, event);
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
for (var i = 0; i < event.changedTouches.length; i++) {
|
||||
this.game.input.stopPointer(event.changedTouches[i]);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Stop the event listeners
|
||||
* @method stop
|
||||
*/
|
||||
Touch.prototype.stop = function () {
|
||||
if (this.game.device.touch) {
|
||||
this.game.stage.canvas.removeEventListener('touchstart', this._onTouchStart);
|
||||
this.game.stage.canvas.removeEventListener('touchmove', this._onTouchMove);
|
||||
this.game.stage.canvas.removeEventListener('touchend', this._onTouchEnd);
|
||||
this.game.stage.canvas.removeEventListener('touchenter', this._onTouchEnter);
|
||||
this.game.stage.canvas.removeEventListener('touchleave', this._onTouchLeave);
|
||||
this.game.stage.canvas.removeEventListener('touchcancel', this._onTouchCancel);
|
||||
|
||||
document.removeEventListener('touchmove', this._documentTouchMove);
|
||||
}
|
||||
};
|
||||
return Touch;
|
||||
})();
|
||||
Phaser.Touch = Touch;
|
||||
})(Phaser || (Phaser = {}));
|
||||
Reference in New Issue
Block a user