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
+15 -4
View File
@@ -60,6 +60,8 @@ module Phaser {
*/
constructor(callbackContext, parent?: string = '', width?: number = 800, height?: number = 600, initCallback = null, createCallback = null, updateCallback = null, renderCallback = null, destroyCallback = null) {
this.id = Phaser.GAMES.push(this) - 1;
this.callbackContext = callbackContext;
this.onInitCallback = initCallback;
this.onCreateCallback = createCallback;
@@ -69,16 +71,21 @@ module Phaser {
if (document.readyState === 'complete' || document.readyState === 'interactive')
{
setTimeout(() => this.boot(parent, width, height));
//setTimeout(() => this.boot(parent, width, height));
setTimeout(() => Phaser.GAMES[this.id].boot(parent, width, height));
}
else
{
document.addEventListener('DOMContentLoaded', () => this.boot(parent, width, height), false);
window.addEventListener('load', () => this.boot(parent, width, height), false);
//document.addEventListener('DOMContentLoaded', () => this.boot(parent, width, height), false);
//window.addEventListener('load', () => this.boot(parent, width, height), false);
document.addEventListener('DOMContentLoaded', Phaser.GAMES[this.id].boot(parent, width, height), false);
window.addEventListener('load', Phaser.GAMES[this.id].boot(parent, width, height), false);
}
}
public id: number;
/**
* Game loop trigger wrapper.
*/
@@ -308,10 +315,14 @@ module Phaser {
if (!document.body)
{
window.setTimeout(() => this.boot(parent, width, height), 13);
//window.setTimeout(() => this.boot(parent, width, height), 13);
setTimeout(() => Phaser.GAMES[this.id].boot(parent, width, height), 13);
}
else
{
document.removeEventListener('DOMContentLoaded', Phaser.GAMES[this.id].boot);
window.removeEventListener('load', Phaser.GAMES[this.id].boot);
this.device = new Device();
this.net = new Net(this);
this.math = new GameMath(this);
+2
View File
@@ -19,4 +19,6 @@ module Phaser {
export var VERSION: string = 'Phaser version 1.0.0';
export var GAMES = [];
}
+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);
}
}
+8 -4
View File
@@ -330,8 +330,6 @@ module Phaser {
case 'audio':
file.url = this.getAudioURL(file.url);
//console.log('Loader audio');
//console.log(file.url);
if (file.url !== null)
{
@@ -349,7 +347,6 @@ module Phaser {
if (this._game.sound.touchLocked)
{
// If audio is locked we can't do this yet, so need to queue this load request somehow. Bum.
//console.log('Audio is touch locked');
file.data = new Audio();
file.data.name = file.key;
file.data.preload = 'auto';
@@ -363,7 +360,7 @@ module Phaser {
file.data.onerror = () => this.fileError(file.key);
file.data.preload = 'auto';
file.data.src = file.url;
file.data.addEventListener('canplaythrough', () => this.fileComplete(file.key), false);
file.data.addEventListener('canplaythrough', Phaser.GAMES[this._game.id].load.fileComplete(file.key), false);
file.data.load();
}
}
@@ -425,6 +422,12 @@ module Phaser {
*/
private fileComplete(key: string) {
if (!this._fileList[key])
{
throw new Error('Phaser.Loader fileComplete invalid key ' + key);
return;
}
this._fileList[key].loaded = true;
var file = this._fileList[key];
@@ -491,6 +494,7 @@ module Phaser {
}
else
{
file.data.removeEventListener('canplaythrough', Phaser.GAMES[this._game.id].load.fileComplete);
this._game.cache.addSound(file.key, file.url, file.data, false, true);
}
break;
+5 -1
View File
@@ -18,7 +18,11 @@ module Phaser {
GameMath.sinA = [];
GameMath.cosA = [];
for (var i = 0; i < 360; i++)
// Android 4 stock browser bug fix
GameMath.sinA.push(0);
GameMath.cosA.push(0);
for (var i = 1; i < 360; i++)
{
GameMath.sinA.push(Math.sin(this.degreesToRadians(i)));
GameMath.cosA.push(Math.cos(this.degreesToRadians(i)));
+15 -4
View File
@@ -89,6 +89,11 @@ module Phaser {
**/
public isRunning: bool = false;
/**
* A reference to the RAF/setTimeout to avoid constant anonymous function creation
*/
public _onLoop;
/**
* Starts the requestAnimatioFrame running or setTimeout if unavailable in browser
* @method start
@@ -104,12 +109,14 @@ module Phaser {
if (!window.requestAnimationFrame)
{
this._isSetTimeOut = true;
this._timeOutID = window.setTimeout(() => this.SetTimeoutUpdate(), 0);
this._onLoop = () => this.SetTimeoutUpdate();
this._timeOutID = window.setTimeout(this._onLoop, 0);
}
else
{
this._isSetTimeOut = false;
window.requestAnimationFrame(() => this.RAFUpdate(0));
this._onLoop = () => this.RAFUpdate(0);
window.requestAnimationFrame(this._onLoop);
}
this.isRunning = true;
@@ -148,7 +155,9 @@ module Phaser {
this.callback.call(this._game);
}
window.requestAnimationFrame((time) => this.RAFUpdate(time));
this._onLoop = (time) => this.RAFUpdate(time);
window.requestAnimationFrame(this._onLoop);
}
@@ -160,7 +169,9 @@ module Phaser {
this._game.time.update(Date.now());
this._timeOutID = window.setTimeout(() => this.SetTimeoutUpdate(), 16.7);
this._onLoop = () => this.SetTimeoutUpdate();
this._timeOutID = window.setTimeout(this._onLoop, 16);
if (this.callback)
{
+9 -12
View File
@@ -1,6 +1,7 @@
var Phaser;
(function (Phaser) {
/// <reference path="../Phaser/Game.ts" />
/// <reference path="IPlugin.ts" />
/**
* Phaser - Example Plugin
*/
@@ -13,31 +14,27 @@ var Phaser;
}
Example.prototype.preUpdate = /**
* Pre-update is called at the start of the update cycle, before any other updates have taken place.
* It is only called if active is set to true.
*/
function () {
};
Example.prototype.postUpdate = /**
* Post-update is called at the end of the objects update cycle, after other update logic has taken place.
* It is only called if active is set to true.
*/
function () {
};
Example.prototype.preRender = /**
* Pre-render is called at the start of the object render cycle, before any transforms have taken place.
* It happens directly AFTER a canvas context.save has happened if added to a Camera.
* @param {Camera} camera
* Pre-render is called right before the Game Renderer starts and before any custom preRender callbacks have been run.
* It is only called if visible is set to true.
*/
function (camera) {
};
Example.prototype.render = /**
* render is called during the objects render cycle, right after all transforms have finished, but before any children/image data is rendered.
* @param {Camera} camera
*/
function (camera) {
function () {
};
Example.prototype.postRender = /**
* Post-render is called during the objects render cycle, after the children/image data has been rendered.
* Post-render is called after every camera and game object has been rendered, also after any custom postRender callbacks have been run.
* It is only called if visible is set to true.
*/
function (camera) {
function () {
};
Example.prototype.destroy = /**
* Clear down this Plugin and null out references
+3
View File
@@ -165,6 +165,9 @@ V1.0.0
* Added Sprite.bringToTop()
* Added Stage.disableVisibilityChange to stop the auto pause/resume from ever firing.
* Added crop support to the Texture component, so you can do Sprite.crop to restrict rendering to a specified Rectangle without distortion.
* Added references to all the event listener functions so they can be cleanly destroyed.
* Fixed interesting Firefox bug when an audio track ended it fired another 'canplaythrough' event, confusing the Loader.
V0.9.6
+3 -1
View File
@@ -22,8 +22,10 @@
// Finally we set the fill color that is put over the top of the mirror effect.
mirror.start(0, 400, new Phaser.Rectangle(0, 0, 800, 400), 'rgba(0, 0, 100, 0.7)');
// Experiment with variations on these to see the different mirror effects that can be achieved.
mirror.flipX = true;
//mirror.flipX = true;
//mirror.flipY = true;
// The Mirror FX will literally mirror EVERYTHING that was rendered to the camera, in the case of this test it's
// just a single image, but when used on a full game it can look really quite neat.
game.add.sprite(0, 0, 'backdrop');
}
function update() {
+13
View File
@@ -136,6 +136,19 @@ if ($state == false && $mobile == false)
<div id="links">
<?php
$files = dirToArray(dirname(__FILE__));
$total = 0;
foreach ($files as $key => $value) {
// If $key is an array, output it as an h2 or something
if (is_array($value) && count($value) > 0)
{
$total += count($value);
}
}
echo "<h2>Total Tests: $total </h2>";
foreach ($files as $key => $value) {
+76 -71
View File
@@ -7780,8 +7780,6 @@ var Phaser;
break;
case 'audio':
file.url = this.getAudioURL(file.url);
//console.log('Loader audio');
//console.log(file.url);
if(file.url !== null) {
// WebAudio or Audio Tag?
if(this._game.sound.usingWebAudio) {
@@ -7797,7 +7795,6 @@ var Phaser;
} else if(this._game.sound.usingAudioTag) {
if(this._game.sound.touchLocked) {
// If audio is locked we can't do this yet, so need to queue this load request somehow. Bum.
//console.log('Audio is touch locked');
file.data = new Audio();
file.data.name = file.key;
file.data.preload = 'auto';
@@ -7811,9 +7808,7 @@ var Phaser;
};
file.data.preload = 'auto';
file.data.src = file.url;
file.data.addEventListener('canplaythrough', function () {
return _this.fileComplete(file.key);
}, false);
file.data.addEventListener('canplaythrough', Phaser.GAMES[this._game.id].load.fileComplete(file.key), false);
file.data.load();
}
}
@@ -7861,6 +7856,10 @@ var Phaser;
*/
function (key) {
var _this = this;
if(!this._fileList[key]) {
throw new Error('Phaser.Loader fileComplete invalid key ' + key);
return;
}
this._fileList[key].loaded = true;
var file = this._fileList[key];
var loadNext = true;
@@ -7909,6 +7908,7 @@ var Phaser;
});
}
} else {
file.data.removeEventListener('canplaythrough', Phaser.GAMES[this._game.id].load.fileComplete);
this._game.cache.addSound(file.key, file.url, file.data, false, true);
}
break;
@@ -8433,7 +8433,10 @@ var Phaser;
this.game = game;
GameMath.sinA = [];
GameMath.cosA = [];
for(var i = 0; i < 360; i++) {
// Android 4 stock browser bug fix
GameMath.sinA.push(0);
GameMath.cosA.push(0);
for(var i = 1; i < 360; i++) {
GameMath.sinA.push(Math.sin(this.degreesToRadians(i)));
GameMath.cosA.push(Math.cos(this.degreesToRadians(i)));
}
@@ -13403,6 +13406,7 @@ var Phaser;
var Phaser;
(function (Phaser) {
Phaser.VERSION = 'Phaser version 1.0.0';
Phaser.GAMES = [];
})(Phaser || (Phaser = {}));
var Phaser;
(function (Phaser) {
@@ -15407,14 +15411,16 @@ var Phaser;
}
if(!window.requestAnimationFrame) {
this._isSetTimeOut = true;
this._timeOutID = window.setTimeout(function () {
this._onLoop = function () {
return _this.SetTimeoutUpdate();
}, 0);
};
this._timeOutID = window.setTimeout(this._onLoop, 0);
} else {
this._isSetTimeOut = false;
window.requestAnimationFrame(function () {
this._onLoop = function () {
return _this.RAFUpdate(0);
});
};
window.requestAnimationFrame(this._onLoop);
}
this.isRunning = true;
};
@@ -15435,14 +15441,13 @@ var Phaser;
* @method RAFUpdate
**/
function (time) {
var _this = this;
this._game.time.update(time);
if(this.callback) {
this.callback.call(this._game);
}
window.requestAnimationFrame(function (time) {
return _this.RAFUpdate(time);
});
//this._onLoop = (time) => this.RAFUpdate(time);
//window.requestAnimationFrame(this._onLoop);
window.requestAnimationFrame();
};
RequestAnimationFrame.prototype.SetTimeoutUpdate = /**
* The update method for the setTimeout
@@ -16331,15 +16336,18 @@ var Phaser;
// Android stock browser fires mouse events even if you preventDefault on the touchStart, so ...
return;
}
this._game.stage.canvas.addEventListener('mousedown', function (event) {
this._onMouseDown = function (event) {
return _this.onMouseDown(event);
}, true);
this._game.stage.canvas.addEventListener('mousemove', function (event) {
};
this._onMouseMove = function (event) {
return _this.onMouseMove(event);
}, true);
this._game.stage.canvas.addEventListener('mouseup', function (event) {
};
this._onMouseUp = function (event) {
return _this.onMouseUp(event);
}, true);
};
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);
};
Mouse.prototype.onMouseDown = /**
* @param {MouseEvent} event
@@ -16385,10 +16393,10 @@ var Phaser;
* @method stop
*/
function () {
//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);
};
return Mouse;
})();
Phaser.Mouse = Mouse;
@@ -16417,13 +16425,14 @@ var Phaser;
this._game = game;
}
Keyboard.prototype.start = function () {
var _this = this;
document.body.addEventListener('keydown', function (event) {
return _this.onKeyDown(event);
}, false);
document.body.addEventListener('keyup', function (event) {
return _this.onKeyUp(event);
}, false);
document.body.addEventListener('keydown', Phaser.GAMES[this._game.id].input.keyboard.onKeyDown, false);
document.body.addEventListener('keyup', Phaser.GAMES[this._game.id].input.keyboard.onKeyUp, false);
//document.body.addEventListener('keydown', (event: KeyboardEvent) => this.onKeyDown(event), false);
//document.body.addEventListener('keyup', (event: KeyboardEvent) => this.onKeyUp(event), false);
};
Keyboard.prototype.stop = function () {
document.body.removeEventListener('keydown', Phaser.GAMES[this._game.id].input.keyboard.onKeyDown);
document.body.removeEventListener('keyup', Phaser.GAMES[this._game.id].input.keyboard.onKeyUp);
};
Keyboard.prototype.addKeyCapture = /**
* By default when a key is pressed Phaser will not stop the event from propagating up to the browser.
@@ -16676,30 +16685,22 @@ var Phaser;
* @method start
*/
function () {
var _this = this;
if(this._game.device.touch) {
this._game.stage.canvas.addEventListener('touchstart', function (event) {
return _this.onTouchStart(event);
}, false);
this._game.stage.canvas.addEventListener('touchmove', function (event) {
return _this.onTouchMove(event);
}, false);
this._game.stage.canvas.addEventListener('touchend', function (event) {
return _this.onTouchEnd(event);
}, false);
this._game.stage.canvas.addEventListener('touchenter', function (event) {
return _this.onTouchEnter(event);
}, false);
this._game.stage.canvas.addEventListener('touchleave', function (event) {
return _this.onTouchLeave(event);
}, false);
this._game.stage.canvas.addEventListener('touchcancel', function (event) {
return _this.onTouchCancel(event);
}, false);
document.addEventListener('touchmove', function (event) {
return _this.consumeTouchMove(event);
}, false);
}
this._game.stage.canvas.addEventListener('touchstart', Phaser.GAMES[this._game.id].input.touch.onTouchStart, false);
this._game.stage.canvas.addEventListener('touchmove', Phaser.GAMES[this._game.id].input.touch.onTouchMove, false);
this._game.stage.canvas.addEventListener('touchend', Phaser.GAMES[this._game.id].input.touch.onTouchEnd, false);
this._game.stage.canvas.addEventListener('touchenter', Phaser.GAMES[this._game.id].input.touch.onTouchEnter, false);
this._game.stage.canvas.addEventListener('touchleave', Phaser.GAMES[this._game.id].input.touch.onTouchLeave, false);
this._game.stage.canvas.addEventListener('touchcancel', Phaser.GAMES[this._game.id].input.touch.onTouchCancel, false);
document.addEventListener('touchmove', Phaser.GAMES[this._game.id].input.touch.consumeTouchMove, false);
//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);
}
};
Touch.prototype.consumeTouchMove = /**
* Prevent iOS bounce-back (doesn't work?)
@@ -16819,13 +16820,14 @@ var Phaser;
*/
function () {
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', Phaser.GAMES[this._game.id].input.touch.onTouchStart);
this._game.stage.canvas.removeEventListener('touchmove', Phaser.GAMES[this._game.id].input.touch.onTouchMove);
this._game.stage.canvas.removeEventListener('touchend', Phaser.GAMES[this._game.id].input.touch.onTouchEnd);
this._game.stage.canvas.removeEventListener('touchenter', Phaser.GAMES[this._game.id].input.touch.onTouchEnter);
this._game.stage.canvas.removeEventListener('touchleave', Phaser.GAMES[this._game.id].input.touch.onTouchLeave);
this._game.stage.canvas.removeEventListener('touchcancel', Phaser.GAMES[this._game.id].input.touch.onTouchCancel);
document.removeEventListener('touchmove', Phaser.GAMES[this._game.id].input.touch.consumeTouchMove);
}
};
return Touch;
})();
@@ -18324,6 +18326,7 @@ var Phaser;
* @type {boolean}
*/
this.isRunning = false;
this.id = Phaser.GAMES.push(this) - 1;
this.callbackContext = callbackContext;
this.onInitCallback = initCallback;
this.onCreateCallback = createCallback;
@@ -18331,16 +18334,15 @@ var Phaser;
this.onRenderCallback = renderCallback;
this.onDestroyCallback = destroyCallback;
if(document.readyState === 'complete' || document.readyState === 'interactive') {
//setTimeout(() => this.boot(parent, width, height));
setTimeout(function () {
return _this.boot(parent, width, height);
return Phaser.GAMES[_this.id].boot(parent, width, height);
});
} else {
document.addEventListener('DOMContentLoaded', function () {
return _this.boot(parent, width, height);
}, false);
window.addEventListener('load', function () {
return _this.boot(parent, width, height);
}, false);
//document.addEventListener('DOMContentLoaded', () => this.boot(parent, width, height), false);
//window.addEventListener('load', () => this.boot(parent, width, height), false);
document.addEventListener('DOMContentLoaded', Phaser.GAMES[this.id].boot(parent, width, height), false);
window.addEventListener('load', Phaser.GAMES[this.id].boot(parent, width, height), false);
}
}
Game.prototype.boot = /**
@@ -18355,10 +18357,13 @@ var Phaser;
return;
}
if(!document.body) {
window.setTimeout(function () {
return _this.boot(parent, width, height);
//window.setTimeout(() => this.boot(parent, width, height), 13);
setTimeout(function () {
return Phaser.GAMES[_this.id].boot(parent, width, height);
}, 13);
} else {
document.removeEventListener('DOMContentLoaded', Phaser.GAMES[this.id].boot);
window.removeEventListener('load', Phaser.GAMES[this.id].boot);
this.device = new Phaser.Device();
this.net = new Phaser.Net(this);
this.math = new Phaser.GameMath(this);