2013-05-28 20:38:37 +00:00
|
|
|
/// <reference path="../Game.ts" />
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
/**
|
2013-04-18 15:49:08 +00:00
|
|
|
* Phaser - Mouse
|
|
|
|
*
|
|
|
|
* The Mouse class handles mouse interactions with the game and the resulting events.
|
2013-04-18 13:16:18 +00:00
|
|
|
*/
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
module Phaser {
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
export class Mouse {
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
constructor(game: Game) {
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
this._game = game;
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
}
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-05-16 20:34:24 +00:00
|
|
|
/**
|
|
|
|
* Local private reference to game.
|
|
|
|
* @property _game
|
|
|
|
* @type {Phaser.Game}
|
|
|
|
* @private
|
|
|
|
**/
|
2013-04-18 13:16:18 +00:00
|
|
|
private _game: Game;
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
public static LEFT_BUTTON: number = 0;
|
|
|
|
public static MIDDLE_BUTTON: number = 1;
|
|
|
|
public static RIGHT_BUTTON: number = 2;
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-05-16 01:36:58 +00:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
|
2013-05-11 16:26:30 +00:00
|
|
|
/**
|
2013-05-16 20:34:24 +00:00
|
|
|
* Starts the event listeners running
|
|
|
|
* @method start
|
|
|
|
*/
|
2013-04-18 13:16:18 +00:00
|
|
|
public start() {
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
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);
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
}
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-05-11 16:26:30 +00:00
|
|
|
/**
|
|
|
|
* @param {MouseEvent} event
|
|
|
|
*/
|
2013-04-18 13:16:18 +00:00
|
|
|
public onMouseDown(event: MouseEvent) {
|
2013-04-14 01:31:00 +00:00
|
|
|
|
2013-05-16 01:36:58 +00:00
|
|
|
if (this._game.input.disabled || this.disabled)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-16 20:34:24 +00:00
|
|
|
event['identifier'] = 0;
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-05-16 20:34:24 +00:00
|
|
|
this._game.input.mousePointer.start(event);
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
}
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-05-11 16:26:30 +00:00
|
|
|
/**
|
|
|
|
* @param {MouseEvent} event
|
|
|
|
*/
|
2013-04-18 13:16:18 +00:00
|
|
|
public onMouseMove(event: MouseEvent) {
|
2013-04-14 01:31:00 +00:00
|
|
|
|
2013-05-16 01:36:58 +00:00
|
|
|
if (this._game.input.disabled || this.disabled)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-16 20:34:24 +00:00
|
|
|
event['identifier'] = 0;
|
2013-04-18 13:16:18 +00:00
|
|
|
|
2013-05-16 20:34:24 +00:00
|
|
|
this._game.input.mousePointer.move(event);
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
}
|
|
|
|
|
2013-05-11 16:26:30 +00:00
|
|
|
/**
|
|
|
|
* @param {MouseEvent} event
|
|
|
|
*/
|
2013-04-18 13:16:18 +00:00
|
|
|
public onMouseUp(event: MouseEvent) {
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-05-16 01:36:58 +00:00
|
|
|
if (this._game.input.disabled || this.disabled)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-16 20:34:24 +00:00
|
|
|
event['identifier'] = 0;
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-05-16 20:34:24 +00:00
|
|
|
this._game.input.mousePointer.stop(event);
|
2013-04-12 16:19:56 +00:00
|
|
|
|
2013-05-16 20:34:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stop the event listeners
|
|
|
|
* @method stop
|
|
|
|
*/
|
|
|
|
public stop() {
|
2013-04-18 13:16:18 +00:00
|
|
|
|
2013-05-16 20:34:24 +00:00
|
|
|
//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);
|
2013-04-19 17:53:21 +00:00
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
}
|
2013-04-14 01:31:00 +00:00
|
|
|
|
2013-04-12 16:19:56 +00:00
|
|
|
}
|
|
|
|
|
2013-04-18 13:16:18 +00:00
|
|
|
}
|