Phaser.RequestAnimationFrame = function (game, forceSetTimeOut){ if (typeof forceSetTimeOut === 'undefined') { forceSetTimeOut = false ; } this.game = game; this.isRunning = false ; this.forceSetTimeOut = forceSetTimeOut; var vendors = ['ms', 'moz', 'webkit', 'o'] ; for (var x = 0; x < _AN_Read_length('length', vendors) && !window.requestAnimationFrame; x++ ){ window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame']; window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame']; } this._isSetTimeOut = false ; this._onLoop = null ; this._timeOutID = null ; } ; Phaser.RequestAnimationFrame.prototype = { start: function (){ this.isRunning = true ; var _this = this; if (!window.requestAnimationFrame || this.forceSetTimeOut) { this._isSetTimeOut = true ; this._onLoop = function (){ return _this.updateSetTimeout(); } ; this._timeOutID = _AN_Call_settimeout('setTimeout', window, this._onLoop, 0); } else { this._isSetTimeOut = false ; this._onLoop = function (time){ return _this.updateRAF(time); } ; this._timeOutID = window.requestAnimationFrame(this._onLoop); } } , updateRAF: function (){ this.game.update(Date.now()); this._timeOutID = window.requestAnimationFrame(this._onLoop); } , updateSetTimeout: function (){ this.game.update(Date.now()); this._timeOutID = _AN_Call_settimeout('setTimeout', window, this._onLoop, this.game.time.timeToCall); } , stop: function (){ if (this._isSetTimeOut) { clearTimeout(this._timeOutID); } else { window.cancelAnimationFrame(this._timeOutID); } this.isRunning = false ; } , isSetTimeOut: function (){ return this._isSetTimeOut; } , isRAF: function (){ return (this._isSetTimeOut === false ); } } ; Phaser.RequestAnimationFrame.prototype.constructor = Phaser.RequestAnimationFrame;