Example #1
0
  protected void renderParticles() {
    particleFrameBuffer.begin();
    batch.begin();

    Color initialColor = batch.getColor();

    Values<Entity> values = particleEntities.values();

    while (values.hasNext()) {
      Entity entity = values.next();
      ParticleComponent particle = entity.getComponent(ParticleComponent.class);
      ColorComponent color = entity.getComponent(ColorComponent.class);

      if (color != null) {
        batch.setColor(color.color);
      }

      particle.effect.draw(batch);

      batch.setColor(initialColor);
    }

    batch.end();
    particleFrameBuffer.end();

    batch.begin();
    batch.draw(particleRegion, 0.0f, 0.0f);
    batch.end();
  }
Example #2
0
  protected void renderWorldEntities() {

    Values<Entity> values = worldEntities.values();

    while (values.hasNext()) {
      Entity entity = values.next();

      TextureComponent texture = entity.getComponent(TextureComponent.class);
      TransformComponent transform = entity.getComponent(TransformComponent.class);

      if (isInFustrum(texture, transform)) {
        sortedEntities.add(entity);
      }
    }

    values = spineAnimatedEntities.values();

    while (values.hasNext()) {
      sortedEntities.add(values.next());
    }

    sortedEntities.sort(sorter);
    batch.setProjectionMatrix(camera.combined);

    for (Entity entity : sortedEntities) {
      if (entity.hasComponent(TextureComponent.class)) {
        TextureComponent texture = entity.getComponent(TextureComponent.class);
        TransformComponent transform = entity.getComponent(TransformComponent.class);

        float scale = transform.scale * Env.pixelsToMetres;
        float width = texture.region.getRegionWidth();
        float height = texture.region.getRegionHeight();
        float originX = width * 0.5f;
        float originY = height * 0.5f;

        batch.draw(
            texture.region,
            transform.position.x - originX,
            transform.position.y - originY,
            originX,
            originY,
            width,
            height,
            scale,
            scale,
            MathUtils.radiansToDegrees * transform.angle);
      } else {
        SpineComponent animation = entity.getComponent(SpineComponent.class);
        skeletonRenderer.draw(batch, animation.skeleton);
      }
    }

    sortedEntities.clear();
  }