Automatically remove from display list

This commit is contained in:
Richard Davey 2018-04-05 15:28:34 +01:00
parent ae8706a424
commit 7e64b4d624

View file

@ -115,6 +115,16 @@ var Container = new Class({
*/ */
this.removeCallback = this.removeHandler; this.removeCallback = this.removeHandler;
/**
* A reference to the Scene Display List.
*
* @name Phaser.GameObjects.Container#_displayList
* @type {Phaser.GameObjects.DisplayList}
* @private
* @since 3.4.0
*/
this._displayList = scene.sys.displayList;
this.setPosition(x, y); this.setPosition(x, y);
if (Array.isArray(children)) if (Array.isArray(children))
@ -135,6 +145,8 @@ var Container = new Class({
*/ */
addHandler: function (list, gameObject) addHandler: function (list, gameObject)
{ {
this._displayList.remove(gameObject);
gameObject.on('destroy', this.remove, this); gameObject.on('destroy', this.remove, this);
if (gameObject.parentContainer) if (gameObject.parentContainer)