There are two solutions -
1 - Stop using [multiple] groups. Sucks, but it could be easier. If you look at how the rendering / drawing is done, you start with the root group for the stage and get its children and render them. For each of these children, if they are a Group, then draw that Group of children. ZIndex is nothing more than the order of children in a group. If you look at the setZIndex Actor, you will see why toFront or setZIndex affects only siblings.
public void setZIndex (int index) { if (index < 0) throw new IllegalArgumentException("ZIndex cannot be < 0."); Group parent = this.parent; if (parent == null) return; Array<Actor> children = parent.getChildren(); if (children.size == 1) return; if (!children.removeValue(this, true)) return; if (index >= children.size) children.add(this); else children.insert(index, this); }
2 - The only other option is to change the drawing order of all participants. You need to extend the Stage and replace the draw method with draw based on a different order of your choice. You will probably have to include many functions from the Group.drawChildren method.
TL; DR; The way everything is implemented in LibGDX - a group is a layer. If you do not want layers, then either change which groups do or stop using groups.
Chase
source share