1
\$\begingroup\$

I have a rendering system that extends SortedIteratingSystem and created a comparator to sort the sprite draw order. But the problem is when I update the z index, it takes some time before it changes the order.

public class RenderingSystem extends SortedIteratingSystem {

    public RenderingSystem() {
        super(Family.all(...components).get(), new ZComparator());
    }

    private static class ZComparator implements Comparator<Entity> {
        @Override
        public int compare(Entity e1, Entity e2) {
            return (int)Math.signum(Mappers.index.get(e1).z - Mappers.index.get(e2).z);
        }
    }

}

IndexComponent implements Component {
    public int z = 0;
}
\$\endgroup\$
6
  • \$\begingroup\$ Are you saying "it takes a second" as in a literal second or are you saying "it takes a second" as in it takes some time? \$\endgroup\$
    – Charanor
    Jul 25, 2016 at 18:41
  • \$\begingroup\$ ya my mistake, it take some time \$\endgroup\$
    – ronscript
    Jul 25, 2016 at 18:42
  • \$\begingroup\$ Well then the easiest explanation would probably be that you have so many entities that it simply takes some time to sort the entities again. Could you try to decrease the amount of entities (like half the amount) and see if this speeds up the sorting? \$\endgroup\$
    – Charanor
    Jul 25, 2016 at 18:48
  • \$\begingroup\$ sure let me test it \$\endgroup\$
    – ronscript
    Jul 25, 2016 at 19:02
  • 1
    \$\begingroup\$ This is a complete shot out of the blue, but perhaps this is somehow linked to this question? \$\endgroup\$
    – Charanor
    Jul 25, 2016 at 19:30

0

You must log in to answer this question.

Browse other questions tagged .