You are given a complex Scene2D
graph in libgdx
with several Group's
and Actor's
. You want the user to select some Actors
and draw those at the end so they appear focussed on top of any other Actors
.
I would like to iterate over the Stage
twice. The first time it draws the unselected Actors
, the second time it draws the selected actors
. I don't see any 'good' way to enforce this behaviour however.
I would prefer options that are clean. I would not like to copy an entire method implementation just for the sake of this small addition.
What doesn't work:
- the
Actor's
toFront
() method only works for it's siblings. - swapping places of
Actor's
in the Stage: this modifies the transformations theActors
have.
Scenario to think about: you have a Root
with a group gA and a group gB. Group
gA contains two images iA1 and iA2. Group
gB contains one image iB. Given that Group
gA is added first to the stage and that image iA1 overlaps with iB; now you want to select iA1 and make it appear over iB. I don't want to only call gA.toFront(); this would put the whole Group
gA to the front, which means also iA2 is put to the front. Putting iA2 in front has the undesired effect of hiding parts of images inside Group
gB
You can work around this by overriding
draw
on the parent:There are two solutions-
1 - Stop using [multiple] groups. Sucks but this may be the easier option. If you look at how rendering/drawing is done you start at the root Group for a Stage and get its children and render them. For each of those children, if they are a Group then render that Groups children. ZIndex is nothing more than the order of children within a group. If you look at the Actor's
setZIndex
you can see whytoFront
orsetZIndex
only affect siblings.2 - The only other option would be to change the drawing order of all the actors. You'd have to extend
Stage
and replace thedraw
method todraw
based on a different order of your choosing. You'd probably have to incorporate a lot of the functionality from theGroup.drawChildren
method.TLDR; The way things are implemented in LibGDX - a Group is a layer. If you don't want layers then either change what groups do or stop using groups.