Skip to content

Commit 497a9ec

Browse files
committed
Merge pull request phaserjs#1328 from pnstickne/wip-device-to-1
Phaser.Device - inverted from Game
2 parents cbaa36f + fb89176 commit 497a9ec

2 files changed

Lines changed: 412 additions & 301 deletions

File tree

src/core/Game.js

Lines changed: 52 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ Phaser.Game = function (width, height, renderer, parent, state, transparent, ant
206206
/**
207207
* @property {Phaser.Device} device - Contains device information and capabilities.
208208
*/
209-
this.device = null;
209+
this.device = Phaser.Device;
210210

211211
/**
212212
* @property {Phaser.Camera} camera - A handy reference to world.camera.
@@ -366,26 +366,7 @@ Phaser.Game = function (width, height, renderer, parent, state, transparent, ant
366366
this.state = new Phaser.StateManager(this, state);
367367
}
368368

369-
var _this = this;
370-
371-
this._onBoot = function () {
372-
return _this.boot();
373-
};
374-
375-
if (document.readyState === 'complete' || document.readyState === 'interactive')
376-
{
377-
window.setTimeout(this._onBoot, 0);
378-
}
379-
else if (typeof window.cordova !== "undefined" && !navigator['isCocoonJS'])
380-
{
381-
// Cordova, but NOT Cocoon?
382-
document.addEventListener('deviceready', this._onBoot, false);
383-
}
384-
else
385-
{
386-
document.addEventListener('DOMContentLoaded', this._onBoot, false);
387-
window.addEventListener('load', this._onBoot, false);
388-
}
369+
this.device.whenReady(this.boot, this);
389370

390371
return this;
391372

@@ -481,76 +462,62 @@ Phaser.Game.prototype = {
481462
return;
482463
}
483464

484-
if (!document.body)
465+
this.onPause = new Phaser.Signal();
466+
this.onResume = new Phaser.Signal();
467+
this.onBlur = new Phaser.Signal();
468+
this.onFocus = new Phaser.Signal();
469+
470+
this.isBooted = true;
471+
472+
this.math = Phaser.Math;
473+
474+
this.scale = new Phaser.ScaleManager(this, this._width, this._height);
475+
this.stage = new Phaser.Stage(this);
476+
477+
this.setUpRenderer();
478+
479+
this.world = new Phaser.World(this);
480+
this.add = new Phaser.GameObjectFactory(this);
481+
this.make = new Phaser.GameObjectCreator(this);
482+
this.cache = new Phaser.Cache(this);
483+
this.load = new Phaser.Loader(this);
484+
this.time = new Phaser.Time(this);
485+
this.tweens = new Phaser.TweenManager(this);
486+
this.input = new Phaser.Input(this);
487+
this.sound = new Phaser.SoundManager(this);
488+
this.physics = new Phaser.Physics(this, this.physicsConfig);
489+
this.particles = new Phaser.Particles(this);
490+
this.plugins = new Phaser.PluginManager(this);
491+
this.net = new Phaser.Net(this);
492+
493+
this.time.boot();
494+
this.stage.boot();
495+
this.world.boot();
496+
this.scale.boot();
497+
this.input.boot();
498+
this.sound.boot();
499+
this.state.boot();
500+
501+
if (this.config['enableDebug'])
485502
{
486-
window.setTimeout(this._onBoot, 20);
503+
this.debug = new Phaser.Utils.Debug(this);
504+
this.debug.boot();
487505
}
488-
else
489-
{
490-
document.removeEventListener('DOMContentLoaded', this._onBoot);
491-
window.removeEventListener('load', this._onBoot);
492-
493-
this.onPause = new Phaser.Signal();
494-
this.onResume = new Phaser.Signal();
495-
this.onBlur = new Phaser.Signal();
496-
this.onFocus = new Phaser.Signal();
497-
498-
this.isBooted = true;
499-
500-
this.device = new Phaser.Device(this);
501-
502-
this.math = Phaser.Math;
503-
504-
this.scale = new Phaser.ScaleManager(this, this._width, this._height);
505-
this.stage = new Phaser.Stage(this);
506-
507-
this.setUpRenderer();
508-
509-
this.device.checkFullScreenSupport();
510506

511-
this.world = new Phaser.World(this);
512-
this.add = new Phaser.GameObjectFactory(this);
513-
this.make = new Phaser.GameObjectCreator(this);
514-
this.cache = new Phaser.Cache(this);
515-
this.load = new Phaser.Loader(this);
516-
this.time = new Phaser.Time(this);
517-
this.tweens = new Phaser.TweenManager(this);
518-
this.input = new Phaser.Input(this);
519-
this.sound = new Phaser.SoundManager(this);
520-
this.physics = new Phaser.Physics(this, this.physicsConfig);
521-
this.particles = new Phaser.Particles(this);
522-
this.plugins = new Phaser.PluginManager(this);
523-
this.net = new Phaser.Net(this);
507+
this.showDebugHeader();
524508

525-
this.time.boot();
526-
this.stage.boot();
527-
this.world.boot();
528-
this.scale.boot();
529-
this.input.boot();
530-
this.sound.boot();
531-
this.state.boot();
509+
this.isRunning = true;
532510

533-
if (this.config['enableDebug'])
534-
{
535-
this.debug = new Phaser.Utils.Debug(this);
536-
this.debug.boot();
537-
}
538-
539-
this.showDebugHeader();
540-
541-
this.isRunning = true;
542-
543-
if (this.config && this.config['forceSetTimeOut'])
544-
{
545-
this.raf = new Phaser.RequestAnimationFrame(this, this.config['forceSetTimeOut']);
546-
}
547-
else
548-
{
549-
this.raf = new Phaser.RequestAnimationFrame(this, false);
550-
}
551-
552-
this.raf.start();
511+
if (this.config && this.config['forceSetTimeOut'])
512+
{
513+
this.raf = new Phaser.RequestAnimationFrame(this, this.config['forceSetTimeOut']);
553514
}
515+
else
516+
{
517+
this.raf = new Phaser.RequestAnimationFrame(this, false);
518+
}
519+
520+
this.raf.start();
554521

555522
},
556523

0 commit comments

Comments
 (0)