mirror of
https://github.com/wassname/phaser.git
synced 2026-08-16 11:25:21 +08:00
Refactoring ready for 1.0 release.
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
/// <reference path="../../Game.ts" />
|
||||
/// <reference path="Pointer.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Gestures
|
||||
*
|
||||
* The Gesture class monitors for gestures and dispatches the resulting signals when they occur.
|
||||
* Note: Android 2.x only supports 1 touch event at once, no multi-touch
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class Gestures {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param {Game} game.
|
||||
* @return {Touch} This object.
|
||||
*/
|
||||
constructor(game: Game) {
|
||||
|
||||
this._game = game;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Local private reference to game.
|
||||
* @property _game
|
||||
* @type {Game}
|
||||
* @private
|
||||
**/
|
||||
private _game: Game;
|
||||
|
||||
private _p1: Pointer;
|
||||
private _p2: Pointer;
|
||||
private _p3: Pointer;
|
||||
private _p4: Pointer;
|
||||
private _p5: Pointer;
|
||||
private _p6: Pointer;
|
||||
private _p7: Pointer;
|
||||
private _p8: Pointer;
|
||||
private _p9: Pointer;
|
||||
private _p10: Pointer;
|
||||
|
||||
public start() {
|
||||
|
||||
// Local references to the Phaser.Input.pointer objects
|
||||
this._p1 = this._game.input.pointer1;
|
||||
this._p2 = this._game.input.pointer2;
|
||||
this._p3 = this._game.input.pointer3;
|
||||
this._p4 = this._game.input.pointer4;
|
||||
this._p5 = this._game.input.pointer5;
|
||||
this._p6 = this._game.input.pointer6;
|
||||
this._p7 = this._game.input.pointer7;
|
||||
this._p8 = this._game.input.pointer8;
|
||||
this._p9 = this._game.input.pointer9;
|
||||
this._p10 = this._game.input.pointer10;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,873 @@
|
||||
/// <reference path="../../Game.ts" />
|
||||
/// <reference path="../../Signal.ts" />
|
||||
/// <reference path="Pointer.ts" />
|
||||
/// <reference path="MSPointer.ts" />
|
||||
/// <reference path="Gestures.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Input
|
||||
*
|
||||
* A game specific Input manager that looks after the mouse, keyboard and touch objects.
|
||||
* This is updated by the core game loop.
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class Input {
|
||||
|
||||
constructor(game: Game) {
|
||||
|
||||
this._game = game;
|
||||
|
||||
this.mousePointer = new Pointer(this._game, 0);
|
||||
this.pointer1 = new Pointer(this._game, 1);
|
||||
this.pointer2 = new Pointer(this._game, 2);
|
||||
this.pointer3 = new Pointer(this._game, 3);
|
||||
this.pointer4 = new Pointer(this._game, 4);
|
||||
this.pointer5 = new Pointer(this._game, 5);
|
||||
|
||||
this.mouse = new Mouse(this._game);
|
||||
this.keyboard = new Keyboard(this._game);
|
||||
this.touch = new Touch(this._game);
|
||||
this.mspointer = new 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.position = new Vector2;
|
||||
this.circle = new Circle(0, 0, 44);
|
||||
|
||||
this.currentPointers = 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Local private reference to game.
|
||||
*/
|
||||
private _game: Game;
|
||||
|
||||
/**
|
||||
* 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}
|
||||
*/
|
||||
public disabled: bool = false;
|
||||
|
||||
/**
|
||||
* Controls the expected behaviour when using a mouse and touch together on a multi-input device
|
||||
*/
|
||||
public multiInputOverride: number = Input.MOUSE_TOUCH_COMBINE;
|
||||
|
||||
/**
|
||||
* Static defining the behaviour expected on a multi-input device system.
|
||||
* With this setting when the mouse is used it updates the Input.x/y globals regardless if another pointer is active or not
|
||||
*/
|
||||
public static MOUSE_OVERRIDES_TOUCH: number = 0;
|
||||
|
||||
/**
|
||||
* Static defining the behaviour expected on a multi-input device system.
|
||||
* With this setting when the mouse is used it only updates the Input.x/y globals if no other pointer is active
|
||||
*/
|
||||
public static TOUCH_OVERRIDES_MOUSE: number = 1;
|
||||
|
||||
/**
|
||||
* Static defining the behaviour expected on a multi-input device system.
|
||||
* With this setting when the mouse is used it updates the Input.x/y globals at the same time as any active Pointer objects might
|
||||
*/
|
||||
public static MOUSE_TOUCH_COMBINE: number = 2;
|
||||
|
||||
/**
|
||||
* Phaser.Mouse handler
|
||||
* @type {Mouse}
|
||||
*/
|
||||
public mouse: Mouse;
|
||||
|
||||
/**
|
||||
* Phaser.Keyboard handler
|
||||
* @type {Keyboard}
|
||||
*/
|
||||
public keyboard: Keyboard;
|
||||
|
||||
/**
|
||||
* Phaser.Touch handler
|
||||
* @type {Touch}
|
||||
*/
|
||||
public touch: Touch;
|
||||
|
||||
/**
|
||||
* Phaser.MSPointer handler
|
||||
* @type {MSPointer}
|
||||
*/
|
||||
public mspointer: MSPointer;
|
||||
|
||||
/**
|
||||
* Phaser.Gestures handler
|
||||
* @type {Gestures}
|
||||
*/
|
||||
public gestures: Gestures;
|
||||
|
||||
/**
|
||||
* A vector object representing the current position of the Pointer.
|
||||
* @property vector
|
||||
* @type {Vector2}
|
||||
**/
|
||||
public position: Vector2 = 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}
|
||||
**/
|
||||
public circle: Circle = null;
|
||||
|
||||
/**
|
||||
* X coordinate of the most recent Pointer event
|
||||
* @type {Number}
|
||||
* @private
|
||||
*/
|
||||
private _x: number = 0;
|
||||
|
||||
/**
|
||||
* X coordinate of the most recent Pointer event
|
||||
* @type {Number}
|
||||
* @private
|
||||
*/
|
||||
private _y: number = 0;
|
||||
|
||||
/**
|
||||
*
|
||||
* @type {Number}
|
||||
*/
|
||||
public scaleX: number = 1;
|
||||
|
||||
/**
|
||||
*
|
||||
* @type {Number}
|
||||
*/
|
||||
public scaleY: number = 1;
|
||||
|
||||
/**
|
||||
* 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}
|
||||
*/
|
||||
public maxPointers: number = 10;
|
||||
|
||||
/**
|
||||
* The current number of active Pointers.
|
||||
* @type {Number}
|
||||
*/
|
||||
public currentPointers: number = 0;
|
||||
|
||||
/**
|
||||
* A Signal dispatched when a mouse/Pointer object is pressed
|
||||
* @type {Phaser.Signal}
|
||||
*/
|
||||
public onDown: Phaser.Signal;
|
||||
|
||||
/**
|
||||
* A Signal dispatched when a mouse/Pointer object is released
|
||||
* @type {Phaser.Signal}
|
||||
*/
|
||||
public onUp: Phaser.Signal;
|
||||
|
||||
/**
|
||||
* A Signal dispatched when a Pointer object (including the mouse) is tapped: pressed and released quickly.
|
||||
* The signal sends 2 parameters. The Pointer that caused it and a boolean depending if the tap was a single tap or a double tap.
|
||||
* @type {Phaser.Signal}
|
||||
*/
|
||||
public onTap: Phaser.Signal;
|
||||
|
||||
/**
|
||||
* A Signal dispatched when a Pointer object (including the mouse) is held down
|
||||
* @type {Phaser.Signal}
|
||||
*/
|
||||
public onHold: Phaser.Signal;
|
||||
|
||||
/**
|
||||
* 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}
|
||||
**/
|
||||
public tapRate: number = 200;
|
||||
|
||||
/**
|
||||
* The number of milliseconds between taps of the same Pointer for it to be considered a double tap / click
|
||||
* @property doubleTapRate
|
||||
* @type {Number}
|
||||
**/
|
||||
public doubleTapRate: number = 300;
|
||||
|
||||
/**
|
||||
* The number of milliseconds that the Pointer has to be pressed down for it to fire a onHold event
|
||||
* @property holdRate
|
||||
* @type {Number}
|
||||
**/
|
||||
public holdRate: number = 2000;
|
||||
|
||||
/**
|
||||
* The number of milliseconds below which the Pointer is considered justPressed
|
||||
* @property justPressedRate
|
||||
* @type {Number}
|
||||
**/
|
||||
public justPressedRate: number = 200;
|
||||
|
||||
/**
|
||||
* The number of milliseconds below which the Pointer is considered justReleased
|
||||
* @property justReleasedRate
|
||||
* @type {Number}
|
||||
**/
|
||||
public justReleasedRate: number = 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}
|
||||
**/
|
||||
public recordPointerHistory: bool = true;
|
||||
|
||||
/**
|
||||
* The rate in milliseconds at which the Pointer objects should update their tracking history
|
||||
* @property recordRate
|
||||
* @type {Number}
|
||||
*/
|
||||
public recordRate: number = 100;
|
||||
|
||||
/**
|
||||
* The total number of entries that can be recorded into the Pointer objects tracking history.
|
||||
* The 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}
|
||||
*/
|
||||
public recordLimit: number = 100;
|
||||
|
||||
/**
|
||||
* A Pointer object specifically used by the Mouse
|
||||
* @property mousePointer
|
||||
* @type {Pointer}
|
||||
**/
|
||||
public mousePointer: Pointer;
|
||||
|
||||
/**
|
||||
* A Pointer object
|
||||
* @property pointer1
|
||||
* @type {Pointer}
|
||||
**/
|
||||
public pointer1: Pointer;
|
||||
|
||||
/**
|
||||
* A Pointer object
|
||||
* @property pointer2
|
||||
* @type {Pointer}
|
||||
**/
|
||||
public pointer2: Pointer;
|
||||
|
||||
/**
|
||||
* A Pointer object
|
||||
* @property pointer3
|
||||
* @type {Pointer}
|
||||
**/
|
||||
public pointer3: Pointer;
|
||||
|
||||
/**
|
||||
* A Pointer object
|
||||
* @property pointer4
|
||||
* @type {Pointer}
|
||||
**/
|
||||
public pointer4: Pointer;
|
||||
|
||||
/**
|
||||
* A Pointer object
|
||||
* @property pointer5
|
||||
* @type {Pointer}
|
||||
**/
|
||||
public pointer5: Pointer;
|
||||
|
||||
/**
|
||||
* A Pointer object
|
||||
* @property pointer6
|
||||
* @type {Pointer}
|
||||
**/
|
||||
public pointer6: Pointer = null;
|
||||
|
||||
/**
|
||||
* A Pointer object
|
||||
* @property pointer7
|
||||
* @type {Pointer}
|
||||
**/
|
||||
public pointer7: Pointer = null;
|
||||
|
||||
/**
|
||||
* A Pointer object
|
||||
* @property pointer8
|
||||
* @type {Pointer}
|
||||
**/
|
||||
public pointer8: Pointer = null;
|
||||
|
||||
/**
|
||||
* A Pointer object
|
||||
* @property pointer9
|
||||
* @type {Pointer}
|
||||
**/
|
||||
public pointer9: Pointer = null;
|
||||
|
||||
/**
|
||||
* A Pointer object
|
||||
* @property pointer10
|
||||
* @type {Pointer}
|
||||
**/
|
||||
public pointer10: Pointer = null;
|
||||
|
||||
/**
|
||||
* The screen X coordinate
|
||||
* @property x
|
||||
* @type {Number}
|
||||
**/
|
||||
public get x(): number {
|
||||
|
||||
return this._x;
|
||||
|
||||
}
|
||||
|
||||
public set x(value: number) {
|
||||
|
||||
this._x = Math.round(value);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The screen Y coordinate
|
||||
* @property y
|
||||
* @type {Number}
|
||||
**/
|
||||
public get y(): number {
|
||||
|
||||
return this._y;
|
||||
|
||||
}
|
||||
|
||||
public set y(value: number) {
|
||||
|
||||
this._y = Math.round(value);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new Pointer object to the Input Manager. By default Input creates 5 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
|
||||
**/
|
||||
public addPointer(): Pointer {
|
||||
|
||||
var next: number = 0;
|
||||
|
||||
if (this.pointer10 === null)
|
||||
{
|
||||
next = 10;
|
||||
}
|
||||
|
||||
if (this.pointer9 === null)
|
||||
{
|
||||
next = 9;
|
||||
}
|
||||
|
||||
if (this.pointer8 === null)
|
||||
{
|
||||
next = 8;
|
||||
}
|
||||
|
||||
if (this.pointer7 === null)
|
||||
{
|
||||
next = 7;
|
||||
}
|
||||
|
||||
if (this.pointer6 === null)
|
||||
{
|
||||
next = 6;
|
||||
}
|
||||
|
||||
if (next == 0)
|
||||
{
|
||||
throw new Error("You can only have 10 Pointer objects");
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
this['pointer' + next] = new Pointer(this._game, next);
|
||||
return this['pointer' + next];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the Input Manager running
|
||||
* @method start
|
||||
**/
|
||||
public start() {
|
||||
|
||||
this.mouse.start();
|
||||
this.keyboard.start();
|
||||
this.touch.start();
|
||||
this.mspointer.start();
|
||||
this.gestures.start();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the Input Manager. Called by the core Game loop.
|
||||
* @method update
|
||||
**/
|
||||
public update() {
|
||||
|
||||
this.mousePointer.update();
|
||||
this.pointer1.update();
|
||||
this.pointer2.update();
|
||||
this.pointer3.update();
|
||||
this.pointer4.update();
|
||||
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(); }
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
public reset(hard?: bool = false) {
|
||||
|
||||
this.keyboard.reset();
|
||||
|
||||
this.pointer1.reset();
|
||||
this.pointer2.reset();
|
||||
this.pointer3.reset();
|
||||
this.pointer4.reset();
|
||||
this.pointer5.reset();
|
||||
|
||||
if (this.pointer6) { this.pointer6.reset(); }
|
||||
if (this.pointer7) { this.pointer7.reset(); }
|
||||
if (this.pointer8) { this.pointer8.reset(); }
|
||||
if (this.pointer9) { this.pointer9.reset(); }
|
||||
if (this.pointer10) { this.pointer10.reset(); }
|
||||
|
||||
this.currentPointers = 0;
|
||||
|
||||
if (hard == true)
|
||||
{
|
||||
this.onDown = new Phaser.Signal();
|
||||
this.onUp = new Phaser.Signal();
|
||||
this.onTap = new Phaser.Signal();
|
||||
this.onHold = new Phaser.Signal();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the total number of inactive Pointers
|
||||
* @method totalInactivePointers
|
||||
* @return {Number} The number of Pointers currently inactive
|
||||
**/
|
||||
public get totalInactivePointers(): number {
|
||||
|
||||
return 10 - this.currentPointers;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Recalculates the total number of active Pointers
|
||||
* @method totalActivePointers
|
||||
* @return {Number} The number of Pointers currently active
|
||||
**/
|
||||
public get totalActivePointers(): number {
|
||||
|
||||
this.currentPointers = 0;
|
||||
|
||||
if (this.pointer1.active == true)
|
||||
{
|
||||
this.currentPointers++;
|
||||
}
|
||||
else if (this.pointer2.active == true)
|
||||
{
|
||||
this.currentPointers++;
|
||||
}
|
||||
else if (this.pointer3.active == true)
|
||||
{
|
||||
this.currentPointers++;
|
||||
}
|
||||
else if (this.pointer4.active == true)
|
||||
{
|
||||
this.currentPointers++;
|
||||
}
|
||||
else if (this.pointer5.active == true)
|
||||
{
|
||||
this.currentPointers++;
|
||||
}
|
||||
else if (this.pointer6 && this.pointer6.active == true)
|
||||
{
|
||||
this.currentPointers++;
|
||||
}
|
||||
else if (this.pointer7 && this.pointer7.active == true)
|
||||
{
|
||||
this.currentPointers++;
|
||||
}
|
||||
else if (this.pointer8 && this.pointer8.active == true)
|
||||
{
|
||||
this.currentPointers++;
|
||||
}
|
||||
else if (this.pointer9 && this.pointer9.active == true)
|
||||
{
|
||||
this.currentPointers++;
|
||||
}
|
||||
else if (this.pointer10 && this.pointer10.active == true)
|
||||
{
|
||||
this.currentPointers++;
|
||||
}
|
||||
|
||||
return this.currentPointers;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
**/
|
||||
public startPointer(event):Pointer {
|
||||
|
||||
if (this.maxPointers < 10 && this.totalActivePointers == this.maxPointers)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// Unrolled for speed
|
||||
if (this.pointer1.active == false)
|
||||
{
|
||||
return this.pointer1.start(event);
|
||||
}
|
||||
else if (this.pointer2.active == false)
|
||||
{
|
||||
return this.pointer2.start(event);
|
||||
}
|
||||
else if (this.pointer3.active == false)
|
||||
{
|
||||
return this.pointer3.start(event);
|
||||
}
|
||||
else if (this.pointer4.active == false)
|
||||
{
|
||||
return this.pointer4.start(event);
|
||||
}
|
||||
else if (this.pointer5.active == false)
|
||||
{
|
||||
return this.pointer5.start(event);
|
||||
}
|
||||
else if (this.pointer6 && this.pointer6.active == false)
|
||||
{
|
||||
return this.pointer6.start(event);
|
||||
}
|
||||
else if (this.pointer7 && this.pointer7.active == false)
|
||||
{
|
||||
return this.pointer7.start(event);
|
||||
}
|
||||
else if (this.pointer8 && this.pointer8.active == false)
|
||||
{
|
||||
return this.pointer8.start(event);
|
||||
}
|
||||
else if (this.pointer9 && this.pointer9.active == false)
|
||||
{
|
||||
return this.pointer9.start(event);
|
||||
}
|
||||
else if (this.pointer10 && this.pointer10.active == false)
|
||||
{
|
||||
return this.pointer10.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
|
||||
**/
|
||||
public updatePointer(event):Pointer {
|
||||
|
||||
// Unrolled for speed
|
||||
if (this.pointer1.active == true && this.pointer1.identifier == event.identifier)
|
||||
{
|
||||
return this.pointer1.move(event);
|
||||
}
|
||||
else if (this.pointer2.active == true && this.pointer2.identifier == event.identifier)
|
||||
{
|
||||
return this.pointer2.move(event);
|
||||
}
|
||||
else if (this.pointer3.active == true && this.pointer3.identifier == event.identifier)
|
||||
{
|
||||
return this.pointer3.move(event);
|
||||
}
|
||||
else if (this.pointer4.active == true && this.pointer4.identifier == event.identifier)
|
||||
{
|
||||
return this.pointer4.move(event);
|
||||
}
|
||||
else if (this.pointer5.active == true && this.pointer5.identifier == event.identifier)
|
||||
{
|
||||
return this.pointer5.move(event);
|
||||
}
|
||||
else if (this.pointer6 && this.pointer6.active == true && this.pointer6.identifier == event.identifier)
|
||||
{
|
||||
return this.pointer6.move(event);
|
||||
}
|
||||
else if (this.pointer7 && this.pointer7.active == true && this.pointer7.identifier == event.identifier)
|
||||
{
|
||||
return this.pointer7.move(event);
|
||||
}
|
||||
else if (this.pointer8 && this.pointer8.active == true && this.pointer8.identifier == event.identifier)
|
||||
{
|
||||
return this.pointer8.move(event);
|
||||
}
|
||||
else if (this.pointer9 && this.pointer9.active == true && this.pointer9.identifier == event.identifier)
|
||||
{
|
||||
return this.pointer9.move(event);
|
||||
}
|
||||
else if (this.pointer10 && this.pointer10.active == true && this.pointer10.identifier == event.identifier)
|
||||
{
|
||||
return this.pointer10.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
|
||||
**/
|
||||
public stopPointer(event):Pointer {
|
||||
|
||||
// Unrolled for speed
|
||||
if (this.pointer1.active == true && this.pointer1.identifier == event.identifier)
|
||||
{
|
||||
return this.pointer1.stop(event);
|
||||
}
|
||||
else if (this.pointer2.active == true && this.pointer2.identifier == event.identifier)
|
||||
{
|
||||
return this.pointer2.stop(event);
|
||||
}
|
||||
else if (this.pointer3.active == true && this.pointer3.identifier == event.identifier)
|
||||
{
|
||||
return this.pointer3.stop(event);
|
||||
}
|
||||
else if (this.pointer4.active == true && this.pointer4.identifier == event.identifier)
|
||||
{
|
||||
return this.pointer4.stop(event);
|
||||
}
|
||||
else if (this.pointer5.active == true && this.pointer5.identifier == event.identifier)
|
||||
{
|
||||
return this.pointer5.stop(event);
|
||||
}
|
||||
else if (this.pointer6 && this.pointer6.active == true && this.pointer6.identifier == event.identifier)
|
||||
{
|
||||
return this.pointer6.stop(event);
|
||||
}
|
||||
else if (this.pointer7 && this.pointer7.active == true && this.pointer7.identifier == event.identifier)
|
||||
{
|
||||
return this.pointer7.stop(event);
|
||||
}
|
||||
else if (this.pointer8 && this.pointer8.active == true && this.pointer8.identifier == event.identifier)
|
||||
{
|
||||
return this.pointer8.stop(event);
|
||||
}
|
||||
else if (this.pointer9 && this.pointer9.active == true && this.pointer9.identifier == event.identifier)
|
||||
{
|
||||
return this.pointer9.stop(event);
|
||||
}
|
||||
else if (this.pointer10 && this.pointer10.active == true && this.pointer10.identifier == event.identifier)
|
||||
{
|
||||
return this.pointer10.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.
|
||||
**/
|
||||
public getPointer(state: bool = false): Pointer {
|
||||
|
||||
// Unrolled for speed
|
||||
if (this.pointer1.active == state)
|
||||
{
|
||||
return this.pointer1;
|
||||
}
|
||||
else if (this.pointer2.active == state)
|
||||
{
|
||||
return this.pointer2;
|
||||
}
|
||||
else if (this.pointer3.active == state)
|
||||
{
|
||||
return this.pointer3;
|
||||
}
|
||||
else if (this.pointer4.active == state)
|
||||
{
|
||||
return this.pointer4;
|
||||
}
|
||||
else if (this.pointer5.active == state)
|
||||
{
|
||||
return this.pointer5;
|
||||
}
|
||||
else if (this.pointer6 && this.pointer6.active == state)
|
||||
{
|
||||
return this.pointer6;
|
||||
}
|
||||
else if (this.pointer7 && this.pointer7.active == state)
|
||||
{
|
||||
return this.pointer7;
|
||||
}
|
||||
else if (this.pointer8 && this.pointer8.active == state)
|
||||
{
|
||||
return this.pointer8;
|
||||
}
|
||||
else if (this.pointer9 && this.pointer9.active == state)
|
||||
{
|
||||
return this.pointer9;
|
||||
}
|
||||
else if (this.pointer10 && this.pointer10.active == state)
|
||||
{
|
||||
return this.pointer10;
|
||||
}
|
||||
|
||||
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.
|
||||
**/
|
||||
public getPointerFromIdentifier(identifier: number): Pointer {
|
||||
|
||||
// Unrolled for speed
|
||||
if (this.pointer1.identifier == identifier)
|
||||
{
|
||||
return this.pointer1;
|
||||
}
|
||||
else if (this.pointer2.identifier == identifier)
|
||||
{
|
||||
return this.pointer2;
|
||||
}
|
||||
else if (this.pointer3.identifier == identifier)
|
||||
{
|
||||
return this.pointer3;
|
||||
}
|
||||
else if (this.pointer4.identifier == identifier)
|
||||
{
|
||||
return this.pointer4;
|
||||
}
|
||||
else if (this.pointer5.identifier == identifier)
|
||||
{
|
||||
return this.pointer5;
|
||||
}
|
||||
else if (this.pointer6 && this.pointer6.identifier == identifier)
|
||||
{
|
||||
return this.pointer6;
|
||||
}
|
||||
else if (this.pointer7 && this.pointer7.identifier == identifier)
|
||||
{
|
||||
return this.pointer7;
|
||||
}
|
||||
else if (this.pointer8 && this.pointer8.identifier == identifier)
|
||||
{
|
||||
return this.pointer8;
|
||||
}
|
||||
else if (this.pointer9 && this.pointer9.identifier == identifier)
|
||||
{
|
||||
return this.pointer9;
|
||||
}
|
||||
else if (this.pointer10 && this.pointer10.identifier == identifier)
|
||||
{
|
||||
return this.pointer10;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Camera} [camera]
|
||||
*/
|
||||
public getWorldX(camera?: Camera = this._game.camera) {
|
||||
|
||||
return camera.worldView.x + this.x;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Camera} [camera]
|
||||
*/
|
||||
public getWorldY(camera?: Camera = this._game.camera) {
|
||||
|
||||
return camera.worldView.y + this.y;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Number} x
|
||||
* @param {Number} y
|
||||
* @param {String} [color]
|
||||
*/
|
||||
public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
|
||||
|
||||
this._game.stage.context.font = '14px Courier';
|
||||
this._game.stage.context.fillStyle = color;
|
||||
this._game.stage.context.fillText('Input', x, y);
|
||||
this._game.stage.context.fillText('Screen X: ' + this.x + ' Screen Y: ' + this.y, x, y + 14);
|
||||
this._game.stage.context.fillText('World X: ' + this.getWorldX() + ' World Y: ' + this.getWorldY(), x, y + 28);
|
||||
this._game.stage.context.fillText('Scale X: ' + this.scaleX.toFixed(1) + ' Scale Y: ' + this.scaleY.toFixed(1), x, y + 42);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the distance between two Pointer objects
|
||||
* @method getDistance
|
||||
* @param {Pointer} pointer1
|
||||
* @param {Pointer} pointer2
|
||||
**/
|
||||
public getDistance(pointer1: Pointer, pointer2: Pointer): number {
|
||||
return pointer1.position.distance(pointer2.position);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the angle between two Pointer objects
|
||||
* @method getAngle
|
||||
* @param {Pointer} pointer1
|
||||
* @param {Pointer} pointer2
|
||||
**/
|
||||
public getAngle(pointer1: Pointer, pointer2: Pointer): number {
|
||||
return pointer1.position.angle(pointer2.position);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,304 @@
|
||||
/// <reference path="../../Game.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.
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class Keyboard {
|
||||
|
||||
constructor(game: Game) {
|
||||
|
||||
this._game = game;
|
||||
|
||||
}
|
||||
|
||||
private _game: Game;
|
||||
private _keys = {};
|
||||
private _capture = {};
|
||||
|
||||
/**
|
||||
* You can disable all Input by setting disabled = true. While set all new input related events will be ignored.
|
||||
* @type {Boolean}
|
||||
*/
|
||||
public disabled: bool = false;
|
||||
|
||||
public start() {
|
||||
|
||||
document.body.addEventListener('keydown', (event: KeyboardEvent) => this.onKeyDown(event), false);
|
||||
document.body.addEventListener('keyup', (event: KeyboardEvent) => this.onKeyUp(event), false);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public addKeyCapture(keycode) {
|
||||
|
||||
if (typeof keycode === 'object')
|
||||
{
|
||||
for (var i:number = 0; i < keycode.length; i++)
|
||||
{
|
||||
this._capture[keycode[i]] = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this._capture[keycode] = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Number} keycode
|
||||
*/
|
||||
public removeKeyCapture(keycode: number) {
|
||||
|
||||
delete this._capture[keycode];
|
||||
|
||||
}
|
||||
|
||||
public clearCaptures() {
|
||||
|
||||
this._capture = {};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {KeyboardEvent} event
|
||||
*/
|
||||
public onKeyDown(event: KeyboardEvent) {
|
||||
|
||||
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
|
||||
*/
|
||||
public onKeyUp(event: KeyboardEvent) {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public reset() {
|
||||
|
||||
for (var key in this._keys)
|
||||
{
|
||||
this._keys[key].isDown = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Number} keycode
|
||||
* @param {Number} [duration]
|
||||
* @return {Boolean}
|
||||
*/
|
||||
public justPressed(keycode: number, duration?: number = 250): bool {
|
||||
|
||||
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}
|
||||
*/
|
||||
public justReleased(keycode: number, duration?: number = 250): bool {
|
||||
|
||||
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}
|
||||
*/
|
||||
public isDown(keycode: number): bool {
|
||||
|
||||
if (this._keys[keycode])
|
||||
{
|
||||
return this._keys[keycode].isDown;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Letters
|
||||
public static A: number = "A".charCodeAt(0);
|
||||
public static B: number = "B".charCodeAt(0);
|
||||
public static C: number = "C".charCodeAt(0);
|
||||
public static D: number = "D".charCodeAt(0);
|
||||
public static E: number = "E".charCodeAt(0);
|
||||
public static F: number = "F".charCodeAt(0);
|
||||
public static G: number = "G".charCodeAt(0);
|
||||
public static H: number = "H".charCodeAt(0);
|
||||
public static I: number = "I".charCodeAt(0);
|
||||
public static J: number = "J".charCodeAt(0);
|
||||
public static K: number = "K".charCodeAt(0);
|
||||
public static L: number = "L".charCodeAt(0);
|
||||
public static M: number = "M".charCodeAt(0);
|
||||
public static N: number = "N".charCodeAt(0);
|
||||
public static O: number = "O".charCodeAt(0);
|
||||
public static P: number = "P".charCodeAt(0);
|
||||
public static Q: number = "Q".charCodeAt(0);
|
||||
public static R: number = "R".charCodeAt(0);
|
||||
public static S: number = "S".charCodeAt(0);
|
||||
public static T: number = "T".charCodeAt(0);
|
||||
public static U: number = "U".charCodeAt(0);
|
||||
public static V: number = "V".charCodeAt(0);
|
||||
public static W: number = "W".charCodeAt(0);
|
||||
public static X: number = "X".charCodeAt(0);
|
||||
public static Y: number = "Y".charCodeAt(0);
|
||||
public static Z: number = "Z".charCodeAt(0);
|
||||
|
||||
// Numbers
|
||||
public static ZERO: number = "0".charCodeAt(0);
|
||||
public static ONE: number = "1".charCodeAt(0);
|
||||
public static TWO: number = "2".charCodeAt(0);
|
||||
public static THREE: number = "3".charCodeAt(0);
|
||||
public static FOUR: number = "4".charCodeAt(0);
|
||||
public static FIVE: number = "5".charCodeAt(0);
|
||||
public static SIX: number = "6".charCodeAt(0);
|
||||
public static SEVEN: number = "7".charCodeAt(0);
|
||||
public static EIGHT: number = "8".charCodeAt(0);
|
||||
public static NINE: number = "9".charCodeAt(0);
|
||||
|
||||
// Numpad
|
||||
public static NUMPAD_0: number = 96;
|
||||
public static NUMPAD_1: number = 97;
|
||||
public static NUMPAD_2: number = 98;
|
||||
public static NUMPAD_3: number = 99;
|
||||
public static NUMPAD_4: number = 100;
|
||||
public static NUMPAD_5: number = 101;
|
||||
public static NUMPAD_6: number = 102;
|
||||
public static NUMPAD_7: number = 103;
|
||||
public static NUMPAD_8: number = 104;
|
||||
public static NUMPAD_9: number = 105;
|
||||
public static NUMPAD_MULTIPLY: number = 106;
|
||||
public static NUMPAD_ADD: number = 107;
|
||||
public static NUMPAD_ENTER: number = 108;
|
||||
public static NUMPAD_SUBTRACT: number = 109;
|
||||
public static NUMPAD_DECIMAL: number = 110;
|
||||
public static NUMPAD_DIVIDE: number = 111;
|
||||
|
||||
// Function Keys
|
||||
public static F1: number = 112;
|
||||
public static F2: number = 113;
|
||||
public static F3: number = 114;
|
||||
public static F4: number = 115;
|
||||
public static F5: number = 116;
|
||||
public static F6: number = 117;
|
||||
public static F7: number = 118;
|
||||
public static F8: number = 119;
|
||||
public static F9: number = 120;
|
||||
public static F10: number = 121;
|
||||
public static F11: number = 122;
|
||||
public static F12: number = 123;
|
||||
public static F13: number = 124;
|
||||
public static F14: number = 125;
|
||||
public static F15: number = 126;
|
||||
|
||||
// Symbol Keys
|
||||
public static COLON: number = 186;
|
||||
public static EQUALS: number = 187;
|
||||
public static UNDERSCORE: number = 189;
|
||||
public static QUESTION_MARK: number = 191;
|
||||
public static TILDE: number = 192;
|
||||
public static OPEN_BRACKET: number = 219;
|
||||
public static BACKWARD_SLASH: number = 220;
|
||||
public static CLOSED_BRACKET: number = 221;
|
||||
public static QUOTES: number = 222;
|
||||
|
||||
// Other Keys
|
||||
public static BACKSPACE: number = 8;
|
||||
public static TAB: number = 9;
|
||||
public static CLEAR: number = 12;
|
||||
public static ENTER: number = 13;
|
||||
public static SHIFT: number = 16;
|
||||
public static CONTROL: number = 17;
|
||||
public static ALT: number = 18;
|
||||
public static CAPS_LOCK: number = 20;
|
||||
public static ESC: number = 27;
|
||||
public static SPACEBAR: number = 32;
|
||||
public static PAGE_UP: number = 33;
|
||||
public static PAGE_DOWN: number = 34;
|
||||
public static END: number = 35;
|
||||
public static HOME: number = 36;
|
||||
public static LEFT: number = 37;
|
||||
public static UP: number = 38;
|
||||
public static RIGHT: number = 39;
|
||||
public static DOWN: number = 40;
|
||||
public static INSERT: number = 45;
|
||||
public static DELETE: number = 46;
|
||||
public static HELP: number = 47;
|
||||
public static NUM_LOCK: number = 144;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
/// <reference path="../../Game.ts" />
|
||||
/// <reference path="Pointer.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
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class MSPointer {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param {Game} game.
|
||||
* @return {MSPointer} This object.
|
||||
*/
|
||||
constructor(game: Game) {
|
||||
|
||||
this._game = game;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Local private reference to game.
|
||||
* @property _game
|
||||
* @type Game
|
||||
* @private
|
||||
**/
|
||||
private _game: Game;
|
||||
|
||||
/**
|
||||
* You can disable all Input by setting disabled = true. While set all new input related events will be ignored.
|
||||
* @type {Boolean}
|
||||
*/
|
||||
public disabled: bool = false;
|
||||
|
||||
/**
|
||||
* Starts the event listeners running
|
||||
* @method start
|
||||
*/
|
||||
public start() {
|
||||
|
||||
if (this._game.device.mspointer == true)
|
||||
{
|
||||
this._game.stage.canvas.addEventListener('MSPointerDown', (event) => this.onPointerDown(event), false);
|
||||
this._game.stage.canvas.addEventListener('MSPointerMove', (event) => this.onPointerMove(event), false);
|
||||
this._game.stage.canvas.addEventListener('MSPointerUp', (event) => this.onPointerUp(event), false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method onPointerDown
|
||||
* @param {Any} event
|
||||
**/
|
||||
private onPointerDown(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
|
||||
**/
|
||||
private onPointerMove(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
|
||||
**/
|
||||
private onPointerUp(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
|
||||
*/
|
||||
public stop() {
|
||||
|
||||
if (this._game.device.mspointer == true)
|
||||
{
|
||||
//this._game.stage.canvas.addEventListener('MSPointerDown', (event) => this.onPointerDown(event), false);
|
||||
//this._game.stage.canvas.addEventListener('MSPointerMove', (event) => this.onPointerMove(event), false);
|
||||
//this._game.stage.canvas.addEventListener('MSPointerUp', (event) => this.onPointerUp(event), false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
/// <reference path="../../Game.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Mouse
|
||||
*
|
||||
* The Mouse class handles mouse interactions with the game and the resulting events.
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class Mouse {
|
||||
|
||||
constructor(game: Game) {
|
||||
|
||||
this._game = game;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Local private reference to game.
|
||||
* @property _game
|
||||
* @type {Phaser.Game}
|
||||
* @private
|
||||
**/
|
||||
private _game: Game;
|
||||
|
||||
|
||||
public static LEFT_BUTTON: number = 0;
|
||||
public static MIDDLE_BUTTON: number = 1;
|
||||
public static RIGHT_BUTTON: number = 2;
|
||||
|
||||
/**
|
||||
* You can disable all Input by setting disabled = true. While set all new input related events will be ignored.
|
||||
* @type {Boolean}
|
||||
*/
|
||||
public disabled: bool = false;
|
||||
|
||||
/**
|
||||
* Starts the event listeners running
|
||||
* @method start
|
||||
*/
|
||||
public start() {
|
||||
|
||||
this._game.stage.canvas.addEventListener('mousedown', (event: MouseEvent) => this.onMouseDown(event), true);
|
||||
this._game.stage.canvas.addEventListener('mousemove', (event: MouseEvent) => this.onMouseMove(event), true);
|
||||
this._game.stage.canvas.addEventListener('mouseup', (event: MouseEvent) => this.onMouseUp(event), true);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {MouseEvent} event
|
||||
*/
|
||||
public onMouseDown(event: MouseEvent) {
|
||||
|
||||
if (this._game.input.disabled || this.disabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
event['identifier'] = 0;
|
||||
|
||||
this._game.input.mousePointer.start(event);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {MouseEvent} event
|
||||
*/
|
||||
public onMouseMove(event: MouseEvent) {
|
||||
|
||||
if (this._game.input.disabled || this.disabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
event['identifier'] = 0;
|
||||
|
||||
this._game.input.mousePointer.move(event);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {MouseEvent} event
|
||||
*/
|
||||
public onMouseUp(event: MouseEvent) {
|
||||
|
||||
if (this._game.input.disabled || this.disabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
event['identifier'] = 0;
|
||||
|
||||
this._game.input.mousePointer.stop(event);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop the event listeners
|
||||
* @method stop
|
||||
*/
|
||||
public stop() {
|
||||
|
||||
//this._game.stage.canvas.addEventListener('mousedown', (event: MouseEvent) => this.onMouseDown(event), true);
|
||||
//this._game.stage.canvas.addEventListener('mousemove', (event: MouseEvent) => this.onMouseMove(event), true);
|
||||
//this._game.stage.canvas.addEventListener('mouseup', (event: MouseEvent) => this.onMouseUp(event), true);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,568 @@
|
||||
/// <reference path="../../Game.ts" />
|
||||
/// <reference path="../../geom/Vector2.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Pointer
|
||||
*
|
||||
* A Pointer object is used by the Touch and MSPoint managers and represents a single finger on the touch screen.
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class Pointer {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param {Phaser.Game} game.
|
||||
* @return {Phaser.Pointer} This object.
|
||||
*/
|
||||
constructor(game: Game, id: number) {
|
||||
|
||||
this._game = game;
|
||||
|
||||
this.id = id;
|
||||
this.active = false;
|
||||
this.position = new Vector2;
|
||||
this.positionDown = new Vector2;
|
||||
this.circle = new Circle(0, 0, 44);
|
||||
|
||||
if (id == 0)
|
||||
{
|
||||
this.isMouse = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Local private reference to game.
|
||||
* @property _game
|
||||
* @type {Phaser.Game}
|
||||
* @private
|
||||
**/
|
||||
private _game: Game;
|
||||
|
||||
/**
|
||||
* Local private variable to store the status of dispatching a hold event
|
||||
* @property _holdSent
|
||||
* @type {Boolean}
|
||||
* @private
|
||||
*/
|
||||
private _holdSent: bool = false;
|
||||
|
||||
/**
|
||||
* Local private variable storing the short-term history of pointer movements
|
||||
* @property _history
|
||||
* @type {Array}
|
||||
* @private
|
||||
*/
|
||||
private _history = [];
|
||||
|
||||
/**
|
||||
* Local private variable storing the time at which the next history drop should occur
|
||||
* @property _lastDrop
|
||||
* @type {Number}
|
||||
* @private
|
||||
*/
|
||||
private _nextDrop: number = 0;
|
||||
|
||||
/**
|
||||
* The Pointer ID (a number between 1 and 10, 0 is reserved for the mouse pointer specifically)
|
||||
* @property id
|
||||
* @type {Number}
|
||||
*/
|
||||
public id: number;
|
||||
|
||||
/**
|
||||
* An identification number for each touch point.
|
||||
* When a touch point becomes active, it is assigned an identifier that is distinct from any other active touch point.
|
||||
* While the touch point remains active, all events that refer to it are assigned the same identifier.
|
||||
* @property identifier
|
||||
* @type {Number}
|
||||
*/
|
||||
public identifier: number;
|
||||
|
||||
/**
|
||||
* Is this Pointer active or not? An active Pointer is one that is in contact with the touch screen.
|
||||
* @property active
|
||||
* @type {Boolean}
|
||||
*/
|
||||
public active: bool;
|
||||
|
||||
/**
|
||||
* A Vector object containing the initial position when the Pointer was engaged with the screen.
|
||||
* @property positionDown
|
||||
* @type {Vector2}
|
||||
**/
|
||||
public positionDown: Vector2 = null;
|
||||
|
||||
/**
|
||||
* A Vector object containing the current position of the Pointer on the screen.
|
||||
* @property position
|
||||
* @type {Vector2}
|
||||
**/
|
||||
public position: Vector2 = 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}
|
||||
**/
|
||||
public circle: Circle = null;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property withinGame
|
||||
* @type {Boolean}
|
||||
*/
|
||||
public withinGame: bool = false;
|
||||
|
||||
/**
|
||||
* If this Pointer is a mouse the button property holds the value of which mouse button was pressed down
|
||||
* @property button
|
||||
* @type {Number}
|
||||
*/
|
||||
public button: number;
|
||||
|
||||
/**
|
||||
* The horizontal coordinate of point relative to the viewport in pixels, excluding any scroll offset
|
||||
* @property clientX
|
||||
* @type {Number}
|
||||
*/
|
||||
public clientX: number = -1;
|
||||
|
||||
/**
|
||||
* The vertical coordinate of point relative to the viewport in pixels, excluding any scroll offset
|
||||
* @property clientY
|
||||
* @type {Number}
|
||||
*/
|
||||
public clientY: number = -1;
|
||||
|
||||
/**
|
||||
* The horizontal coordinate of point relative to the viewport in pixels, including any scroll offset
|
||||
* @property pageX
|
||||
* @type {Number}
|
||||
*/
|
||||
public pageX: number = -1;
|
||||
|
||||
/**
|
||||
* The vertical coordinate of point relative to the viewport in pixels, including any scroll offset
|
||||
* @property pageY
|
||||
* @type {Number}
|
||||
*/
|
||||
public pageY: number = -1;
|
||||
|
||||
/**
|
||||
* The horizontal coordinate of point relative to the screen in pixels
|
||||
* @property screenX
|
||||
* @type {Number}
|
||||
*/
|
||||
public screenX: number = -1;
|
||||
|
||||
/**
|
||||
* The vertical coordinate of point relative to the screen in pixels
|
||||
* @property screenY
|
||||
* @type {Number}
|
||||
*/
|
||||
public screenY: number = -1;
|
||||
|
||||
/**
|
||||
* The horizontal coordinate of point relative to the game element
|
||||
* @property x
|
||||
* @type {Number}
|
||||
*/
|
||||
public x: number = -1;
|
||||
|
||||
/**
|
||||
* The vertical coordinate of point relative to the game element
|
||||
* @property y
|
||||
* @type {Number}
|
||||
*/
|
||||
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
|
||||
* @type {Any}
|
||||
*/
|
||||
public target;
|
||||
|
||||
/**
|
||||
* If the Pointer is a mouse this is true, otherwise false
|
||||
* @property isMouse
|
||||
* @type {Boolean}
|
||||
**/
|
||||
public isMouse: bool = false;
|
||||
|
||||
/**
|
||||
* If the Pointer is touching the touchscreen, or the mouse button is held down, isDown is set to true
|
||||
* @property isDown
|
||||
* @type {Boolean}
|
||||
**/
|
||||
public isDown: bool = false;
|
||||
|
||||
/**
|
||||
* If the Pointer is not touching the touchscreen, or the mouse button is up, isUp is set to true
|
||||
* @property isUp
|
||||
* @type {Boolean}
|
||||
**/
|
||||
public isUp: bool = true;
|
||||
|
||||
/**
|
||||
* A timestamp representing when the Pointer first touched the touchscreen.
|
||||
* @property timeDown
|
||||
* @type {Number}
|
||||
**/
|
||||
public timeDown: number = 0;
|
||||
|
||||
/**
|
||||
* A timestamp representing when the Pointer left the touchscreen.
|
||||
* @property timeUp
|
||||
* @type {Number}
|
||||
**/
|
||||
public timeUp: number = 0;
|
||||
|
||||
/**
|
||||
* A timestamp representing when the Pointer was last tapped or clicked
|
||||
* @property previousTapTime
|
||||
* @type {Number}
|
||||
**/
|
||||
public previousTapTime: number = 0;
|
||||
|
||||
/**
|
||||
* The total number of times this Pointer has been touched to the touchscreen
|
||||
* @property totalTouches
|
||||
* @type {Number}
|
||||
**/
|
||||
public totalTouches: number = 0;
|
||||
|
||||
/**
|
||||
* How long the Pointer has been depressed on the touchscreen. If not currently down it returns -1.
|
||||
* @property duration
|
||||
* @type {Number}
|
||||
**/
|
||||
public get duration(): number {
|
||||
|
||||
if (this.isUp)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return this._game.time.now - this.timeDown;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the X value of this Pointer in world coordinate space
|
||||
* @param {Camera} [camera]
|
||||
*/
|
||||
public getWorldX(camera?: Camera = this._game.camera) {
|
||||
|
||||
return camera.worldView.x + this.x;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Y value of this Pointer in world coordinate space
|
||||
* @param {Camera} [camera]
|
||||
*/
|
||||
public getWorldY(camera?: Camera = this._game.camera) {
|
||||
|
||||
return camera.worldView.y + this.y;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the Pointer is pressed onto the touchscreen
|
||||
* @method start
|
||||
* @param {Any} event
|
||||
*/
|
||||
public start(event): Pointer {
|
||||
|
||||
this.identifier = event.identifier;
|
||||
this.target = event.target;
|
||||
|
||||
if (event.button)
|
||||
{
|
||||
this.button = event.button;
|
||||
}
|
||||
|
||||
// Fix to stop rogue browser plugins from blocking the visibility state event
|
||||
if (this._game.paused == true)
|
||||
{
|
||||
this._game.stage.resumeGame();
|
||||
return this;
|
||||
}
|
||||
|
||||
this._history.length = 0;
|
||||
|
||||
this.move(event);
|
||||
|
||||
this.positionDown.setTo(this.x, this.y);
|
||||
|
||||
this.active = true;
|
||||
this.withinGame = true;
|
||||
this.isDown = true;
|
||||
this.isUp = false;
|
||||
this.timeDown = this._game.time.now;
|
||||
this._holdSent = false;
|
||||
|
||||
if (this._game.input.multiInputOverride == Input.MOUSE_OVERRIDES_TOUCH || this._game.input.multiInputOverride == Input.MOUSE_TOUCH_COMBINE || (this._game.input.multiInputOverride == Input.TOUCH_OVERRIDES_MOUSE && this._game.input.currentPointers == 0))
|
||||
{
|
||||
this._game.input.x = this.x * this._game.input.scaleX;
|
||||
this._game.input.y = this.y * this._game.input.scaleY;
|
||||
this._game.input.onDown.dispatch(this);
|
||||
}
|
||||
|
||||
this.totalTouches++;
|
||||
|
||||
if (this.isMouse == false)
|
||||
{
|
||||
this._game.input.currentPointers++;
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
public update() {
|
||||
|
||||
if (this.active)
|
||||
{
|
||||
if (this._holdSent == false && this.duration >= this._game.input.holdRate)
|
||||
{
|
||||
if (this._game.input.multiInputOverride == Input.MOUSE_OVERRIDES_TOUCH || this._game.input.multiInputOverride == Input.MOUSE_TOUCH_COMBINE || (this._game.input.multiInputOverride == Input.TOUCH_OVERRIDES_MOUSE && this._game.input.currentPointers == 0))
|
||||
{
|
||||
this._game.input.onHold.dispatch(this);
|
||||
}
|
||||
|
||||
this._holdSent = true;
|
||||
}
|
||||
|
||||
// Update the droppings history
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the Pointer is moved on the touchscreen
|
||||
* @method move
|
||||
* @param {Any} event
|
||||
*/
|
||||
public move(event): Pointer {
|
||||
|
||||
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.y = this.pageY - this._game.stage.offset.y;
|
||||
|
||||
this.position.setTo(this.x, this.y);
|
||||
this.circle.x = this.x;
|
||||
this.circle.y = this.y;
|
||||
|
||||
if (this._game.input.multiInputOverride == Input.MOUSE_OVERRIDES_TOUCH || this._game.input.multiInputOverride == Input.MOUSE_TOUCH_COMBINE || (this._game.input.multiInputOverride == Input.TOUCH_OVERRIDES_MOUSE && this._game.input.currentPointers == 0))
|
||||
{
|
||||
this._game.input.x = this.x * this._game.input.scaleX;
|
||||
this._game.input.y = this.y * this._game.input.scaleY;
|
||||
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;
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the Pointer leaves the target area
|
||||
* @method leave
|
||||
* @param {Any} event
|
||||
*/
|
||||
public leave(event) {
|
||||
|
||||
this.withinGame = false;
|
||||
this.move(event);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the Pointer leaves the touchscreen
|
||||
* @method stop
|
||||
* @param {Any} event
|
||||
*/
|
||||
public stop(event): Pointer {
|
||||
|
||||
this.timeUp = this._game.time.now;
|
||||
|
||||
if (this._game.input.multiInputOverride == Input.MOUSE_OVERRIDES_TOUCH || this._game.input.multiInputOverride == Input.MOUSE_TOUCH_COMBINE || (this._game.input.multiInputOverride == Input.TOUCH_OVERRIDES_MOUSE && this._game.input.currentPointers == 0))
|
||||
{
|
||||
this._game.input.onUp.dispatch(this);
|
||||
|
||||
// Was it a tap?
|
||||
if (this.duration >= 0 && this.duration <= this._game.input.tapRate)
|
||||
{
|
||||
// Was it a double-tap?
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this.active = false;
|
||||
this.withinGame = false;
|
||||
this.isDown = false;
|
||||
this.isUp = true;
|
||||
|
||||
if (this.isMouse == false)
|
||||
{
|
||||
this._game.input.currentPointers--;
|
||||
}
|
||||
|
||||
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}
|
||||
*/
|
||||
public justPressed(duration?: number = this._game.input.justPressedRate): bool {
|
||||
|
||||
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}
|
||||
*/
|
||||
public justReleased(duration?: number = this._game.input.justReleasedRate): bool {
|
||||
|
||||
if (this.isUp === true && (this.timeUp + duration) > this._game.time.now)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the Pointer properties. Called by Input.reset when you perform a State change.
|
||||
* @method reset
|
||||
*/
|
||||
public reset() {
|
||||
|
||||
this.active = false;
|
||||
this.identifier = null;
|
||||
this.isDown = false;
|
||||
this.isUp = true;
|
||||
this.totalTouches = 0;
|
||||
this._holdSent = false;
|
||||
this._history.length = 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the Pointer.circle object onto the stage in green if down or red if up.
|
||||
* @method renderDebug
|
||||
*/
|
||||
public renderDebug(hideIfUp: bool = false) {
|
||||
|
||||
if (hideIfUp == true && this.isUp == true)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this._game.stage.context.beginPath();
|
||||
this._game.stage.context.arc(this.x, this.y, this.circle.radius, 0, Math.PI * 2);
|
||||
|
||||
if (this.active)
|
||||
{
|
||||
this._game.stage.context.fillStyle = 'rgba(0,255,0,0.5)';
|
||||
this._game.stage.context.strokeStyle = 'rgb(0,255,0)';
|
||||
}
|
||||
else
|
||||
{
|
||||
this._game.stage.context.fillStyle = 'rgba(255,0,0,0.5)';
|
||||
this._game.stage.context.strokeStyle = 'rgb(100,0,0)';
|
||||
}
|
||||
|
||||
this._game.stage.context.fill();
|
||||
this._game.stage.context.closePath();
|
||||
|
||||
// Render the points
|
||||
this._game.stage.context.beginPath();
|
||||
this._game.stage.context.moveTo(this.positionDown.x, this.positionDown.y);
|
||||
this._game.stage.context.lineTo(this.position.x, this.position.y);
|
||||
this._game.stage.context.lineWidth = 2;
|
||||
this._game.stage.context.stroke();
|
||||
this._game.stage.context.closePath();
|
||||
|
||||
// Render the text
|
||||
this._game.stage.context.fillStyle = 'rgb(255,255,255)';
|
||||
this._game.stage.context.font = 'Arial 16px';
|
||||
this._game.stage.context.fillText('ID: ' + this.id + " Active: " + this.active, this.x, this.y - 100);
|
||||
this._game.stage.context.fillText('Screen X: ' + this.x + " Screen Y: " + this.y, this.x, this.y - 80);
|
||||
this._game.stage.context.fillText('Duration: ' + this.duration + " ms", this.x, this.y - 60);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this object.
|
||||
* @method toString
|
||||
* @return {String} a string representation of the instance.
|
||||
**/
|
||||
public toString(): string {
|
||||
|
||||
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 + ")}]";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,217 @@
|
||||
/// <reference path="../../Game.ts" />
|
||||
/// <reference path="Pointer.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
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
|
||||
export class Touch {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param {Game} game.
|
||||
* @return {Touch} This object.
|
||||
*/
|
||||
constructor(game: Game) {
|
||||
|
||||
this._game = game;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Local private reference to game.
|
||||
* @property _game
|
||||
* @type {Phaser.Game}
|
||||
* @private
|
||||
**/
|
||||
private _game: Game;
|
||||
|
||||
/**
|
||||
* You can disable all Input by setting disabled = true. While set all new input related events will be ignored.
|
||||
* @type {Boolean}
|
||||
*/
|
||||
public disabled: bool = false;
|
||||
|
||||
/**
|
||||
* Starts the event listeners running
|
||||
* @method start
|
||||
*/
|
||||
public start() {
|
||||
|
||||
if (this._game.device.touch)
|
||||
{
|
||||
this._game.stage.canvas.addEventListener('touchstart', (event) => this.onTouchStart(event), false);
|
||||
this._game.stage.canvas.addEventListener('touchmove', (event) => this.onTouchMove(event), false);
|
||||
this._game.stage.canvas.addEventListener('touchend', (event) => this.onTouchEnd(event), false);
|
||||
this._game.stage.canvas.addEventListener('touchenter', (event) => this.onTouchEnter(event), false);
|
||||
this._game.stage.canvas.addEventListener('touchleave', (event) => this.onTouchLeave(event), false);
|
||||
this._game.stage.canvas.addEventListener('touchcancel', (event) => this.onTouchCancel(event), false);
|
||||
|
||||
document.addEventListener('touchmove', (event) => this.consumeTouchMove(event), false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevent iOS bounce-back (doesn't work?)
|
||||
* @method consumeTouchMove
|
||||
* @param {Any} event
|
||||
**/
|
||||
private consumeTouchMove(event) {
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method onTouchStart
|
||||
* @param {Any} event
|
||||
**/
|
||||
private onTouchStart(event) {
|
||||
|
||||
if (this._game.input.disabled || this.disabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
// event.targetTouches = list of all touches on the TARGET ELEMENT (i.e. game dom element)
|
||||
// event.touches = list of all touches on the ENTIRE DOCUMENT, not just the target element
|
||||
// event.changedTouches = the touches that CHANGED in this event, not the total number of them
|
||||
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
|
||||
**/
|
||||
private onTouchCancel(event) {
|
||||
|
||||
if (this._game.input.disabled || this.disabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
// Touch cancel - touches that were disrupted (perhaps by moving into a plugin or browser chrome)
|
||||
// http://www.w3.org/TR/touch-events/#dfn-touchcancel
|
||||
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
|
||||
**/
|
||||
private onTouchEnter(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
|
||||
**/
|
||||
private onTouchLeave(event) {
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
for (var i = 0; i < event.changedTouches.length; i++)
|
||||
{
|
||||
console.log('touch leave');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method onTouchMove
|
||||
* @param {Any} event
|
||||
**/
|
||||
private onTouchMove(event) {
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
for (var i = 0; i < event.changedTouches.length; i++)
|
||||
{
|
||||
this._game.input.updatePointer(event.changedTouches[i]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method onTouchEnd
|
||||
* @param {Any} event
|
||||
**/
|
||||
private onTouchEnd(event) {
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
// For touch end its a list of the touch points that have been removed from the surface
|
||||
// https://developer.mozilla.org/en-US/docs/DOM/TouchList
|
||||
|
||||
// event.changedTouches = the touches that CHANGED in this event, not the total number of them
|
||||
for (var i = 0; i < event.changedTouches.length; i++)
|
||||
{
|
||||
this._game.input.stopPointer(event.changedTouches[i]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop the event listeners
|
||||
* @method stop
|
||||
*/
|
||||
public stop() {
|
||||
|
||||
if (this._game.device.touch)
|
||||
{
|
||||
//this._domElement.addEventListener('touchstart', (event) => this.onTouchStart(event), false);
|
||||
//this._domElement.addEventListener('touchmove', (event) => this.onTouchMove(event), false);
|
||||
//this._domElement.addEventListener('touchend', (event) => this.onTouchEnd(event), false);
|
||||
//this._domElement.addEventListener('touchenter', (event) => this.onTouchEnter(event), false);
|
||||
//this._domElement.addEventListener('touchleave', (event) => this.onTouchLeave(event), false);
|
||||
//this._domElement.addEventListener('touchcancel', (event) => this.onTouchCancel(event), false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user