var Class = require('../utils/Class'); var List = require('../structs/List'); var PluginCache = require('../plugins/PluginCache'); var SceneEvents = require('../scene/events'); var StableSort = require('../utils/array/StableSort'); var DisplayList = new Class({ Extends: List, initialize: function DisplayList(scene){ List.call(this, scene); this.sortChildrenFlag = false ; this.scene = scene; this.systems = scene.sys; scene.sys.events.once(SceneEvents.BOOT, this.boot, this); scene.sys.events.on(SceneEvents.START, this.start, this); } , boot: function (){ this.systems.events.once(SceneEvents.DESTROY, this.destroy, this); } , start: function (){ this.systems.events.once(SceneEvents.SHUTDOWN, this.shutdown, this); } , queueDepthSort: function (){ this.sortChildrenFlag = true ; } , depthSort: function (){ if (this.sortChildrenFlag) { StableSort.inplace(this.list, this.sortByDepth); this.sortChildrenFlag = false ; } } , sortByDepth: function (childA, childB){ return childA._depth - childB._depth; } , getChildren: function (){ return this.list; } , shutdown: function (){ var i = _AN_Read_length('length', this.list); while (i-- ){ this.list[i].destroy(true ); } this.list.length = 0; this.systems.events.off(SceneEvents.SHUTDOWN, this.shutdown, this); } , destroy: function (){ this.shutdown(); this.scene.sys.events.off(SceneEvents.START, this.start, this); this.scene = null ; this.systems = null ; } } ); PluginCache.register('DisplayList', DisplayList, 'displayList'); module.exports = DisplayList;