0
\$\begingroup\$

I am playing around with LibGdx and its OrthographicCamera and notice something, what is really strange for me. I mean if you look into the code below you will see that I am initialising OrthographicCamer without passing arguments (viewportwidth, viewportHeight) and setting up them later, and this code is working properly, I mean it showing me what I have expected I mean smaller area of my map (which is later rendered) in render method.

And I try second way of initialising OrthographicCamera where I pass the same values to the constructor, but this give me nothing. I mean I do not see my map at all just color BLACK(which I pass as ScreenUtils.clear(color) argument) and I am trying to understand the different behaviour of this code which for me should have the same output.

I hope someone will be able to help me understand that, I looked into the LibGdx source code, but I am missing something cause I still not understand why this behaviour is different.

// this is working code
camera = new OrthographicCamera();
camera.setToOrtho(false); // this set Y axis pointing up
camera.viewportWidth = 60;
camera.viewportHeight = 30;

// this code below is not working as expected
camera = new OrthographicCamera(60, 30);
camera.setToOrtho(false); // this set Y axis pointing up
\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

It looks like you are not actually updating the camera in the first version. You are supposed to call camera.update() if you change those values.

Try commenting out these lines

//camera.viewportWidth = 60;
//camera.viewportHeight = 30;

Does it still "work"? I think your map rendering is relying on the default camera.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .