Fixed Firefox audio issue with the Loader and added defined functions for anonymous callbacks

This commit is contained in:
Richard Davey
2013-08-05 03:43:20 +01:00
parent 84ef32e62a
commit d1da4cbdef
15 changed files with 314 additions and 200 deletions
+25 -25
View File
@@ -22,20 +22,20 @@ module Phaser {
constructor(game: Game) {
this._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.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.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();
@@ -48,7 +48,7 @@ module Phaser {
this._oldPosition = new Vec2;
this.circle = new Circle(0, 0, 44);
this.camera = this._game.camera;
this.camera = this.game.camera;
this.activePointer = this.mousePointer;
this.currentPointers = 0;
@@ -61,9 +61,9 @@ module Phaser {
}
/**
* Local private reference to game.
* Local reference to game.
*/
private _game: Game;
public game: Game;
/**
* A 1x1 sized canvas used for pixel-perfect checks
@@ -451,7 +451,7 @@ module Phaser {
}
else
{
this['pointer' + next] = new Pointer(this._game, next);
this['pointer' + next] = new Pointer(this.game, next);
return this['pointer' + next];
}
@@ -563,7 +563,7 @@ module Phaser {
this.currentPointers = 0;
this._game.stage.canvas.style.cursor = "default";
this.game.stage.canvas.style.cursor = "default";
if (hard == true)
{
@@ -939,14 +939,14 @@ module Phaser {
/**
* @param {Camera} [camera]
*/
public getWorldX(camera?: Camera = this._game.camera) {
public getWorldX(camera?: Camera = this.game.camera) {
return camera.worldView.x + this.x;
}
/**
* @param {Camera} [camera]
*/
public getWorldY(camera?: Camera = this._game.camera) {
public getWorldY(camera?: Camera = this.game.camera) {
return camera.worldView.y + this.y;
}
@@ -957,12 +957,12 @@ module Phaser {
*/
public renderDebugInfo(x: number, y: number, color?: string = 'rgb(255,255,255)') {
this._game.stage.context.fillStyle = color;
this._game.stage.context.fillText('Input', x, y);
this._game.stage.context.fillText('X: ' + this.x + ' 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.scale.x.toFixed(1) + ' Scale Y: ' + this.scale.x.toFixed(1), x, y + 42);
this._game.stage.context.fillText('Screen X: ' + this.activePointer.screenX + ' Screen Y: ' + this.activePointer.screenY, x, y + 56);
this.game.stage.context.fillStyle = color;
this.game.stage.context.fillText('Input', x, y);
this.game.stage.context.fillText('X: ' + this.x + ' 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.scale.x.toFixed(1) + ' Scale Y: ' + this.scale.x.toFixed(1), x, y + 42);
this.game.stage.context.fillText('Screen X: ' + this.activePointer.screenX + ' Screen Y: ' + this.activePointer.screenY, x, y + 56);
}
+34 -12
View File
@@ -14,11 +14,17 @@ module Phaser {
constructor(game: Game) {
this._game = game;
this.game = game;
}
private _game: Game;
/**
* Local reference to game.
* @property game
* @type {Phaser.Game}
**/
public game: Game;
private _keys = {};
private _capture = {};
@@ -28,10 +34,26 @@ module Phaser {
*/
public disabled: bool = false;
/**
* A reference to the event handlers to allow removeEventListener support
*/
public _onKeyDown;
public _onKeyUp;
public start() {
document.body.addEventListener('keydown', (event: KeyboardEvent) => this.onKeyDown(event), false);
document.body.addEventListener('keyup', (event: KeyboardEvent) => this.onKeyUp(event), false);
this._onKeyDown = (event: KeyboardEvent) => this.onKeyDown(event);
this._onKeyUp = (event: KeyboardEvent) => this.onKeyUp(event);
document.body.addEventListener('keydown', this._onKeyDown , false);
document.body.addEventListener('keyup', this._onKeyUp, false);
}
public stop() {
document.body.removeEventListener('keydown', this._onKeyDown);
document.body.removeEventListener('keyup', this._onKeyUp);
}
@@ -78,7 +100,7 @@ module Phaser {
*/
public onKeyDown(event: KeyboardEvent) {
if (this._game.input.disabled || this.disabled)
if (this.game.input.disabled || this.disabled)
{
return;
}
@@ -90,12 +112,12 @@ module Phaser {
if (!this._keys[event.keyCode])
{
this._keys[event.keyCode] = { isDown: true, timeDown: this._game.time.now, timeUp: 0 };
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;
this._keys[event.keyCode].timeDown = this.game.time.now;
}
}
@@ -105,7 +127,7 @@ module Phaser {
*/
public onKeyUp(event: KeyboardEvent) {
if (this._game.input.disabled || this.disabled)
if (this.game.input.disabled || this.disabled)
{
return;
}
@@ -117,12 +139,12 @@ module Phaser {
if (!this._keys[event.keyCode])
{
this._keys[event.keyCode] = { isDown: false, timeDown: 0, timeUp: this._game.time.now };
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;
this._keys[event.keyCode].timeUp = this.game.time.now;
}
}
@@ -143,7 +165,7 @@ module Phaser {
*/
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))
if (this._keys[keycode] && this._keys[keycode].isDown === true && (this.game.time.now - this._keys[keycode].timeDown < duration))
{
return true;
}
@@ -161,7 +183,7 @@ module Phaser {
*/
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))
if (this._keys[keycode] && this._keys[keycode].isDown === false && (this.game.time.now - this._keys[keycode].timeUp < duration))
{
return true;
}
+29 -19
View File
@@ -20,17 +20,16 @@ module Phaser {
*/
constructor(game: Game) {
this._game = game;
this.game = game;
}
/**
* Local private reference to game.
* @property _game
* Local reference to game.
* @property game
* @type Game
* @private
**/
private _game: Game;
public game: Game;
/**
* You can disable all Input by setting disabled = true. While set all new input related events will be ignored.
@@ -38,17 +37,28 @@ module Phaser {
*/
public disabled: bool = false;
/**
* A reference to the event handlers to allow removeEventListener support
*/
public _onMSPointerDown;
public _onMSPointerMove;
public _onMSPointerUp;
/**
* Starts the event listeners running
* @method start
*/
public start() {
if (this._game.device.mspointer == true)
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);
this._onMSPointerDown = (event) => this.onPointerDown(event);
this._onMSPointerMove = (event) => this.onPointerMove(event);
this._onMSPointerUp = (event) => 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);
}
}
@@ -60,7 +70,7 @@ module Phaser {
**/
private onPointerDown(event) {
if (this._game.input.disabled || this.disabled)
if (this.game.input.disabled || this.disabled)
{
return;
}
@@ -68,7 +78,7 @@ module Phaser {
event.preventDefault();
event.identifier = event.pointerId;
this._game.input.startPointer(event);
this.game.input.startPointer(event);
}
@@ -79,7 +89,7 @@ module Phaser {
**/
private onPointerMove(event) {
if (this._game.input.disabled || this.disabled)
if (this.game.input.disabled || this.disabled)
{
return;
}
@@ -87,7 +97,7 @@ module Phaser {
event.preventDefault();
event.identifier = event.pointerId;
this._game.input.updatePointer(event);
this.game.input.updatePointer(event);
}
@@ -98,7 +108,7 @@ module Phaser {
**/
private onPointerUp(event) {
if (this._game.input.disabled || this.disabled)
if (this.game.input.disabled || this.disabled)
{
return;
}
@@ -106,7 +116,7 @@ module Phaser {
event.preventDefault();
event.identifier = event.pointerId;
this._game.input.stopPointer(event);
this.game.input.stopPointer(event);
}
@@ -116,11 +126,11 @@ module Phaser {
*/
public stop() {
if (this._game.device.mspointer == true)
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);
this.game.stage.canvas.removeEventListener('MSPointerDown', this._onMSPointerDown);
this.game.stage.canvas.removeEventListener('MSPointerMove', this._onMSPointerMove);
this.game.stage.canvas.removeEventListener('MSPointerUp', this._onMSPointerUp);
}
}
+29 -19
View File
@@ -12,18 +12,17 @@ module Phaser {
constructor(game: Game) {
this._game = game;
this.callbackContext = this._game;
this.game = game;
this.callbackContext = this.game;
}
/**
* Local private reference to game.
* @property _game
* Local reference to game.
* @property game
* @type {Phaser.Game}
* @private
**/
private _game: Game;
public game: Game;
public static LEFT_BUTTON: number = 0;
public static MIDDLE_BUTTON: number = 1;
@@ -44,21 +43,32 @@ module Phaser {
public mouseMoveCallback = null;
public mouseUpCallback = null;
/**
* A reference to the event handlers to allow removeEventListener support
*/
public _onMouseDown;
public _onMouseMove;
public _onMouseUp;
/**
* Starts the event listeners running
* @method start
*/
public start() {
if (this._game.device.android && this._game.device.chrome == false)
if (this.game.device.android && this.game.device.chrome == false)
{
// Android stock browser fires mouse events even if you preventDefault on the touchStart, so ...
return;
}
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);
this._onMouseDown = (event: MouseEvent) => this.onMouseDown(event);
this._onMouseMove = (event: MouseEvent) => this.onMouseMove(event);
this._onMouseUp = (event: MouseEvent) => this.onMouseUp(event);
this.game.stage.canvas.addEventListener('mousedown', this._onMouseDown, true);
this.game.stage.canvas.addEventListener('mousemove', this._onMouseMove, true);
this.game.stage.canvas.addEventListener('mouseup', this._onMouseUp, true);
}
@@ -72,14 +82,14 @@ module Phaser {
this.mouseDownCallback.call(this.callbackContext, event);
}
if (this._game.input.disabled || this.disabled)
if (this.game.input.disabled || this.disabled)
{
return;
}
event['identifier'] = 0;
this._game.input.mousePointer.start(event);
this.game.input.mousePointer.start(event);
}
@@ -93,14 +103,14 @@ module Phaser {
this.mouseMoveCallback.call(this.callbackContext, event);
}
if (this._game.input.disabled || this.disabled)
if (this.game.input.disabled || this.disabled)
{
return;
}
event['identifier'] = 0;
this._game.input.mousePointer.move(event);
this.game.input.mousePointer.move(event);
}
@@ -114,14 +124,14 @@ module Phaser {
this.mouseUpCallback.call(this.callbackContext, event);
}
if (this._game.input.disabled || this.disabled)
if (this.game.input.disabled || this.disabled)
{
return;
}
event['identifier'] = 0;
this._game.input.mousePointer.stop(event);
this.game.input.mousePointer.stop(event);
}
@@ -131,9 +141,9 @@ module Phaser {
*/
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);
this.game.stage.canvas.removeEventListener('mousedown', this._onMouseDown);
this.game.stage.canvas.removeEventListener('mousemove', this._onMouseMove);
this.game.stage.canvas.removeEventListener('mouseup', this._onMouseUp);
}
+48 -28
View File
@@ -22,18 +22,17 @@ module Phaser {
*/
constructor(game: Game) {
this._game = game;
this.callbackContext = this._game;
this.game = game;
this.callbackContext = this.game;
}
/**
* Local private reference to game.
* @property _game
* Local reference to game.
* @property game
* @type {Phaser.Game}
* @private
**/
private _game: Game;
public game: Game;
/**
* You can disable all Input by setting disabled = true. While set all new input related events will be ignored.
@@ -53,22 +52,41 @@ module Phaser {
public touchLeaveCallback = null;
public touchCancelCallback = null;
/**
* A reference to the event handlers to allow removeEventListener support
*/
public _onTouchStart;
public _onTouchMove;
public _onTouchEnd;
public _onTouchEnter;
public _onTouchLeave;
public _onTouchCancel;
public _documentTouchMove;
/**
* Starts the event listeners running
* @method start
*/
public start() {
if (this._game.device.touch)
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);
this._onTouchStart = (event) => this.onTouchStart(event);
this._onTouchMove = (event) => this.onTouchMove(event);
this._onTouchEnd = (event) => this.onTouchEnd(event);
this._onTouchEnter = (event) => this.onTouchEnter(event);
this._onTouchLeave = (event) => this.onTouchLeave(event);
this._onTouchCancel = (event) => this.onTouchCancel(event);
this._documentTouchMove = (event) => this.consumeTouchMove(event);
document.addEventListener('touchmove', (event) => this.consumeTouchMove(event), false);
this.game.stage.canvas.addEventListener('touchstart', this._onTouchStart, false);
this.game.stage.canvas.addEventListener('touchmove', this._onTouchMove, false);
this.game.stage.canvas.addEventListener('touchend', this._onTouchEnd, false);
this.game.stage.canvas.addEventListener('touchenter', this._onTouchEnter, false);
this.game.stage.canvas.addEventListener('touchleave', this._onTouchLeave, false);
this.game.stage.canvas.addEventListener('touchcancel', this._onTouchCancel, false);
document.addEventListener('touchmove', this._documentTouchMove, false);
}
}
@@ -94,7 +112,7 @@ module Phaser {
this.touchStartCallback.call(this.callbackContext, event);
}
if (this._game.input.disabled || this.disabled)
if (this.game.input.disabled || this.disabled)
{
return;
}
@@ -106,7 +124,7 @@ 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++)
{
this._game.input.startPointer(event.changedTouches[i]);
this.game.input.startPointer(event.changedTouches[i]);
}
}
@@ -124,7 +142,7 @@ module Phaser {
this.touchCancelCallback.call(this.callbackContext, event);
}
if (this._game.input.disabled || this.disabled)
if (this.game.input.disabled || this.disabled)
{
return;
}
@@ -135,7 +153,7 @@ module Phaser {
// 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]);
this.game.input.stopPointer(event.changedTouches[i]);
}
}
@@ -153,7 +171,7 @@ module Phaser {
this.touchEnterCallback.call(this.callbackContext, event);
}
if (this._game.input.disabled || this.disabled)
if (this.game.input.disabled || this.disabled)
{
return;
}
@@ -205,7 +223,7 @@ module Phaser {
for (var i = 0; i < event.changedTouches.length; i++)
{
this._game.input.updatePointer(event.changedTouches[i]);
this.game.input.updatePointer(event.changedTouches[i]);
}
}
@@ -230,7 +248,7 @@ 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++)
{
this._game.input.stopPointer(event.changedTouches[i]);
this.game.input.stopPointer(event.changedTouches[i]);
}
}
@@ -241,14 +259,16 @@ module Phaser {
*/
public stop() {
if (this._game.device.touch)
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);
this.game.stage.canvas.removeEventListener('touchstart', this._onTouchStart);
this.game.stage.canvas.removeEventListener('touchmove', this._onTouchMove);
this.game.stage.canvas.removeEventListener('touchend', this._onTouchEnd);
this.game.stage.canvas.removeEventListener('touchenter', this._onTouchEnter);
this.game.stage.canvas.removeEventListener('touchleave', this._onTouchLeave);
this.game.stage.canvas.removeEventListener('touchcancel', this._onTouchCancel);
document.removeEventListener('touchmove', this._documentTouchMove);
}
}