Added getIndexList method.

This commit is contained in:
Richard Davey 2018-04-12 02:11:17 +01:00
parent 38626f8556
commit 9c0c037d79

View file

@ -312,6 +312,49 @@ var GameObject = new Class({
return (GameObject.RENDER_MASK === this.renderFlags); return (GameObject.RENDER_MASK === this.renderFlags);
}, },
/**
* Returns an array containing the display list index of either this Game Object, or if it has one,
* its parent Container. It then iterates up through all of the parent containers until it hits the
* root of the display list (which is index 0 in the returned array).
*
* Used internally by the InputPlugin but also useful if you wish to find out the display depth of
* this Game Object and all of its ancestors.
*
* @method Phaser.GameObjects.GameObject#getIndexList
* @since 3.4.0
*
* @return {integer[]} An array of display list position indexes.
*/
getIndexList: function ()
{
var child = this;
var parent = this.parentContainer;
var indexes = [];
while (parent)
{
// indexes.unshift([parent.getIndex(child), parent.name]);
indexes.unshift(parent.getIndex(child));
child = parent;
if (!parent.parentContainer)
{
break;
}
else
{
parent = parent.parentContainer;
}
}
// indexes.unshift([this.scene.sys.displayList.getIndex(child), 'root']);
indexes.unshift(this.scene.sys.displayList.getIndex(child));
return indexes;
},
/** /**
* Destroys this Game Object removing it from the Display List and Update List and * Destroys this Game Object removing it from the Display List and Update List and
* severing all ties to parent resources. * severing all ties to parent resources.