I have a problem where the bodies in my debug draw does not draw correctly, take a look:
As you can see, there is some space between the dynamic body and the ground. I have checked the contact listeners and they are indeed colliding, but with a space inbetween. The contact point is not drawn either, which gives the hint of some drawing error (?).
My PPM = 100. If I set it to 1, the problem disappears (dafuq), but that's not really feasable to have a 1 pixel/meter ratio. I have tried to play around with the cameras but without result. Here is a simplified snippet from my screen:
public class GameScreen implements Screen {
private OrthographicCamera cam;
private OrthographicCamera b2dcam;
private World world;
private Box2DDebugRenderer b2dr;
private static final float PPM = 100;
private static final int V_WIDTH = 160;
private static final int V_HEIGHT = 90;
public GameScreen() {
cam = new OrthographicCamera();
b2dcam = new OrthographicCamera();
b2dr = new Box2DDebugRenderer();
world = new World(new Vector2(0, -9.82f), true);
/* ... create bodies etc ... */
}
public void render(float delta) {
/* I actually use more complex fixed timestep - just simplified here */
world.step(1/60f, 6, 2);
// Render
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
// Align the b2dr renderer to the camera
b2dr.render(world, cam.combined.cpy().scale(PPM, PPM, 1));
}
public void resize(int width, int height) {
float aspectRatio = (float) width / (float) height;
float aspectRatio2 = (float)height / (float)width;
// This is to maintain the same aspect ratio, using virtual screen-size
if(aspectRatio >= (float) V_WIDTH / (float) V_HEIGHT){
cam.setToOrtho(false, V_HEIGHT * aspectRatio, V_HEIGHT);
} else {
cam.setToOrtho(false, V_WIDTH, V_WIDTH * aspectRatio2);
}
cam.update();
}
}