[libgdx] Orthographic camera and world units

I wrote a small game in libGDX without using the orthographic camera.

I made my own camera which didn’t actually handle transformations at all (each entity visually offsets by the camera position). I look back at this and I realize how stupid it was. So I began to read the wiki’s documentation on the orthographic camera. I have a question.

The wiki uses a method in Sprite called setSize. The example set the size to 100x100 world units for a 1024x1024 texture. If I had a world made of blocks, and each block, for example, would be 64x64 pixels, if I set the size of a block’s sprite to 1x1, then set my camera viewport size to be 30x30, would this still render 30x30 blocks or 30x30 pixels?

Thank you!

Well, essentially you are just rendering pixels, just scaled. You’re basically making your size = to 1 pixel.
I don’t really use gdx sprites though, so I may be wrong.

In case you aren’t sure how to scale the orthographic camera, you can do so when or after initializing it.
camera.setToOrtho(false, viewport_w, viewport_h); I’ve been using 15f and 9f for my games.

:slight_smile:

Thank you for clarifying a bit @syszee! I’ll probably use a separate camera for world rendering and a main one for everything else.

@chrislo27 I generally have a camera for world rendering, including players, enemies, items, etc - and a separate one for HUD related things. :slight_smile: