Merge pull request #6039 from rexrainbow/layer-destroy

Destroy game objects safely in layer.destroy()
This commit is contained in:
Richard Davey 2022-04-14 15:42:46 +01:00 committed by GitHub
commit cceb70a937
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -933,8 +933,10 @@ var Layer = new Class({
* @method Phaser.GameObjects.Layer#destroy
* @fires Phaser.GameObjects.Events#DESTROY
* @since 3.50.0
*
* @param {boolean} [fromScene=false] - `True` if this Game Object is being destroyed by the Scene, `false` if not.
*/
destroy: function ()
destroy: function (fromScene)
{
// This Game Object has already been destroyed
if (!this.scene || this.ignoreDestroy)
@ -944,11 +946,11 @@ var Layer = new Class({
this.emit(GameObjectEvents.DESTROY, this);
var i = this.list.length;
var list = this.list;
while (i--)
while (list.length)
{
this.list[i].destroy();
list[0].destroy(fromScene);
}
this.removeAllListeners();