phaser/src/scene/Systems.js

189 lines
4 KiB
JavaScript
Raw Normal View History

2018-01-16 19:49:13 +00:00
var Class = require('../utils/Class');
var CoreScenePlugins = require('../CoreScenePlugins');
var GetPhysicsPlugins = require('./GetPhysicsPlugins');
var GetScenePlugins = require('./GetScenePlugins');
var GlobalPlugins = require('../GlobalPlugins');
var Settings = require('./Settings');
var Systems = new Class({
initialize:
function Systems (scene, config)
{
this.scene = scene;
this.game;
this.config = config;
this.settings = Settings.create(config);
// Set by the SceneManager - a reference to the Scene canvas / context
this.canvas;
this.context;
// Global Systems - these are single-instance global managers that belong to Game
this.anims;
this.cache;
this.plugins;
this.registry;
2018-01-11 14:48:43 +00:00
this.sound;
this.textures;
// Core Plugins - these are non-optional Scene plugins, needed by lots of the other systems
2018-01-16 02:08:22 +00:00
this.add;
this.cameras;
this.displayList;
this.events;
2018-01-16 02:08:22 +00:00
this.make;
this.scenePlugin;
this.updateList;
},
init: function (game)
{
this.game = game;
var pluginManager = game.plugins;
this.plugins = pluginManager;
pluginManager.installGlobal(this, GlobalPlugins);
pluginManager.installLocal(this, CoreScenePlugins);
pluginManager.installLocal(this, GetScenePlugins(this));
pluginManager.installLocal(this, GetPhysicsPlugins(this));
2018-01-16 02:08:22 +00:00
this.events.emit('boot', this);
this.settings.isBooted = true;
},
install: function (plugin)
{
if (!Array.isArray(plugin))
{
plugin = [ plugin ];
}
this.plugins.installLocal(this, plugin);
2018-01-16 02:08:22 +00:00
},
step: function (time, delta)
{
this.events.emit('preupdate', time, delta);
2017-06-30 03:09:19 +00:00
if (!this.settings.active)
{
return;
}
2018-01-16 02:08:22 +00:00
this.events.emit('update', time, delta);
this.scene.update.call(this.scene, time, delta);
2017-11-08 17:18:10 +00:00
2018-01-16 02:08:22 +00:00
this.events.emit('postupdate', time, delta);
},
render: function (interpolation, renderer)
{
if (!this.settings.visible)
{
return;
}
var displayList = this.displayList;
2017-12-15 04:07:32 +00:00
displayList.process();
this.cameras.render(renderer, displayList, interpolation);
},
// Force a sort of the display list on the next render
queueDepthSort: function ()
{
this.displayList.queueDepthSort();
},
// Immediately sorts the display list if the flag is set
depthSort: function ()
{
this.displayList.depthSort();
},
// A paused Scene still renders, it just doesn't run ANY of its update handlers or systems
pause: function ()
{
// Was paused by the SceneManager
this.settings.active = false;
this.events.emit('pause', this);
},
resume: function ()
{
// Was resumed by the SceneManager
this.settings.active = true;
this.events.emit('resume', this);
},
sleep: function ()
{
// Was sent to sleep by the SceneManager
this.settings.active = false;
this.settings.visible = false;
this.events.emit('sleep', this);
},
wake: function ()
{
// Was woken up by the SceneManager
this.settings.active = true;
this.settings.visible = true;
this.events.emit('wake', this);
2017-06-30 03:06:53 +00:00
},
start: function (data)
{
// Was started by the SceneManager
2017-06-30 03:06:53 +00:00
this.settings.data = data;
this.settings.active = true;
this.settings.visible = true;
this.events.emit('start', this);
},
shutdown: function ()
{
// Was stopped by the SceneManager
this.settings.active = false;
2017-06-30 03:06:53 +00:00
this.settings.visible = false;
2018-01-16 02:08:22 +00:00
this.events.emit('shutdown', this);
},
destroy: function ()
{
2018-01-16 02:08:22 +00:00
this.events.emit('destroy', this);
2017-02-08 00:08:09 +00:00
}
});
module.exports = Systems;