Skip to content

Commit

Permalink
Ignore not-displayable gameobjects
Browse files Browse the repository at this point in the history
  • Loading branch information
rexrainbow committed Dec 17, 2023
1 parent 75b6b1d commit 20dbfc9
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 17 deletions.
2 changes: 2 additions & 0 deletions examples/ui-sizer/bring-child-to-top.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ var CreateUI = function (scene, items) {
ui.bringChildToTop(items[i].item);
}

// ui.sendChildToBack(background)

return ui;
}

Expand Down
20 changes: 12 additions & 8 deletions plugins/gameobjects/container/containerlite/Depth.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import SortGameObjectsByDepth from '../../../utils/system/SortGameObjectsByDepth.js';
import FilterDisplayGameObjects from '../../../utils/system/FilterDisplayGameObjects.js';

export default {
setDepth(value, containerOnly) {
Expand Down Expand Up @@ -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) ||
Expand All @@ -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)) {
Expand Down
13 changes: 13 additions & 0 deletions plugins/utils/system/FilterDisplayGameObjects.js
Original file line number Diff line number Diff line change
@@ -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;
26 changes: 17 additions & 9 deletions plugins/utils/system/SortGameObjectsByDepth.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 20dbfc9

Please sign in to comment.