phaser/todo/TS Source/input/MSPointer.js

100 lines
3.5 KiB
JavaScript
Raw Normal View History

/// <reference path="../_definitions.ts" />
/**
* Phaser - MSPointer
*
2013-05-16 01:36:58 +00:00
* 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 {bool}
*/
this.disabled = false;
this.game = game;
}
MSPointer.prototype.start = /**
2013-05-16 20:34:24 +00:00
* Starts the event listeners running
* @method 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);
}
};
MSPointer.prototype.onPointerDown = /**
*
* @method onPointerDown
* @param {Any} event
**/
function (event) {
if(this.game.input.disabled || this.disabled) {
2013-05-16 01:36:58 +00:00
return;
}
2013-05-16 01:36:58 +00:00
event.preventDefault();
event.identifier = event.pointerId;
this.game.input.startPointer(event);
};
MSPointer.prototype.onPointerMove = /**
*
* @method onPointerMove
* @param {Any} event
**/
function (event) {
if(this.game.input.disabled || this.disabled) {
2013-05-16 01:36:58 +00:00
return;
}
2013-05-16 01:36:58 +00:00
event.preventDefault();
event.identifier = event.pointerId;
this.game.input.updatePointer(event);
};
MSPointer.prototype.onPointerUp = /**
*
* @method onPointerUp
* @param {Any} event
**/
function (event) {
if(this.game.input.disabled || this.disabled) {
2013-05-16 01:36:58 +00:00
return;
}
2013-05-16 01:36:58 +00:00
event.preventDefault();
event.identifier = event.pointerId;
this.game.input.stopPointer(event);
};
MSPointer.prototype.stop = /**
2013-05-16 20:34:24 +00:00
* Stop the event listeners
* @method 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);
2013-05-16 20:34:24 +00:00
}
};
return MSPointer;
})();
Phaser.MSPointer = MSPointer;
})(Phaser || (Phaser = {}));