Skip to content

Instantly share code, notes, and snippets.

@doorbash
Last active August 31, 2019 16:47
Show Gist options
  • Select an option

  • Save doorbash/3e18365010551cc7cb80601738b57e87 to your computer and use it in GitHub Desktop.

Select an option

Save doorbash/3e18365010551cc7cb80601738b57e87 to your computer and use it in GitHub Desktop.
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Matrix4;
import java.lang.reflect.Field;
/**
* Created by Milad Doorbash on 8/31/2019.
*/
public class DebugSpriteBatch extends SpriteBatch {
@Override
protected void switchTexture(Texture texture) {
// int x = 1/0;
try {
Field lastTextureField = getClass().getSuperclass().getDeclaredField("lastTexture");
lastTextureField.setAccessible(true);
Texture lastTexture = (Texture) lastTextureField.get(this);
if (lastTexture != null) {
System.out.println("****** switching from " + lastTexture + " to " + texture);
}
} catch (Exception e) {
e.printStackTrace();
}
super.switchTexture(texture);
}
@Override
public void setProjectionMatrix(Matrix4 projection) {
System.out.println("setProjectionMatrix()");
super.setProjectionMatrix(projection);
}
@Override
public void flush() {
try {
Field idxField = getClass().getSuperclass().getDeclaredField("idx");
idxField.setAccessible(true);
if (((int) idxField.get(this)) > 0) {
System.out.println(">>>>>>>>>>>>> FLUSH >>>>>> renderCalls = " + (renderCalls + 1));
}
} catch (Exception e) {
e.printStackTrace();
}
super.flush();
}
@Override
public void end() {
System.out.println("************* END ******************");
super.end();
}
@Override
public void begin() {
System.out.println("************* BEGIN ******************");
super.begin();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment