var Class = require('../../utils/Class'); var Components = require('../components'); var GameObject = require('../GameObject'); var List = require('../../structs/List'); var Render = require('./ContainerRender'); var Vector2 = require('../../math/Vector2'); var Container = new Class({ Extends: GameObject, Mixins: [Components.BlendMode, Components.Depth, Components.Transform, Components.Visible, Render, List] , initialize: function Container(scene, x, y, children){ GameObject.call(this, scene, 'Container'); this.parent = this; this.list = [] ; this.position = 0; this.localTransform = new Components.TransformMatrix(); this.tempTransformMatrix = new Components.TransformMatrix(); this.addCallback = this.addHandler; this.removeCallback = this.removeHandler; this._displayList = scene.sys.displayList; this.setPosition(x, y); if (Array.isArray(children)) { this.addMultiple(children); } } , addHandler: function (list, gameObject){ this._displayList.remove(gameObject); gameObject.on('destroy', this.remove, this); if (gameObject.parentContainer) { gameObject.parentContainer.remove(gameObject); } gameObject.parentContainer = list; } , removeHandler: function (list, gameObject){ gameObject.off('destroy', list.remove, this); gameObject.parentContainer = null ; } , pointToContainer: function (source, output){ if (output === undefined) { output = new Vector2(); } if (this.parentContainer) { return this.parentContainer.pointToContainer(source, output); } var tempMatrix = this.tempTransformMatrix; tempMatrix.applyITRS(this.x, this.y, this.rotation, this.scaleX, this.scaleY); tempMatrix.invert(); tempMatrix.transformPoint(source.x, source.y, output); return output; } , localToWorld: function (child, camera, output){ if (camera === undefined) { camera = this.scene.sys.cameras.main; } if (output === undefined) { output = new Vector2(); } if (this.exists(child)) { } return output; } , destroy: function (){ if (!this.scene) { return ; } if (this.preDestroy) { this.preDestroy.call(this); } this.emit('destroy', this); var sys = this.scene.sys; sys.displayList.remove(this); if (this.data) { this.data.destroy(); this.data = undefined; } sys.queueDepthSort(); this.active = false ; this.visible = false ; this.scene = undefined; this.removeAllListeners(); this.removeAll(); this.list = [] ; this.parent = null ; this.parentContainer = null ; } } ); module.exports = Container;