Skip to content

Instantly share code, notes, and snippets.

@Zolomon
Created April 29, 2016 08:10
Show Gist options
  • Select an option

  • Save Zolomon/8762fb045c34c082009a487ad98875b5 to your computer and use it in GitHub Desktop.

Select an option

Save Zolomon/8762fb045c34c082009a487ad98875b5 to your computer and use it in GitHub Desktop.
public class RenderingSystem extends SortedIteratingSystem {
private ComponentMapper<RenderableComponent> rm;
private ComponentMapper<PositionComponent> pm;
public RenderingSystem() {
super(Family.all(RenderableComponent.class, PositionComponent.class).get(), new ZComparator());
rm = ComponentMapper.getFor(RenderableComponent.class);
pm = ComponentMapper.getFor(PositionComponent.class);
}
protected void processEntity(Entity entity, float deltaTime) {
// Render the entity
}
private static class ZComparator implements Comparator<Entity> {
@Override
public int compare(Entity e1, Entity e2) {
return (int)Math.signum(pm.get(e1).z - pm.get(e2).z);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment