mirror of
https://github.com/wassname/phaser.git
synced 2026-09-12 12:40:47 +08:00
New Input handler implemented.
This commit is contained in:
+30
-270
@@ -1,20 +1,14 @@
|
||||
/// <reference path="../../Game.ts" />
|
||||
/// <reference path="Finger.ts" />
|
||||
/// <reference path="Pointer.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Touch
|
||||
*
|
||||
* The Touch class handles touch interactions with the game and the resulting Finger objects.
|
||||
* 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
|
||||
*
|
||||
* @todo Try and resolve update lag in Chrome/Android
|
||||
* Gestures (pinch, zoom, swipe)
|
||||
* GameObject Touch
|
||||
* Touch point within GameObject
|
||||
* Input Zones (mouse and touch) - lock entities within them + axis aligned drags
|
||||
*/
|
||||
|
||||
module Phaser {
|
||||
@@ -30,24 +24,6 @@ module Phaser {
|
||||
|
||||
this._game = game;
|
||||
|
||||
this.finger1 = new Finger(this._game);
|
||||
this.finger2 = new Finger(this._game);
|
||||
this.finger3 = new Finger(this._game);
|
||||
this.finger4 = new Finger(this._game);
|
||||
this.finger5 = new Finger(this._game);
|
||||
this.finger6 = new Finger(this._game);
|
||||
this.finger7 = new Finger(this._game);
|
||||
this.finger8 = new Finger(this._game);
|
||||
this.finger9 = new Finger(this._game);
|
||||
this.finger10 = new Finger(this._game);
|
||||
|
||||
this._fingers = [this.finger1, this.finger2, this.finger3, this.finger4, this.finger5, this.finger6, this.finger7, this.finger8, this.finger9, this.finger10];
|
||||
|
||||
this.touchDown = new Signal();
|
||||
this.touchUp = new Signal();
|
||||
|
||||
this.start();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,120 +35,10 @@ module Phaser {
|
||||
private _game: Game;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property x
|
||||
* @type {Number}
|
||||
**/
|
||||
public x: number = 0;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property y
|
||||
* @type {Number}
|
||||
**/
|
||||
public y: number = 0;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property _fingers
|
||||
* @type {Array}
|
||||
* @private
|
||||
**/
|
||||
private _fingers: Finger[];
|
||||
|
||||
/**
|
||||
*
|
||||
* @property finger1
|
||||
* @type {Finger}
|
||||
**/
|
||||
public finger1: Finger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property finger2
|
||||
* @type {Finger}
|
||||
**/
|
||||
public finger2: Finger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property finger3
|
||||
* @type {Finger}
|
||||
**/
|
||||
public finger3: Finger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property finger4
|
||||
* @type {Finger}
|
||||
**/
|
||||
public finger4: Finger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property finger5
|
||||
* @type {Finger}
|
||||
**/
|
||||
public finger5: Finger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property finger6
|
||||
* @type {Finger}
|
||||
**/
|
||||
public finger6: Finger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property finger7
|
||||
* @type {Finger}
|
||||
**/
|
||||
public finger7: Finger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property finger8
|
||||
* @type {Finger}
|
||||
**/
|
||||
public finger8: Finger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property finger9
|
||||
* @type {Finger}
|
||||
**/
|
||||
public finger9: Finger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property finger10
|
||||
* @type {Finger}
|
||||
**/
|
||||
public finger10: Finger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property latestFinger
|
||||
* @type {Finger}
|
||||
**/
|
||||
public latestFinger: Finger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property isDown
|
||||
* You can disable all Input by setting disabled = true. While set all new input related events will be ignored.
|
||||
* @type {Boolean}
|
||||
**/
|
||||
public isDown: bool = false;
|
||||
|
||||
/**
|
||||
*
|
||||
* @property isUp
|
||||
* @type {Boolean}
|
||||
**/
|
||||
public isUp: bool = true;
|
||||
|
||||
public touchDown: Signal;
|
||||
public touchUp: Signal;
|
||||
*/
|
||||
public disabled: bool = false;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -209,91 +75,71 @@ module Phaser {
|
||||
**/
|
||||
private onTouchStart(event) {
|
||||
|
||||
event.preventDefault();
|
||||
if (this._game.input.disabled || this.disabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// A list of all the touch points that BECAME active with the current event
|
||||
// https://developer.mozilla.org/en-US/docs/DOM/TouchList
|
||||
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++)
|
||||
{
|
||||
for (var f = 0; f < this._fingers.length; f++)
|
||||
{
|
||||
if (this._fingers[f].active === false)
|
||||
{
|
||||
this._fingers[f].start(event.changedTouches[i]);
|
||||
this.x = this._fingers[f].x;
|
||||
this.y = this._fingers[f].y;
|
||||
this._game.input.x = this.x * this._game.input.scaleX;
|
||||
this._game.input.y = this.y * this._game.input.scaleY;
|
||||
this.touchDown.dispatch(this._fingers[f].x, this._fingers[f].y, this._fingers[f].timeDown, this._fingers[f].timeUp, this._fingers[f].duration);
|
||||
this._game.input.onDown.dispatch(this._game.input.x, this._game.input.y, this._fingers[f].timeDown);
|
||||
this.isDown = true;
|
||||
this.isUp = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
this._game.input.startPointer(event.changedTouches[i]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Doesn't appear to be supported by most browsers yet
|
||||
* 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
|
||||
// event.changedTouches = the touches that CHANGED in this event, not the total number of them
|
||||
for (var i = 0; i < event.changedTouches.length; i++)
|
||||
{
|
||||
for (var f = 0; f < this._fingers.length; f++)
|
||||
{
|
||||
if (this._fingers[f].identifier === event.changedTouches[i].identifier)
|
||||
{
|
||||
this._fingers[f].stop(event.changedTouches[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
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 touch enter and leave its a list of the touch points that have entered or left the target
|
||||
|
||||
// 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++)
|
||||
{
|
||||
for (var f = 0; f < this._fingers.length; f++)
|
||||
{
|
||||
if (this._fingers[f].active === false)
|
||||
{
|
||||
this._fingers[f].start(event.changedTouches[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
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
|
||||
@@ -302,19 +148,9 @@ module Phaser {
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
// For touch enter and leave its a list of the touch points that have entered or left the target
|
||||
|
||||
// event.changedTouches = the touches that CHANGED in this event, not the total number of them
|
||||
for (var i = 0; i < event.changedTouches.length; i++)
|
||||
{
|
||||
for (var f = 0; f < this._fingers.length; f++)
|
||||
{
|
||||
if (this._fingers[f].identifier === event.changedTouches[i].identifier)
|
||||
{
|
||||
this._fingers[f].leave(event.changedTouches[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
console.log('touch leave');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -328,23 +164,9 @@ module Phaser {
|
||||
|
||||
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++)
|
||||
{
|
||||
for (var f = 0; f < this._fingers.length; f++)
|
||||
{
|
||||
if (this._fingers[f].identifier === event.changedTouches[i].identifier)
|
||||
{
|
||||
this._fingers[f].move(event.changedTouches[i]);
|
||||
this.x = this._fingers[f].x;
|
||||
this.y = this._fingers[f].y;
|
||||
this._game.input.x = this.x * this._game.input.scaleX;
|
||||
this._game.input.y = this.y * this._game.input.scaleY;
|
||||
break;
|
||||
}
|
||||
}
|
||||
this._game.input.updatePointer(event.changedTouches[i]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -364,60 +186,9 @@ module Phaser {
|
||||
// event.changedTouches = the touches that CHANGED in this event, not the total number of them
|
||||
for (var i = 0; i < event.changedTouches.length; i++)
|
||||
{
|
||||
for (var f = 0; f < this._fingers.length; f++)
|
||||
{
|
||||
if (this._fingers[f].identifier === event.changedTouches[i].identifier)
|
||||
{
|
||||
this._fingers[f].stop(event.changedTouches[i]);
|
||||
this.x = this._fingers[f].x;
|
||||
this.y = this._fingers[f].y;
|
||||
this._game.input.x = this.x * this._game.input.scaleX;
|
||||
this._game.input.y = this.y * this._game.input.scaleY;
|
||||
this.touchUp.dispatch(this._fingers[f].x, this._fingers[f].y, this._fingers[f].timeDown, this._fingers[f].timeUp, this._fingers[f].duration);
|
||||
this._game.input.onUp.dispatch(this._game.input.x, this._game.input.y, this._fingers[f].timeUp);
|
||||
this.isDown = false;
|
||||
this.isUp = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
this._game.input.stopPointer(event.changedTouches[i]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method calculateDistance
|
||||
* @param {Finger} finger1
|
||||
* @param {Finger} finger2
|
||||
**/
|
||||
public calculateDistance(finger1: Finger, finger2: Finger) {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method calculateAngle
|
||||
* @param {Finger} finger1
|
||||
* @param {Finger} finger2
|
||||
**/
|
||||
public calculateAngle(finger1: Finger, finger2: Finger) {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method checkOverlap
|
||||
* @param {Finger} finger1
|
||||
* @param {Finger} finger2
|
||||
**/
|
||||
public checkOverlap(finger1: Finger, finger2: Finger) {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method update
|
||||
*/
|
||||
public update() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -435,17 +206,6 @@ module Phaser {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @method reset
|
||||
**/
|
||||
public reset() {
|
||||
|
||||
this.isDown = false;
|
||||
this.isUp = false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user