Hi!
I’m trying to make my camera not leave the map’s borders but it is not working and I don’t know why.
This is just a quick test to show you the code and the problem.
if(p1.getRealPosition().x - (Gdx.graphics.getWidth() * ZOOM / 2) <= 0){
cam.position.x = cam.viewportWidth * cam.zoom / 2;
cam.position.y = p1.getRealPosition().y;
}
else{
cam.position.set(p1.getRealPosition(), 0);
}
if(p1.getB2DPosition().x - (Gdx.graphics.getWidth() * ZOOM / 2 / PPM) <= 0){
b2dCam.position.x = Gdx.graphics.getWidth() * ZOOM / 2 / PPM;
b2dCam.position.y = p1.getB2DPosition().y;
}
else{
b2dCam.position.set(p1.getB2DPosition(), 0);
}
I’m using “cam” for most drawing nad “b2dCam” is only used for Box2D debug render. The wierd thing is that this code works perfectly with the b2dCam but it doesn’t with the normal cam.
Here is how it looks (and should look) with box2d
Here is the same picture same position with the normal camera. As you can see its off by far, it doesnt even show the player.
Could anyone please help me explain what causes this behaviour?