Search code examples
javalibgdxorthographic

sizing images with OrthographicCamera


I am new to libgdx and this question might be obvious since they skip it in every tutorial.

But say I set a camera up like this:

cam = new OrthographicCamera(100, 100);

This means I will now be working with my own units instead of pixels. So how do I know what size to make an image? Say for example I want an image to fill the width of the camera and half of the height. How would I do this? Do I make the image 100x50px? that makes no sense to me.


Solution

  • You say you are working with your own units when you define your camera, yet you are still thinking with pixels when you ask whether you should make your image 100x50px.

    Since you are working with your own units, I would assume that they are not completely detached from original pixel units, meaning that everything should now be measured by your units including the size of the images.

    If you can calculate what 1 unit of your represents pixel-wise, you can then determine the scale to which you can scale all of your images.

    Then you can say that your image should be 100x50units in size, you don't need to make the image to fit this condition, you just need to adjust its scale so that it corresponds with your defined unit measurement.

    If you are using SpriteBatch to draw your images, you might find that a couple of the defined draw overloads documented in the API can be given scale for both X and Y and could prove to be useful in this scenario.