fix sorter so it works correctly even when the camera is reassigned
This commit is contained in:
parent
4dcc40e962
commit
2f0b02ad90
|
@ -1,7 +1,5 @@
|
||||||
package com.blarg.gdx.graphics;
|
package com.blarg.gdx.graphics;
|
||||||
|
|
||||||
import java.util.Comparator;
|
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.graphics.Camera;
|
import com.badlogic.gdx.graphics.Camera;
|
||||||
import com.badlogic.gdx.graphics.GL10;
|
import com.badlogic.gdx.graphics.GL10;
|
||||||
|
@ -14,6 +12,8 @@ import com.badlogic.gdx.utils.Disposable;
|
||||||
import com.badlogic.gdx.utils.ObjectMap;
|
import com.badlogic.gdx.utils.ObjectMap;
|
||||||
import com.badlogic.gdx.utils.Pool;
|
import com.badlogic.gdx.utils.Pool;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* <strong>Note:</strong><br />
|
* <strong>Note:</strong><br />
|
||||||
|
@ -91,14 +91,21 @@ public class AlphaTestCameraGroupStrategy implements GroupStrategy, Disposable {
|
||||||
private final Comparator<Decal> cameraSorter;
|
private final Comparator<Decal> cameraSorter;
|
||||||
|
|
||||||
public AlphaTestCameraGroupStrategy (final Camera camera) {
|
public AlphaTestCameraGroupStrategy (final Camera camera) {
|
||||||
this(camera, new Comparator<Decal>() {
|
if (!Gdx.graphics.isGL20Available())
|
||||||
|
throw new UnsupportedOperationException("AlphaTestCameraGroupStrategy requires shader support.");
|
||||||
|
|
||||||
|
this.camera = camera;
|
||||||
|
createDefaultShader();
|
||||||
|
|
||||||
|
final AlphaTestCameraGroupStrategy that = this;
|
||||||
|
this.cameraSorter = new Comparator<Decal>() {
|
||||||
@Override
|
@Override
|
||||||
public int compare (Decal o1, Decal o2) {
|
public int compare (Decal o1, Decal o2) {
|
||||||
float dist1 = camera.position.dst(o1.getPosition());
|
float dist1 = that.camera.position.dst(o1.getPosition());
|
||||||
float dist2 = camera.position.dst(o2.getPosition());
|
float dist2 = that.camera.position.dst(o2.getPosition());
|
||||||
return (int)Math.signum(dist2 - dist1);
|
return (int)Math.signum(dist2 - dist1);
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public AlphaTestCameraGroupStrategy (Camera camera, Comparator<Decal> sorter) {
|
public AlphaTestCameraGroupStrategy (Camera camera, Comparator<Decal> sorter) {
|
||||||
|
@ -108,7 +115,6 @@ public class AlphaTestCameraGroupStrategy implements GroupStrategy, Disposable {
|
||||||
this.camera = camera;
|
this.camera = camera;
|
||||||
this.cameraSorter = sorter;
|
this.cameraSorter = sorter;
|
||||||
createDefaultShader();
|
createDefaultShader();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCamera (Camera camera) {
|
public void setCamera (Camera camera) {
|
||||||
|
|
Loading…
Reference in a new issue