SHARE
TWEET

Untitled

a guest May 21st, 2019 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     public RenderingSystem(SpriteBatch batch) {
  2.         // gets all entities with a TransofmComponent and TextureComponent
  3.         super(Family.all(TransformComponent.class, TextureComponent.class).get(), new ZComparator());
  4.  
  5.         //creates out componentMappers
  6.         textureM = ComponentMapper.getFor(TextureComponent.class);
  7.         transformM = ComponentMapper.getFor(TransformComponent.class);
  8.  
  9.         // create the array for sorting entities
  10.         renderQueue = new Array<Entity>();
  11.      
  12.         this.batch = batch;  // set our batch to the one supplied in constructor
  13.  
  14.         // set up the camera to match our screen size
  15.         cam = new OrthographicCamera(FRUSTUM_WIDTH, FRUSTUM_HEIGHT);
  16.         cam.position.set(FRUSTUM_WIDTH / 2f, FRUSTUM_HEIGHT / 2f, 0);
  17.     }
  18.  
  19.     @Override
  20.     public void update(float deltaTime) {
  21.         super.update(deltaTime);
  22.  
  23.         // sort the renderQueue based on z index
  24.         renderQueue.sort(comparator);
  25.        
  26.         // update camera and sprite batch
  27.         cam.update();
  28.         batch.setProjectionMatrix(cam.combined);
  29.         batch.enableBlending();
  30.         batch.begin();
  31.  
  32.         // loop through each entity in our render queue
  33.         for (Entity entity : renderQueue) {
  34.             TextureComponent tex = textureM.get(entity);
  35.             TransformComponent t = transformM.get(entity);
  36.  
  37.             if (tex.region == null || t.isHidden) {
  38.                 continue;
  39.             }
  40.  
  41.  
  42.             float width = tex.region.getRegionWidth();
  43.             float height = tex.region.getRegionHeight();
  44.  
  45.             float originX = width/2f;
  46.             float originY = height/2f;
  47.  
  48.             batch.draw(tex.region,
  49.                     t.position.x - originX, t.position.y - originY,
  50.                     originX, originY,
  51.                     width, height,
  52.                     PixelsToMeters(t.scale.x), PixelsToMeters(t.scale.y),
  53.                     t.rotation);
  54.         }
  55.  
  56.         batch.end();
  57.         renderQueue.clear();
  58.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top