2016-11-06 12:18:08 +00:00
|
|
|
Phaser.State.Systems = function (state, config)
|
|
|
|
{
|
|
|
|
this.state = state;
|
|
|
|
|
|
|
|
this.config = config;
|
|
|
|
|
|
|
|
// State specific managers (Factory, Tweens, Loader, Physics, etc)
|
|
|
|
this.add;
|
|
|
|
this.input;
|
|
|
|
this.load;
|
|
|
|
this.tweens;
|
2016-11-08 01:50:57 +00:00
|
|
|
this.mainloop;
|
|
|
|
this.updates;
|
2016-11-06 12:18:08 +00:00
|
|
|
|
|
|
|
// State specific properties (transform, data, children, etc)
|
2016-11-07 17:05:14 +00:00
|
|
|
this.camera;
|
2016-11-06 12:18:08 +00:00
|
|
|
this.children;
|
|
|
|
this.color;
|
|
|
|
this.data;
|
|
|
|
this.fbo;
|
|
|
|
this.time;
|
|
|
|
this.transform;
|
|
|
|
};
|
|
|
|
|
|
|
|
Phaser.State.Systems.prototype.constructor = Phaser.State.Systems;
|
|
|
|
|
|
|
|
Phaser.State.Systems.prototype = {
|
|
|
|
|
|
|
|
init: function ()
|
|
|
|
{
|
|
|
|
// State specific managers (Factory, Tweens, Loader, Physics, etc)
|
|
|
|
this.add = new Phaser.GameObject.Factory(this.state);
|
|
|
|
this.load = new Phaser.Loader(this.state);
|
2016-11-09 12:25:26 +00:00
|
|
|
this.mainloop = new Phaser.State.MainLoop(this.state, this.state.settings.fps);
|
2016-11-08 01:50:57 +00:00
|
|
|
this.updates = new Phaser.UpdateManager(this.state);
|
|
|
|
this.tweens = new Phaser.TweenManager(this.state);
|
2016-11-10 00:10:39 +00:00
|
|
|
this.input = new Phaser.State.Input(this.state);
|
2016-11-11 02:20:31 +00:00
|
|
|
this.physics = new Phaser.Physics.Arcade(this.state, 800, 600);
|
2016-11-06 12:18:08 +00:00
|
|
|
|
|
|
|
// State specific properties (transform, data, children, etc)
|
2016-11-07 17:05:14 +00:00
|
|
|
this.camera = new Phaser.Camera(this.state, 0, 0, 800, 600);
|
2016-11-06 12:18:08 +00:00
|
|
|
this.children = new Phaser.Component.Children(this.state);
|
|
|
|
this.color = new Phaser.Component.Color(this.state);
|
|
|
|
this.data = new Phaser.Component.Data(this.state);
|
2016-11-07 17:05:14 +00:00
|
|
|
this.transform = this.camera.transform;
|
2016-11-06 12:18:08 +00:00
|
|
|
|
2016-11-10 00:10:39 +00:00
|
|
|
// Boot
|
|
|
|
|
|
|
|
this.input.init();
|
|
|
|
|
2016-11-06 12:18:08 +00:00
|
|
|
// Defaults
|
|
|
|
|
|
|
|
this.state.add = this.add;
|
|
|
|
this.state.load = this.load;
|
|
|
|
this.state.children = this.children;
|
|
|
|
this.state.color = this.color;
|
2016-11-08 01:50:57 +00:00
|
|
|
this.state.data = this.data;
|
2016-11-07 17:05:14 +00:00
|
|
|
this.state.camera = this.camera;
|
2016-11-10 00:10:39 +00:00
|
|
|
this.state.input = this.input;
|
2016-11-07 17:05:14 +00:00
|
|
|
this.state.transform = this.camera.transform;
|
2016-11-10 02:01:02 +00:00
|
|
|
this.state.state = this.state.game.state;
|
2016-11-06 12:18:08 +00:00
|
|
|
|
|
|
|
// Here we can check which Systems to install as properties into the State object
|
|
|
|
// (default systems always exist in here, regardless)
|
|
|
|
|
|
|
|
var config = this.config;
|
|
|
|
var t = typeof config;
|
|
|
|
|
|
|
|
if (t !== 'object' || (t === 'object' && !t.hasOwnProperty('systems')))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// this.key = (config.hasOwnProperty('key')) ? config.key : '';
|
2016-11-08 01:50:57 +00:00
|
|
|
},
|
|
|
|
|
2016-11-09 15:33:47 +00:00
|
|
|
begin: function (timestamp, frameDelta)
|
|
|
|
{
|
|
|
|
},
|
|
|
|
|
2016-11-11 02:20:31 +00:00
|
|
|
update: function (timestep, physicsStep)
|
2016-11-09 12:25:26 +00:00
|
|
|
{
|
2016-11-11 02:20:31 +00:00
|
|
|
this.tweens.update(timestep);
|
|
|
|
this.physics.preUpdate(physicsStep);
|
|
|
|
},
|
|
|
|
|
|
|
|
preRender: function ()
|
|
|
|
{
|
|
|
|
this.physics.update();
|
2016-11-09 12:25:26 +00:00
|
|
|
},
|
|
|
|
|
2016-11-09 15:33:47 +00:00
|
|
|
end: function (fps, panic)
|
2016-11-08 01:50:57 +00:00
|
|
|
{
|
2016-11-09 15:33:47 +00:00
|
|
|
if (panic)
|
|
|
|
{
|
|
|
|
// This pattern introduces non-deterministic behavior, but in this case
|
|
|
|
// it's better than the alternative (the application would look like it
|
|
|
|
// was running very quickly until the simulation caught up to real
|
|
|
|
// time).
|
|
|
|
var discardedTime = Math.round(this.mainloop.resetFrameDelta());
|
|
|
|
|
|
|
|
console.warn('Main loop panicked, probably because the browser tab was put in the background. Discarding ' + discardedTime + 'ms');
|
|
|
|
}
|
2016-11-06 12:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|