mirror of
https://github.com/photonstorm/phaser
synced 2024-12-14 07:13:00 +00:00
Split into base class and plugin extension so other classes can use them too
This commit is contained in:
parent
e1609fc866
commit
134c67a51b
6 changed files with 100 additions and 49 deletions
|
@ -11,8 +11,8 @@ var CoreScenePlugins = [
|
|||
'GameObjectCreator',
|
||||
'GameObjectFactory',
|
||||
'ScenePlugin',
|
||||
'DisplayList',
|
||||
'UpdateList'
|
||||
'DisplayListPlugin',
|
||||
'UpdateListPlugin'
|
||||
|
||||
];
|
||||
|
||||
|
|
|
@ -1,23 +1,12 @@
|
|||
var Class = require('../utils/Class');
|
||||
var StableSort = require('../utils/array/StableSort');
|
||||
var PluginManager = require('../plugins/PluginManager');
|
||||
|
||||
var DisplayList = new Class({
|
||||
|
||||
initialize:
|
||||
|
||||
function DisplayList (scene)
|
||||
function DisplayList ()
|
||||
{
|
||||
// The Scene that owns this plugin
|
||||
this.scene = scene;
|
||||
|
||||
this.systems = scene.sys;
|
||||
|
||||
if (!scene.sys.settings.isBooted)
|
||||
{
|
||||
scene.sys.events.once('boot', this.boot, this);
|
||||
}
|
||||
|
||||
// The objects that belong to this collection.
|
||||
// The equivalent of the old `Sprite.children` array.
|
||||
this.list = [];
|
||||
|
@ -27,14 +16,6 @@ var DisplayList = new Class({
|
|||
this.position = 0;
|
||||
},
|
||||
|
||||
boot: function ()
|
||||
{
|
||||
var eventEmitter = this.systems.events;
|
||||
|
||||
eventEmitter.on('shutdown', this.shutdown, this);
|
||||
eventEmitter.on('destroy', this.destroy, this);
|
||||
},
|
||||
|
||||
process: function ()
|
||||
{
|
||||
if (this.sortChildrenFlag)
|
||||
|
@ -725,6 +706,4 @@ var DisplayList = new Class({
|
|||
|
||||
});
|
||||
|
||||
PluginManager.register('DisplayList', DisplayList, 'displayList');
|
||||
|
||||
module.exports = DisplayList;
|
||||
|
|
48
src/gameobjects/DisplayListPlugin.js
Normal file
48
src/gameobjects/DisplayListPlugin.js
Normal file
|
@ -0,0 +1,48 @@
|
|||
var Class = require('../utils/Class');
|
||||
var DisplayList = require('./DisplayList');
|
||||
var PluginManager = require('../plugins/PluginManager');
|
||||
|
||||
var DisplayListPlugin = new Class({
|
||||
|
||||
Extends: DisplayList,
|
||||
|
||||
initialize:
|
||||
|
||||
function DisplayListPlugin (scene)
|
||||
{
|
||||
// The Scene that owns this plugin
|
||||
this.scene = scene;
|
||||
|
||||
this.systems = scene.sys;
|
||||
|
||||
if (!scene.sys.settings.isBooted)
|
||||
{
|
||||
scene.sys.events.once('boot', this.boot, this);
|
||||
}
|
||||
|
||||
DisplayList.call(this);
|
||||
},
|
||||
|
||||
boot: function ()
|
||||
{
|
||||
var eventEmitter = this.systems.events;
|
||||
|
||||
eventEmitter.on('shutdown', this.shutdown, this);
|
||||
eventEmitter.on('destroy', this.destroy, this);
|
||||
},
|
||||
|
||||
shutdown: function ()
|
||||
{
|
||||
this.removeAll();
|
||||
},
|
||||
|
||||
destroy: function ()
|
||||
{
|
||||
this.shutdown();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
PluginManager.register('DisplayListPlugin', DisplayListPlugin, 'displayList');
|
||||
|
||||
module.exports = DisplayListPlugin;
|
|
@ -1,36 +1,16 @@
|
|||
var Class = require('../utils/Class');
|
||||
var PluginManager = require('../plugins/PluginManager');
|
||||
|
||||
var UpdateList = new Class({
|
||||
|
||||
initialize:
|
||||
|
||||
function UpdateList (scene)
|
||||
function UpdateList ()
|
||||
{
|
||||
this.scene = scene;
|
||||
|
||||
this.systems = scene.sys;
|
||||
|
||||
if (!scene.sys.settings.isBooted)
|
||||
{
|
||||
scene.sys.events.once('boot', this.boot, this);
|
||||
}
|
||||
|
||||
this._list = [];
|
||||
this._pendingInsertion = [];
|
||||
this._pendingRemoval = [];
|
||||
},
|
||||
|
||||
boot: function ()
|
||||
{
|
||||
var eventEmitter = this.systems.events;
|
||||
|
||||
eventEmitter.on('preupdate', this.preUpdate, this);
|
||||
eventEmitter.on('update', this.update, this);
|
||||
eventEmitter.on('shutdown', this.shutdown, this);
|
||||
eventEmitter.on('destroy', this.destroy, this);
|
||||
},
|
||||
|
||||
add: function (child)
|
||||
{
|
||||
// Is child already in this list?
|
||||
|
@ -130,12 +110,8 @@ var UpdateList = new Class({
|
|||
destroy: function ()
|
||||
{
|
||||
this.shutdown();
|
||||
|
||||
this.scene = undefined;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
PluginManager.register('UpdateList', UpdateList, 'updateList');
|
||||
|
||||
module.exports = UpdateList;
|
||||
|
|
46
src/gameobjects/UpdateListPlugin.js
Normal file
46
src/gameobjects/UpdateListPlugin.js
Normal file
|
@ -0,0 +1,46 @@
|
|||
var Class = require('../utils/Class');
|
||||
var PluginManager = require('../plugins/PluginManager');
|
||||
var UpdateList = require('./UpdateList');
|
||||
|
||||
var UpdateListPlugin = new Class({
|
||||
|
||||
Extends: UpdateList,
|
||||
|
||||
initialize:
|
||||
|
||||
function UpdateListPlugin (scene)
|
||||
{
|
||||
this.scene = scene;
|
||||
|
||||
this.systems = scene.sys;
|
||||
|
||||
if (!scene.sys.settings.isBooted)
|
||||
{
|
||||
scene.sys.events.once('boot', this.boot, this);
|
||||
}
|
||||
|
||||
UpdateList.call(this);
|
||||
},
|
||||
|
||||
boot: function ()
|
||||
{
|
||||
var eventEmitter = this.systems.events;
|
||||
|
||||
eventEmitter.on('preupdate', this.preUpdate, this);
|
||||
eventEmitter.on('update', this.update, this);
|
||||
eventEmitter.on('shutdown', this.shutdown, this);
|
||||
eventEmitter.on('destroy', this.destroy, this);
|
||||
},
|
||||
|
||||
destroy: function ()
|
||||
{
|
||||
this.shutdown();
|
||||
|
||||
this.scene = undefined;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
PluginManager.register('UpdateListPlugin', UpdateListPlugin, 'updateList');
|
||||
|
||||
module.exports = UpdateListPlugin;
|
|
@ -3,7 +3,9 @@
|
|||
var GameObjects = {
|
||||
|
||||
DisplayList: require('./DisplayList'),
|
||||
DisplayListPlugin: require('./DisplayListPlugin'),
|
||||
UpdateList: require('./UpdateList'),
|
||||
UpdateListPlugin: require('./UpdateListPlugin'),
|
||||
GameObjectCreator: require('./GameObjectCreator'),
|
||||
GameObjectFactory: require('./GameObjectFactory'),
|
||||
|
||||
|
|
Loading…
Reference in a new issue