Skip to content

Commit 9c0c037

Browse files
committed
Added getIndexList method.
1 parent 38626f8 commit 9c0c037

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

src/gameobjects/GameObject.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,49 @@ var GameObject = new Class({
312312
return (GameObject.RENDER_MASK === this.renderFlags);
313313
},
314314

315+
/**
316+
* Returns an array containing the display list index of either this Game Object, or if it has one,
317+
* its parent Container. It then iterates up through all of the parent containers until it hits the
318+
* root of the display list (which is index 0 in the returned array).
319+
*
320+
* Used internally by the InputPlugin but also useful if you wish to find out the display depth of
321+
* this Game Object and all of its ancestors.
322+
*
323+
* @method Phaser.GameObjects.GameObject#getIndexList
324+
* @since 3.4.0
325+
*
326+
* @return {integer[]} An array of display list position indexes.
327+
*/
328+
getIndexList: function ()
329+
{
330+
var child = this;
331+
var parent = this.parentContainer;
332+
333+
var indexes = [];
334+
335+
while (parent)
336+
{
337+
// indexes.unshift([parent.getIndex(child), parent.name]);
338+
indexes.unshift(parent.getIndex(child));
339+
340+
child = parent;
341+
342+
if (!parent.parentContainer)
343+
{
344+
break;
345+
}
346+
else
347+
{
348+
parent = parent.parentContainer;
349+
}
350+
}
351+
352+
// indexes.unshift([this.scene.sys.displayList.getIndex(child), 'root']);
353+
indexes.unshift(this.scene.sys.displayList.getIndex(child));
354+
355+
return indexes;
356+
},
357+
315358
/**
316359
* Destroys this Game Object removing it from the Display List and Update List and
317360
* severing all ties to parent resources.

0 commit comments

Comments
 (0)