I'm having trouble sorting Actors in a LibGdx Stage object. When the Stage gets rendered the images are rendered in the order they are added. Stage uses an Array to hold the Actors. I've tried setting the ZIndex of each Actor, but it still didn't sort. Then I tried creating a comparator object like this:
public class ActorComparator implements Comparator < Actor > {
@Override
public int compare(Actor arg0, Actor arg1) {
if (arg0.getZIndex() < arg1.getZIndex()) {
return -1;
} else if (arg0.getZIndex() == arg1.getZIndex()) {
return 0;
} else {
return 1;
}
}
}
and then when I want to do the actual comparison I did:
Collections.sort(Stage.getActors(), new ActorComparator());
It gives me the following error and won't compile:
The method sort(List<T>, Comparator<? super T>) in the type Collections
is not applicable for the arguments (Array<Actor>, ActorComparator)
I have no clue what I'm doing wrong. Can someone explain this to me?