State handling done. Refactored the Game constructor a LOT. Now works from within closures, outside of them, with Phaser.State objects or normal Objects with the right functions inside. Also fixed some small bugs in PluginManager and various scope issues with RAF.

This commit is contained in:
Richard Davey
2013-08-29 07:06:16 +01:00
parent 3c8cd20b70
commit 4bbcc380c5
12 changed files with 558 additions and 475 deletions
+22 -4
View File
@@ -26,6 +26,12 @@ Phaser.RequestAnimationFrame = function(game) {
Phaser.RequestAnimationFrame.prototype = {
/**
* The function called by the update
* @private
**/
_onLoop: null,
/**
* Starts the requestAnimatioFrame running or setTimeout if unavailable in browser
* @method start
@@ -34,15 +40,27 @@ Phaser.RequestAnimationFrame.prototype = {
this.isRunning = true;
var _this = this;
if (!window.requestAnimationFrame)
{
this._isSetTimeOut = true;
this._timeOutID = window.setTimeout(Phaser.GAMES[this.game.id].raf.updateSetTimeout, 0);
this._onLoop = function () {
return _this.updateSetTimeout();
};
this._timeOutID = window.setTimeout(this._onLoop, 0);
}
else
{
this._isSetTimeOut = false;
window.requestAnimationFrame(Phaser.GAMES[this.game.id].raf.updateRAF);
this._onLoop = function () {
return _this.updateRAF();
};
window.requestAnimationFrame(this._onLoop);
}
},
@@ -55,7 +73,7 @@ Phaser.RequestAnimationFrame.prototype = {
this.game.update(time);
window.requestAnimationFrame(Phaser.GAMES[this.game.id].raf.updateRAF);
window.requestAnimationFrame(this._onLoop);
},
@@ -67,7 +85,7 @@ Phaser.RequestAnimationFrame.prototype = {
this.game.update(Date.now());
this._timeOutID = window.setTimeout(Phaser.GAMES[this.game.id].raf.updateSetTimeout, this.game.time.timeToCall);
this._timeOutID = window.setTimeout(this._onLoop, this.game.time.timeToCall);
},