The_Blog
The_Blog

Reputation: 155

LibGDX + Box2D | Camera too big

I use one camera at the moment to draw the Box2DDebugRenderer and one for drawing the map from the tmx. file. My problem is that, although the cameras have the SAME definition. The camera that is used for drawing the map is way too big on the screen.

SCREENSHOT Of the Problem:

enter image description here

Definition for box2dCam:

b2dCam = new OrthographicCamera();
b2dCam.setToOrtho(false, Game.getWidth() / PPM, Game.getHeight() / PPM);
b2dCam.update();

Definition for regular Camera:

cam = new OrthographicCamera();
cam.setToOrtho(false, Game.getWidth() / PPM, Game.getHeight() / PPM);
cam.update();

PPM (pixels per meter) is 32.

Code Game-class (regular camera is getting defined there!):

http://pastebin.com/FcCD5SLZ

Code for Play-GameState (box2dCam get's defined and also both cams get moved to player position):

http://pastebin.com/FcCD5SLZ

Anybody has any idea why that happens?

Upvotes: 2

Views: 575

Answers (1)

noone
noone

Reputation: 19776

Definition for box2dCam:

b2dCam = new OrthographicCamera();
b2dCam.setToOrtho(false, Game.getWidth() / PPM, Game.getHeight() / PPM);
b2dCam.update();

Definition for regular Camera:

cam = new OrthographicCamera();
cam.setToOrtho(false, Game.getWidth(), Game.getHeight()); // <--
cam.update();

That's how it should be. Don't divide the tiled map's camera's viewport by the PPM ratio, since here you want it to be 1 unit = 1 px.

Upvotes: 2

Related Questions