2013-04-13 03:25:03 +00:00
|
|
|
/// <reference path="../../Game.ts" />
|
|
|
|
|
|
|
|
/**
|
2013-04-18 15:49:08 +00:00
|
|
|
* Phaser - Finger
|
|
|
|
*
|
|
|
|
* A Finger object is used by the Touch manager and represents a single finger on the touch screen.
|
2013-04-18 13:16:18 +00:00
|
|
|
*/
|
2013-04-13 03:25:03 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
module Phaser {
|
2013-04-13 03:25:03 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
export class Finger {
|
2013-04-13 03:25:03 +00:00
|
|
|
|
2013-05-11 16:26:30 +00:00
|
|
|
/**
|
2013-04-18 13:16:18 +00:00
|
|
|
* Constructor
|
|
|
|
* @param {Phaser.Game} game.
|
|
|
|
* @return {Phaser.Finger} This object.
|
|
|
|
*/
|
|
|
|
constructor(game: Game) {
|
2013-04-13 03:25:03 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
this._game = game;
|
|
|
|
this.active = false;
|
2013-04-13 03:25:03 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-05-11 16:26:30 +00:00
|
|
|
/**
|
|
|
|
*
|
2013-04-18 13:16:18 +00:00
|
|
|
* @property _game
|
2013-05-11 16:26:30 +00:00
|
|
|
* @type {Phaser.Game}
|
2013-04-18 13:16:18 +00:00
|
|
|
* @private
|
|
|
|
**/
|
|
|
|
private _game: Game;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An identification number for each touch point. When a touch point becomes active, it must be assigned an identifier that is distinct from any other active touch point. While the touch point remains active, all events that refer to it must assign it the same identifier.
|
|
|
|
* @property identifier
|
2013-05-11 16:26:30 +00:00
|
|
|
* @type {Number}
|
2013-04-18 13:16:18 +00:00
|
|
|
*/
|
|
|
|
public identifier: number;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @property active
|
2013-05-11 16:26:30 +00:00
|
|
|
* @type {Boolean}
|
2013-04-18 13:16:18 +00:00
|
|
|
*/
|
|
|
|
public active: bool;
|
|
|
|
|
2013-05-11 16:26:30 +00:00
|
|
|
/**
|
|
|
|
*
|
2013-04-18 13:16:18 +00:00
|
|
|
* @property point
|
2013-05-11 16:26:30 +00:00
|
|
|
* @type {Point}
|
2013-04-18 13:16:18 +00:00
|
|
|
**/
|
|
|
|
public point: Point = null;
|
|
|
|
|
2013-05-11 16:26:30 +00:00
|
|
|
/**
|
|
|
|
*
|
2013-04-18 13:16:18 +00:00
|
|
|
* @property circle
|
2013-05-11 16:26:30 +00:00
|
|
|
* @type {Circle}
|
2013-04-18 13:16:18 +00:00
|
|
|
**/
|
|
|
|
public circle: Circle = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @property withinGame
|
2013-05-11 16:26:30 +00:00
|
|
|
* @type {Boolean}
|
2013-04-18 13:16:18 +00:00
|
|
|
*/
|
|
|
|
public withinGame: bool = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The horizontal coordinate of point relative to the viewport in pixels, excluding any scroll offset
|
|
|
|
* @property clientX
|
2013-05-11 16:26:30 +00:00
|
|
|
* @type {Number}
|
2013-04-18 13:16:18 +00:00
|
|
|
*/
|
|
|
|
public clientX: number = -1;
|
|
|
|
|
2013-05-11 16:26:30 +00:00
|
|
|
//
|
2013-04-18 13:16:18 +00:00
|
|
|
/**
|
|
|
|
* The vertical coordinate of point relative to the viewport in pixels, excluding any scroll offset
|
|
|
|
* @property clientY
|
2013-05-11 16:26:30 +00:00
|
|
|
* @type {Number}
|
2013-04-18 13:16:18 +00:00
|
|
|
*/
|
|
|
|
public clientY: number = -1;
|
|
|
|
|
2013-05-11 16:26:30 +00:00
|
|
|
//
|
2013-04-18 13:16:18 +00:00
|
|
|
/**
|
|
|
|
* The horizontal coordinate of point relative to the viewport in pixels, including any scroll offset
|
|
|
|
* @property pageX
|
2013-05-11 16:26:30 +00:00
|
|
|
* @type {Number}
|
2013-04-18 13:16:18 +00:00
|
|
|
*/
|
|
|
|
public pageX: number = -1;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The vertical coordinate of point relative to the viewport in pixels, including any scroll offset
|
|
|
|
* @property pageY
|
2013-05-11 16:26:30 +00:00
|
|
|
* @type {Number}
|
2013-04-18 13:16:18 +00:00
|
|
|
*/
|
|
|
|
public pageY: number = -1;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The horizontal coordinate of point relative to the screen in pixels
|
|
|
|
* @property screenX
|
2013-05-11 16:26:30 +00:00
|
|
|
* @type {Number}
|
2013-04-18 13:16:18 +00:00
|
|
|
*/
|
|
|
|
public screenX: number = -1;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The vertical coordinate of point relative to the screen in pixels
|
|
|
|
* @property screenY
|
2013-05-11 16:26:30 +00:00
|
|
|
* @type {Number}
|
2013-04-18 13:16:18 +00:00
|
|
|
*/
|
|
|
|
public screenY: number = -1;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The horizontal coordinate of point relative to the game element
|
|
|
|
* @property x
|
2013-05-11 16:26:30 +00:00
|
|
|
* @type {Number}
|
2013-04-18 13:16:18 +00:00
|
|
|
*/
|
|
|
|
public x: number = -1;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The vertical coordinate of point relative to the game element
|
|
|
|
* @property y
|
2013-05-11 16:26:30 +00:00
|
|
|
* @type {Number}
|
2013-04-18 13:16:18 +00:00
|
|
|
*/
|
|
|
|
public y: number = -1;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Element on which the touch point started when it was first placed on the surface, even if the touch point has since moved outside the interactive area of that element.
|
|
|
|
* @property target
|
2013-05-11 16:26:30 +00:00
|
|
|
* @type {Any}
|
2013-04-18 13:16:18 +00:00
|
|
|
*/
|
|
|
|
public target;
|
|
|
|
|
2013-05-11 16:26:30 +00:00
|
|
|
/**
|
|
|
|
*
|
2013-04-18 13:16:18 +00:00
|
|
|
* @property isDown
|
2013-05-11 16:26:30 +00:00
|
|
|
* @type {Boolean}
|
2013-04-18 13:16:18 +00:00
|
|
|
**/
|
|
|
|
public isDown: bool = false;
|
|
|
|
|
2013-05-11 16:26:30 +00:00
|
|
|
/**
|
|
|
|
*
|
2013-04-18 13:16:18 +00:00
|
|
|
* @property isUp
|
2013-05-11 16:26:30 +00:00
|
|
|
* @type {Boolean}
|
2013-04-18 13:16:18 +00:00
|
|
|
**/
|
|
|
|
public isUp: bool = false;
|
|
|
|
|
2013-05-11 16:26:30 +00:00
|
|
|
/**
|
|
|
|
*
|
2013-04-18 13:16:18 +00:00
|
|
|
* @property timeDown
|
2013-05-11 16:26:30 +00:00
|
|
|
* @type {Number}
|
2013-04-18 13:16:18 +00:00
|
|
|
**/
|
|
|
|
public timeDown: number = 0;
|
|
|
|
|
2013-05-11 16:26:30 +00:00
|
|
|
/**
|
|
|
|
*
|
2013-04-18 13:16:18 +00:00
|
|
|
* @property duration
|
2013-05-11 16:26:30 +00:00
|
|
|
* @type {Number}
|
2013-04-18 13:16:18 +00:00
|
|
|
**/
|
|
|
|
public duration: number = 0;
|
|
|
|
|
2013-05-11 16:26:30 +00:00
|
|
|
/**
|
|
|
|
*
|
2013-04-18 13:16:18 +00:00
|
|
|
* @property timeUp
|
2013-05-11 16:26:30 +00:00
|
|
|
* @type {Number}
|
2013-04-18 13:16:18 +00:00
|
|
|
**/
|
|
|
|
public timeUp: number = 0;
|
|
|
|
|
2013-05-11 16:26:30 +00:00
|
|
|
/**
|
|
|
|
*
|
2013-04-18 13:16:18 +00:00
|
|
|
* @property justPressedRate
|
2013-05-11 16:26:30 +00:00
|
|
|
* @type {Number}
|
2013-04-18 13:16:18 +00:00
|
|
|
**/
|
|
|
|
public justPressedRate: number = 200;
|
|
|
|
|
2013-05-11 16:26:30 +00:00
|
|
|
/**
|
|
|
|
*
|
2013-04-18 13:16:18 +00:00
|
|
|
* @property justReleasedRate
|
2013-05-11 16:26:30 +00:00
|
|
|
* @type {Number}
|
2013-04-18 13:16:18 +00:00
|
|
|
**/
|
|
|
|
public justReleasedRate: number = 200;
|
|
|
|
|
|
|
|
/**
|
2013-05-11 16:26:30 +00:00
|
|
|
*
|
2013-04-18 13:16:18 +00:00
|
|
|
* @method start
|
|
|
|
* @param {Any} event
|
|
|
|
*/
|
|
|
|
public start(event) {
|
|
|
|
|
|
|
|
this.identifier = event.identifier;
|
|
|
|
this.target = event.target;
|
|
|
|
|
|
|
|
// populate geom objects
|
|
|
|
if (this.point === null)
|
|
|
|
{
|
|
|
|
this.point = new Point();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.circle === null)
|
|
|
|
{
|
|
|
|
this.circle = new Circle(0, 0, 44);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.move(event);
|
|
|
|
|
|
|
|
this.active = true;
|
|
|
|
this.withinGame = true;
|
|
|
|
this.isDown = true;
|
|
|
|
this.isUp = false;
|
|
|
|
this.timeDown = this._game.time.now;
|
2013-04-13 03:25:03 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
}
|
2013-04-13 03:25:03 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
/**
|
2013-05-11 16:26:30 +00:00
|
|
|
*
|
2013-04-18 13:16:18 +00:00
|
|
|
* @method move
|
|
|
|
* @param {Any} event
|
|
|
|
*/
|
|
|
|
public move(event) {
|
2013-04-13 03:25:03 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
this.clientX = event.clientX;
|
|
|
|
this.clientY = event.clientY;
|
|
|
|
this.pageX = event.pageX;
|
|
|
|
this.pageY = event.pageY;
|
|
|
|
this.screenX = event.screenX;
|
|
|
|
this.screenY = event.screenY;
|
2013-04-13 03:25:03 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
this.x = this.pageX - this._game.stage.offset.x;
|
|
|
|
this.y = this.pageY - this._game.stage.offset.y;
|
2013-04-13 03:25:03 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
this.point.setTo(this.x, this.y);
|
|
|
|
this.circle.setTo(this.x, this.y, 44);
|
2013-04-13 03:25:03 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
// Droppings history (used for gestures and motion tracking)
|
2013-04-13 03:25:03 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
this.duration = this._game.time.now - this.timeDown;
|
2013-04-13 03:25:03 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
}
|
2013-04-13 03:25:03 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
/**
|
2013-05-11 16:26:30 +00:00
|
|
|
*
|
2013-04-18 13:16:18 +00:00
|
|
|
* @method leave
|
|
|
|
* @param {Any} event
|
|
|
|
*/
|
|
|
|
public leave(event) {
|
2013-04-13 03:25:03 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
this.withinGame = false;
|
|
|
|
this.move(event);
|
2013-04-13 03:25:03 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
}
|
2013-04-13 03:25:03 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
/**
|
2013-05-11 16:26:30 +00:00
|
|
|
*
|
2013-04-18 13:16:18 +00:00
|
|
|
* @method stop
|
|
|
|
* @param {Any} event
|
|
|
|
*/
|
|
|
|
public stop(event) {
|
2013-04-13 03:25:03 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
this.active = false;
|
|
|
|
this.withinGame = false;
|
2013-04-13 03:25:03 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
this.isDown = false;
|
|
|
|
this.isUp = true;
|
|
|
|
this.timeUp = this._game.time.now;
|
|
|
|
this.duration = this.timeUp - this.timeDown;
|
2013-04-13 03:25:03 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
}
|
2013-04-13 03:25:03 +00:00
|
|
|
|
2013-05-11 16:26:30 +00:00
|
|
|
/**
|
|
|
|
*
|
2013-04-18 13:16:18 +00:00
|
|
|
* @method justPressed
|
2013-05-11 16:26:30 +00:00
|
|
|
* @param {Number} [duration].
|
2013-04-18 13:16:18 +00:00
|
|
|
* @return {Boolean}
|
|
|
|
*/
|
|
|
|
public justPressed(duration?: number = this.justPressedRate): bool {
|
|
|
|
|
|
|
|
if (this.isDown === true && (this.timeDown + duration) > this._game.time.now)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2013-04-13 03:25:03 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-05-11 16:26:30 +00:00
|
|
|
/**
|
|
|
|
*
|
2013-04-18 13:16:18 +00:00
|
|
|
* @method justReleased
|
2013-05-11 16:26:30 +00:00
|
|
|
* @param {Number} [duration].
|
2013-04-18 13:16:18 +00:00
|
|
|
* @return {Boolean}
|
|
|
|
*/
|
|
|
|
public justReleased(duration?: number = this.justReleasedRate): bool {
|
|
|
|
|
|
|
|
if (this.isUp === true && (this.timeUp + duration) > this._game.time.now)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2013-04-13 03:25:03 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
/**
|
|
|
|
* Returns a string representation of this object.
|
|
|
|
* @method toString
|
2013-05-11 16:26:30 +00:00
|
|
|
* @return {String} a string representation of the instance.
|
2013-04-18 13:16:18 +00:00
|
|
|
**/
|
|
|
|
public toString(): string {
|
2013-04-13 03:25:03 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
return "[{Finger (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 + ")}]";
|
2013-04-13 03:25:03 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
}
|
2013-04-13 03:25:03 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
}
|