Skip to content

Commit 157be83

Browse files
committed
The Container will now test to see if any Game Object added to it is already on the display list, or not, and emit its ADDED and REMOVED events accordingly. Fix phaserjs#5267 phaserjs#3876
1 parent 3bd91ea commit 157be83

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

src/gameobjects/container/Container.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ var Class = require('../../utils/Class');
1111
var Components = require('../components');
1212
var Events = require('../events');
1313
var GameObject = require('../GameObject');
14+
var GameObjectEvents = require('../events');
1415
var Rectangle = require('../../geom/rectangle/Rectangle');
1516
var Render = require('./ContainerRender');
1617
var Union = require('../../geom/rectangle/Union');
@@ -452,6 +453,12 @@ var Container = new Class({
452453

453454
gameObject.parentContainer = this;
454455
}
456+
457+
// Is only on the Display List via this Container
458+
if (!this.scene.sys.displayList.exists(gameObject))
459+
{
460+
gameObject.emit(GameObjectEvents.ADDED_TO_SCENE, gameObject, this.scene);
461+
}
455462
},
456463

457464
/**
@@ -471,6 +478,12 @@ var Container = new Class({
471478
{
472479
gameObject.parentContainer = null;
473480
}
481+
482+
// Is only on the Display List via this Container
483+
if (!this.scene.sys.displayList.exists(gameObject))
484+
{
485+
gameObject.emit(GameObjectEvents.REMOVED_FROM_SCENE, gameObject, this.scene);
486+
}
474487
},
475488

476489
/**

0 commit comments

Comments
 (0)