package com.ychstudio.systems;

import com.artemis.Aspect;
import com.artemis.ComponentMapper;
import com.artemis.systems.IteratingSystem;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.ychstudio.components.Renderer;
import com.ychstudio.components.Transform;

public class RenderSystem extends IteratingSystem {

    private SpriteBatch batch;
    
    protected ComponentMapper<Transform> mTransform;
    protected ComponentMapper<Renderer> mRenderer;
    
    public RenderSystem(SpriteBatch batch) {
        super(Aspect.all(Transform.class, Renderer.class));
        
        this.batch = batch;
    }

    @Override
    protected void begin() {
        batch.begin();
    }
    
    @Override
    protected void end() {
        batch.end();
    }

    @Override
    protected void process(int i) {
        Transform transform = mTransform.get(i);
        Renderer renderer = mRenderer.get(i);
        
        renderer.setPosition(transform.posX, transform.posY);
        renderer.setRotation(transform.rotation);
        renderer.setScale(transform.sclX, transform.sclY);
        
        renderer.draw(batch);
    }
    
}

@@ -111,31 +111,108 @@
 mis.
-sys
+Entity;%0Aimport com.ar
 tem
+i
 s.
-IteratingSystem
+EntitySystem;%0Aimport com.artemis.utils.Bag;%0Aimport com.artemis.utils.Sort
 ;%0Aim
@@ -343,16 +343,45 @@
 ansform;
+%0Aimport java.util.Comparator;
 %0A%0Apublic
@@ -412,17 +412,14 @@
 nds 
-Iterating
+Entity
 Syst
@@ -436,16 +436,22 @@
 private 
+final 
 SpriteBa
@@ -866,38 +866,24 @@
 d();%0A    %7D%0A%0A
-    @Override%0A
     protecte
@@ -901,13 +901,16 @@
 ess(
-i
+E
 nt
- 
 i
+ty e
 ) %7B%0A
@@ -950,25 +950,25 @@
 ansform.get(
-i
+e
 );%0A        R
@@ -1000,17 +1000,17 @@
 rer.get(
-i
+e
 );%0A     
@@ -1224,20 +1224,560 @@
 atch);%0A    %7D
+%0A%0A    @Override%0A    protected void processSystem() %7B%0A        Bag%3CEntity%3E entities = getEntities();%0A        %0A        Sort sort = Sort.instance();%0A        sort.sort(entities, new Comparator%3CEntity%3E() %7B%0A            @Override%0A            public int compare(Entity o1, Entity o2) %7B%0A                Transform t1 = mTransform.get(o1);%0A                Transform t2 = mTransform.get(o2);%0A                return (int) -(t1.posY - t2.posY);%0A            %7D%0A        %7D);%0A        %0A        for (Entity e : entities) %7B%0A            process(e);%0A        %7D%0A    %7D
 %0A    %0A%7D%0A

Add sorting before rendering with RenderSystem