I am trying to use Box2D Debug Renderer with my lyrics and LibGDX bodies. The problem I am facing is that Renderer draws the body of the box in the center of the screen, and then Sprite draws by default the default (0,0) in the lower left corner of the screen. When I move the Car Sprite, the movement of the Car and Debug Box makes them not overlapping.
I know that the problem is with the camera, because for several days I was messing around with different camera values. In some cases, they overlap, but then the Box2D Debug Body moves faster than the Car Sprite.
Several times, the Box2D is in the same position as the Sprite, but very small. I use 2 cameras. One of them is 720 x 480. The debugging camera is in meters, so its 24 x 16.
Here is some code where the problem might occur (I use Stages and Actors):
BattleScreen.java:
public void show() { battleStage = new Stage( 720, 480, false ); // The Box2D Debug Renderer will handle rendering all physics objects for debugging debugRenderer = new Box2DDebugRenderer( true, true, true, true ); debugCam = new OrthographicCamera( 24, 16 ); } public void render() { // Set the Camera matrices battleStage.getCamera().update(); // Update the Physics World, use 1/45 for something around 45 Frames/Second for mobile devices physicsWorld.step( 1/45.0f, 8, 3 ); // 1/45 for devices // Again update the Camera matrices and call the debug renderer //debugCam.update(); debugRenderer.render( physicsWorld, debugCam.combined ); // Update all Game Objects then Draw them battleStage.act(delta); battleStage.draw(); }
Car.java: (also actor)
public Car(Texture texture ) { super( "Car" ); mSprite = new Sprite( texture ); mSprite.setSize( 54, 105 ); mSprite.setOrigin( mSprite.getWidth()/2, mSprite.getHeight()/2);
And so that everything worsens. It really gets complicated when I try to get the main camera to follow the car.