diff --git a/examples/ui-sizer/bring-child-to-top.js b/examples/ui-sizer/bring-child-to-top.js index 87afb78cda..f5874f08b8 100644 --- a/examples/ui-sizer/bring-child-to-top.js +++ b/examples/ui-sizer/bring-child-to-top.js @@ -58,6 +58,8 @@ var CreateUI = function (scene, items) { ui.bringChildToTop(items[i].item); } + // ui.sendChildToBack(background) + return ui; } diff --git a/plugins/gameobjects/container/containerlite/Depth.js b/plugins/gameobjects/container/containerlite/Depth.js index 24ff11642e..793758c8d8 100644 --- a/plugins/gameobjects/container/containerlite/Depth.js +++ b/plugins/gameobjects/container/containerlite/Depth.js @@ -1,4 +1,5 @@ import SortGameObjectsByDepth from '../../../utils/system/SortGameObjectsByDepth.js'; +import FilterDisplayGameObjects from '../../../utils/system/FilterDisplayGameObjects.js'; export default { setDepth(value, containerOnly) { @@ -86,15 +87,17 @@ export default { var gameObjects; if (child.isRexContainerLite) { gameObjects = child.getAllChildren([child]); - SortGameObjectsByDepth(gameObjects, false); + gameObjects = FilterDisplayGameObjects(gameObjects); + gameObjects = SortGameObjectsByDepth(gameObjects, false); } else { gameObjects = [child]; } var children = this.getAllChildren([this]); - SortGameObjectsByDepth(children, true); + children = FilterDisplayGameObjects(children); + children = SortGameObjectsByDepth(children, false); + var topChild = children[children.length - 1]; - var topChild = children[0]; for (var i = 0, cnt = gameObjects.length; i < cnt; i++) { var gameObject = gameObjects[i]; if ((topChild === gameObject) || @@ -112,17 +115,18 @@ export default { var gameObjects; if (child.isRexContainerLite) { gameObjects = child.getAllChildren([child]); - SortGameObjectsByDepth(gameObjects, false); + gameObjects = FilterDisplayGameObjects(gameObjects); + gameObjects = SortGameObjectsByDepth(gameObjects, false); } else { gameObjects = [child]; } var children = this.getAllChildren([this]); - SortGameObjectsByDepth(children, false); - - + children = FilterDisplayGameObjects(children); + children = SortGameObjectsByDepth(children, false); var bottomChild = children[0]; - for (var i = 0, cnt = gameObjects.length; i < cnt; i++) { + + for (var i = gameObjects.length - 1; i >= 0; i--) { var gameObject = gameObjects[i]; if ((bottomChild === gameObject) || (bottomChild.displayList !== gameObject.displayList)) { diff --git a/plugins/utils/system/FilterDisplayGameObjects.js b/plugins/utils/system/FilterDisplayGameObjects.js new file mode 100644 index 0000000000..71318a6df3 --- /dev/null +++ b/plugins/utils/system/FilterDisplayGameObjects.js @@ -0,0 +1,13 @@ +var FilterDisplayGameObjects = function (gameObjects) { + return gameObjects.filter(function (gameObject) { + if (gameObject.displayList) { + // Inside a scene or a layer + return true; + } else if (gameObject.parentContainer) { + // Inside a container + return true; + } + }) +} + +export default FilterDisplayGameObjects; \ No newline at end of file diff --git a/plugins/utils/system/SortGameObjectsByDepth.js b/plugins/utils/system/SortGameObjectsByDepth.js index da33be061b..63e3551882 100644 --- a/plugins/utils/system/SortGameObjectsByDepth.js +++ b/plugins/utils/system/SortGameObjectsByDepth.js @@ -8,16 +8,24 @@ var SortGameObjectsByDepth = function (gameObjects, descending) { } var itemList; - var gameObject = gameObjects[0]; - if (gameObject.displayList) { - // Inside a scene or a layer - itemList = gameObject.displayList; // displayList - } else if (gameObject.parentContainer) { - // Inside a container - itemList = gameObject.parentContainer.list; // array - } else { + for (var i = 0, cnt = gameObjects.length; i < cnt; i++) { + var gameObject = gameObjects[i]; + if (gameObject.displayList) { + // Inside a scene or a layer + itemList = gameObject.displayList; // displayList + } else if (gameObject.parentContainer) { + // Inside a container + itemList = gameObject.parentContainer.list; // array + } + + if (itemList) { + break; + } + } + + if (!itemList) { itemList = gameObject.scene.sys.displayList; // displayList - // ?? + // ?? } if (itemList.depthSort) {