ObjectGroup rendering order

Hi! I’m coming back after integrating a significant subset of Tiled into my game engine, having myself a bit confused about the rendering order of objects within an ObjectGroup.

As far as I know, an ObjectGroup has a “draworder” property which is one of “topdown” (default) and “index” (which allows you to order overlapping objects with “Page up”/“Page down”). When rendering a Tiled map, I would like to provide a predictable behaviour and render the same thing as Tiled would. However, when having the default “topdown” set, if two objects have the same “y” coordinate, I can’t seem to figure out what is the criteria to break ties? Which one will be drawn first? The one with smaller “x”? If they have the same “x” and “y”, then what is the criteria? The one which was added first (with the smallest “id”)? Is the behaviour in this case undefined? (that would actually give my engine more flexibility in deciding how to render those objects, while still being compatible with Tiled).

After playing a while with Tiled, I still couldn’t figure out what is the criteria.

Thanks in advance!

Tiled uses the zValue property of QGraphicsItem to implement the rendering order. If two items have the same zValue, they are rendered in order of insertion.

So the behavior you should be seeing for “topdown” is that for objects with the same y coordinate, the last created object is always drawn last.

Got it! Thanks for the clarification.