[LibGDX] Seperate scaling for UI and Game Screen

Currently I’m using OrthographicCamera and PolygonSpriteBatch for displaying my game.
I need to implement Zoom In and Zoom Out for my game, so I used OrthographicCamera’s zoom variable.
Scaling itself works well, but it also scales UI which needs to be fixed size regardless of zoomed in or out.

I heard using multiple batch is not recommended, so what is the best way to separate scaling of UI and Game Screen?

Its a good idea to use 2 separate cameras for the game screen and the UI, then they can behave differently. Using multiple batches would provide no advantage.

You don’t need different batches, but different cameras and viewports.
Then you have to set the projection matrix of your batch to the one of your game-camera and render your game.
After that, you need to set the projection matrix of the batch to the one of your UI and render the UI.

This has multiple advantages:

  • The game cam can move around, while the UI stays at the same place.
  • The two cameras can have an independent scale and viewport. For example, your game might be 20 Units (meters?) heigh, while your UI uses a pixel-perfect size.
  • You use the same batch and save resources. Also you don’t have to take care of ending and begining the batches all the time.

Thank you!
It worked really well, and using two cam solved other problems I had as well!