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
Actor
, by using toFront() or toBack() it changes the z-Index of thatActor
and sorts theActor
list.Actor
s with a high z Index will be drawn at last,Actor
s with a low z Index will be drawn at first, and so in the back. If you call actor.toFront() in theselect()
method or however you call it, thisActor
will be rendered the last. In thedeselect()
you can calltoBack()
. This works forGroup
to, asGroup
is anActor
subclass. It is not a 100% working thing but in this case this should be enough. – PowderyGroup
is also anActor
you can compare it the same. Just give theGroup
the right depth. In that case the siblings of the group should have the same depth. Else it wouldnt work since you cant let the group drawn at different times inside of the Stage. (just calls the.draw
from the Group) i Would recomend to add an insertionsort instead of the collection sort. it's much faster for a closely sorted list. (and your list wont change alot i think) – EmbolismActor
from the group, add it to theStage
, order theActor
s andGroup
s and draw them. As soon as you need theActor
back in theGroup
again, for some reason, remove it from theStage
and add it to theGroup
. It is pretty complicated, but should work. Otherwise, don't use Scene2D. I also like Scene2D but everything has a disadvantage to... – Powderystage.draw()
. For my approach: Ofc if you remove an acotr of a group you need to change his position depending on the position of the group. This would be really complex but should work. But in your case i would try to do this without scene2d... This kind of sorting just won't be easy to integrate to scene2d... – Powdery