Phaser.Game = function (width, height, renderer, parent, state, transparent, antialias){ if (typeof width === "undefined") { width = 800; } if (typeof height === "undefined") { height = 600; } if (typeof renderer === "undefined") { renderer = Phaser.AUTO; } if (typeof parent === "undefined") { parent = ''; } if (typeof state === "undefined") { state = null ; } if (typeof transparent === "undefined") { transparent = false ; } if (typeof antialias === "undefined") { antialias = true ; } this.id = Phaser.GAMES.push(this) - 1; this.parent = parent; this.width = width; this.height = height; this.transparent = transparent; this.antialias = antialias; this.renderType = renderer; this.state = new Phaser.StateManager(this, state); var _this = this; this._onBoot = function (){ return _this.boot(); } ; if (document.readyState === 'complete' || document.readyState === 'interactive') { _AN_Call_settimeout('setTimeout', window, this._onBoot, 0); } else { document.addEventListener('DOMContentLoaded', this._onBoot, false ); window.addEventListener('load', this._onBoot, false ); } return this; } ; Phaser.Game.prototype = { _tempState: null , _onBoot: null , id: 0, width: 0, height: 0, transparent: false , antialias: true , parent: '', renderType: 0, renderer: null , _loadComplete: false , paused: false , isBooted: false , isRunning: false , raf: null , state: null , add: null , cache: null , input: null , load: null , math: null , net: null , sound: null , stage: null , time: null , tweens: null , world: null , physics: null , rnd: null , device: null , camera: null , canvas: null , context: null , debug: null , boot: function (){ if (this.isBooted) { return ; } if (!document.body) { _AN_Call_settimeout('setTimeout', window, this._onBoot, 20); } else { document.removeEventListener('DOMContentLoaded', this._onBoot); window.removeEventListener('load', this._onBoot); this.onPause = new Phaser.Signal(); this.onResume = new Phaser.Signal(); this.isBooted = true ; this.device = new Phaser.Device(); this.math = Phaser.Math; this.rnd = new Phaser.RandomDataGenerator([(Date.now() * Math.random()).toString()] ); this.setUpRenderer(); this.world = new Phaser.World(this); this.stage = new Phaser.Stage(this); this.add = new Phaser.GameObjectFactory(this); this.cache = new Phaser.Cache(this); this.load = new Phaser.Loader(this); this.time = new Phaser.Time(this); this.tweens = new Phaser.TweenManager(this); this.input = new Phaser.Input(this); this.plugins = new Phaser.PluginManager(this, this); this.net = new Phaser.Net(this); this.debug = new Phaser.Utils.Debug(this); this.load.onLoadComplete.add(this.loadComplete, this); this.world.boot(); this.state.boot(); this.input.boot(); if (this.renderType == Phaser.CANVAS) { console.log('%cPhaser ' + Phaser.VERSION + ' initialized. Rendering to Canvas', 'color: #ffff33; background: #000000'); } else { console.log('%cPhaser ' + Phaser.VERSION + ' initialized. Rendering to WebGL', 'color: #ffff33; background: #000000'); } this.isRunning = true ; this._loadComplete = false ; this.raf = new Phaser.RequestAnimationFrame(this); this.raf.start(); } } , setUpRenderer: function (){ if (this.renderType == Phaser.CANVAS || (this.renderType == Phaser.AUTO && this.device.webGL == false )) { if (this.device.canvas) { this.renderType = Phaser.CANVAS; this.renderer = new PIXI.CanvasRenderer(this.width, this.height, null , this.transparent); Phaser.Canvas.setSmoothingEnabled(this.renderer.context, this.antialias); this.canvas = this.renderer.view; this.context = this.renderer.context; } else { throw new Error('Phaser.Game - cannot create Canvas or WebGL context, aborting.') } } else { this.renderer = new PIXI.WebGLRenderer(this.width, this.height, null , this.transparent, this.antialias); this.canvas = this.renderer.view; this.context = null ; } Phaser.Canvas.addToDOM(this.renderer.view, this.parent, true ); Phaser.Canvas.setTouchAction(this.renderer.view); } , loadComplete: function (){ this._loadComplete = true ; this.state.loadComplete(); } , update: function (time){ this.time.update(time); this.plugins.preUpdate(); this.input.update(); this.tweens.update(); this.world.update(); this.state.update(); this.plugins.update(); this.renderer.render(this.world._stage); this.state.render(); this.plugins.postRender(); } , destroy: function (){ this.state.destroy(); this.state = null ; this.cache = null ; this.input = null ; this.load = null ; this.sound = null ; this.stage = null ; this.time = null ; this.world = null ; this.isBooted = false ; } } ;