Phaser.Game = function (width, height, renderer, parent, state, transparent, antialias){ this.id = Phaser.GAMES.push(this) - 1; this.config = null ; this.parent = ''; this.width = 800; this.height = 600; this.transparent = false ; this.antialias = true ; this.renderer = Phaser.AUTO; this.renderType = Phaser.AUTO; this.state = null ; this._paused = false ; this._loadComplete = false ; this.isBooted = false ; this.isRunning = false ; this.raf = null ; this.add = null ; this.cache = null ; this.input = null ; this.load = null ; this.math = null ; this.net = null ; this.scale = null ; this.sound = null ; this.stage = null ; this.time = null ; this.tweens = null ; this.world = null ; this.physics = null ; this.rnd = null ; this.device = null ; this.camera = null ; this.canvas = null ; this.context = null ; this.debug = null ; this.particles = null ; this.stepping = false ; this.pendingStep = false ; this.stepCount = 0; if (_AN_Read_length('length', arguments) === 1 && typeof arguments[0] === 'object') { this.parseConfig(arguments[0]); } else { if (typeof width !== 'undefined') { this.width = width; } if (typeof height !== 'undefined') { this.height = height; } if (typeof renderer !== 'undefined') { this.renderer = renderer; this.renderType = renderer; } if (typeof parent !== 'undefined') { this.parent = parent; } if (typeof transparent !== 'undefined') { this.transparent = transparent; } if (typeof antialias !== 'undefined') { this.antialias = antialias; } 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 = { parseConfig: function (config){ this.config = config; if (config.width) { this.width = this.parseDimension(config.width, 0); } if (config.height) { this.height = this.parseDimension(config.height, 1); } if (config.renderer) { this.renderer = config.renderer; this.renderType = config.renderer; } if (config.parent) { this.parent = config.parent; } if (config.transparent) { this.transparent = config.transparent; } if (config.antialias) { this.antialias = config.antialias; } var state = null ; if (config.state) { state = config.state; } this.state = new Phaser.StateManager(this, state); } , parseDimension: function (size, dimension){ var f = 0; var px = 0; if (typeof size === 'string') { if (size.substr(-1) === '%') { f = parseInt(size, 10) / 100; if (dimension === 0) { px = window.innerWidth * f; } else { px = window.innerHeight * f; } } else { px = parseInt(size, 10); } } else { px = size; } return px; } , 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.stage = new Phaser.Stage(this, this.width, this.height); this.scale = new Phaser.StageScaleMode(this, this.width, this.height); this.setUpRenderer(); this.world = new Phaser.World(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.sound = new Phaser.SoundManager(this); this.physics = new Phaser.Physics.World(this); this.particles = new Phaser.Particles(this); this.plugins = new Phaser.PluginManager(this, this); this.net = new Phaser.Net(this); this.debug = new Phaser.Utils.Debug(this); this.time.boot(); this.stage.boot(); this.world.boot(); this.input.boot(); this.sound.boot(); this.state.boot(); this.load.onLoadComplete.add(this.loadComplete, this); this.showDebugHeader(); this.isRunning = true ; this._loadComplete = false ; this.raf = new Phaser.RequestAnimationFrame(this); this.raf.start(); } } , showDebugHeader: function (){ var v = Phaser.DEV_VERSION; var r = 'Canvas'; var a = 'HTML Audio'; if (this.renderType == Phaser.WEBGL) { r = 'WebGL'; } else if (this.renderType == Phaser.HEADLESS) { r = 'Headless'; } if (this.device.webAudio) { a = 'WebAudio'; } if (this.device.chrome) { var args = ['%c %c %c Phaser v' + v + ' - Renderer: ' + r + ' - Audio: ' + a + ' %c %c ', 'background: #00bff3', 'background: #0072bc', 'color: #ffffff; background: #003471', 'background: #0072bc', 'background: #00bff3'] ; console.log.apply(console, args); } else { console.log('Phaser v' + v + ' - Renderer: ' + r + ' - Audio: ' + a); } } , setUpRenderer: function (){ if (this.renderType === Phaser.HEADLESS || this.renderType === Phaser.CANVAS || (this.renderType === Phaser.AUTO && this.device.webGL === false )) { if (this.device.canvas) { if (this.renderType === Phaser.AUTO) { this.renderType = Phaser.CANVAS; } this.renderer = new PIXI.CanvasRenderer(this.width, this.height, this.canvas, this.transparent); Phaser.Canvas.setSmoothingEnabled(this.renderer.context, this.antialias); this.context = this.renderer.context; } else { throw new Error('Phaser.Game - cannot create Canvas or WebGL context, aborting.') } } else { this.renderType = Phaser.WEBGL; this.renderer = new PIXI.WebGLRenderer(this.width, this.height, this.canvas, this.transparent, this.antialias); this.context = null ; } Phaser.Canvas.addToDOM(this.canvas, this.parent, true ); Phaser.Canvas.setTouchAction(this.canvas); } , loadComplete: function (){ this._loadComplete = true ; this.state.loadComplete(); } , update: function (time){ this.time.update(time); if (this._paused) { this.renderer.render(this.stage); this.plugins.render(); this.state.render(); } else { if (!this.pendingStep) { if (this.stepping) { this.pendingStep = true ; } this.plugins.preUpdate(); this.stage.preUpdate(); this.stage.update(); this.tweens.update(); this.sound.update(); this.input.update(); this.state.update(); this.physics.update(); this.particles.update(); this.plugins.update(); this.stage.postUpdate(); this.plugins.postUpdate(); } if (this.renderType !== Phaser.HEADLESS) { this.renderer.render(this.stage); this.plugins.render(); this.state.render(); this.plugins.postRender(); } } } , enableStep: function (){ this.stepping = true ; this.pendingStep = false ; this.stepCount = 0; } , disableStep: function (){ this.stepping = false ; this.pendingStep = false ; } , step: function (){ this.pendingStep = false ; this.stepCount++ ; } , destroy: function (){ this.raf.stop(); this.input.destroy(); 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 ; } } ; Phaser.Game.prototype.constructor = Phaser.Game; Object.defineProperty(Phaser.Game.prototype, "paused", { get: function (){ return this._paused; } , set: function (value){ if (value === true ) { if (this._paused === false ) { this._paused = true ; this.onPause.dispatch(this); } } else { if (this._paused) { this._paused = false ; this.onResume.dispatch(this); } } } } );