Controlling z between collection proxies (SOLVED)

I have a general settings dialog in a collection proxy. It can be loaded from different screens around the game. In some of the screens it ends up behind other gui-elements (from other collections). How do I control the order of dynamically loaded collections?

1 Like

You can’t separate collection content like that. Everything is drawn according to their Z, sorted globally in each respective draw-pass (by render predicate).

In the screen where the settings screen ends up behind some other elements, all the gui elements has a z-position of 0. All the elements in the settings gui has a z-position of 1. That tells me the sorting can’t be global? They both have the standard gui-material so they share render predicate as well.

Oh, sorry you’re talking about GUI nodes. They are not sorted on Z, no. Not sure how they are sorted. Let me come back to you on this one…

1 Like

Now I found it. :smile: It’s not tied to collection proxies at all, but you can control the render order of GUI scenes with the function gui.set_render_order() http://doc.defold.com/ref/gui#gui.set_render_order

4 Likes

1 year old necropost incomming!
I haven’t been able to find any info on how to set the order/sorting of individual nodes. I have a data-driven gui that is procedurally generated, so all the gui templates (nodes I use gui.clone_tree() on) reside inside the same gui scene. The logical thing here is that the sorting would be based off the node’s position along z but that doesn’t work atm - in fact the position-z value has no effect what so ever on the ordering.

I know that the location of a node inside the hierachy under Nodes/ determine this somewhat, but afaik you cannot change this with code nor can you “place” a cloned node tree where you want it. Is this a bug, an intentional design or am I doing things wrong?

It is correct that z-value is completely ignored in gui scenes. This is well documented and unlikely to ever change. You control the draw order through parent-child hierarchies and/or gui layers.

gui.set_parent() will allow you to move nodes within the node hierarchy. gui.set_layer() will change layer on a node.

There’s http://www.defold.com/ref/gui/#gui.move_above and http://www.defold.com/ref/gui/#gui.move_below

1 Like

I was adviced to use gui.move_above() and gui.move_below() for setting the node order.

So in my update function, I loop through the nodes that needs to be sorted.
Then, for each item in the loop I loop through the nodes one more time (so every node gets compared to every other node) and perform a simple if
gui.get_position(item.gui_node_root).z > gui.get_position(item2.gui_node_root).z then

Then I just use the functions mentioned at the top of this post.

EDIT: The problem that arises from this though (not being able to sort via position.z) is that you need to add in a sorting algorithm there. And it gets confusing as there is no function for doing swapping between two nodes (you can only place one node above another - which is troublematic if there are additional nodes in between these… nodes that might have been processed already). In short: I’m still stuck.

2 Likes