예제 #1
0
  @Override
  public Array<IGameObject> getRenderObjects() {
    renderObjects.clear();

    Array<IGameObject> objects = gameWorld.getObjects();
    for (int i = objects.size - 1; i >= 0; --i) {
      IGameObject obj = objects.get(i);

      // filter out objects that are not within the camera view
      final float left = obj.getX();
      final float bottom = obj.getY();
      final float right = left + obj.getWidth();
      final float top = bottom + obj.getHeight();

      if (camera.frustum.pointInFrustum(left, bottom, 0) // bottom left within view or
          || camera.frustum.pointInFrustum(right, bottom, 0) // or bottom right within view
          || camera.frustum.pointInFrustum(right, top, 0) // or top right within view
          || camera.frustum.pointInFrustum(left, top, 0) // or bottom left within view
      ) {
        renderObjects.add(obj);
      }
    }

    // sort objects by y-coordinate
    renderObjects.sort();

    return renderObjects;
  }
예제 #2
0
  @Override
  default int compareTo(IGameObject o) {
    // first sort by z
    int deltaZ = Integer.compare(getZ(), o.getZ());

    if (deltaZ == 0) {
      // if z is equal -> order by y
      return Float.compare(getY(), o.getY());
    }

    return deltaZ;
  }