From 4f10309f2f88ff4b236882ccd660744fa6c3962f Mon Sep 17 00:00:00 2001 From: Rex Date: Thu, 23 Jan 2025 20:55:48 +0800 Subject: [PATCH] Add getDisplayList method to layer game object --- src/gameobjects/layer/Layer.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/gameobjects/layer/Layer.js b/src/gameobjects/layer/Layer.js index eda5058581..b656e4c591 100644 --- a/src/gameobjects/layer/Layer.js +++ b/src/gameobjects/layer/Layer.js @@ -918,6 +918,38 @@ var Layer = new Class({ return this; }, + /** + * Returns a reference to the underlying display list _array_ that contains this Game Object, + * which will be either the Scene's Display List or the internal list belonging + * to its parent Container, if it has one. + * + * If this Game Object is not on a display list or in a container, it will return `null`. + * + * You should be very careful with this method, and understand that it returns a direct reference to the + * internal array used by the Display List. Mutating this array directly can cause all kinds of subtle + * and difficult to debug issues in your game. + * + * @method Phaser.GameObjects.Layer#getDisplayList + * @since 3.85.0 + * + * @return {?Phaser.GameObjects.GameObject[]} The internal Display List array of Game Objects, or `null`. + */ + getDisplayList: function () + { + var list = null; + + if (this.parentContainer) + { + list = this.parentContainer.list; + } + else if (this.displayList) + { + list = this.displayList.list; + } + + return list; + }, + /** * Destroys this Layer removing it from the Display List and Update List and * severing all ties to parent resources.