Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (777)
Games in Android Showcase (231)
games submitted by our members
Games in WIP (856)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [LibGDX] Seperate scaling for UI and Game Screen  (Read 511 times)
0 Members and 1 Guest are viewing this topic.
Offline MossyForest

Senior Newbie


Exp: 1 year



« Posted 2018-04-12 08:58:36 »

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?
Offline LiquidNitrogen
« Reply #1 - Posted 2018-04-12 09:47:08 »

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.
Offline Springrbua
« Reply #2 - Posted 2018-04-12 09:56:36 »

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.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline MossyForest

Senior Newbie


Exp: 1 year



« Reply #3 - Posted 2018-04-12 11:31:11 »

Thank you!
It worked really well, and using two cam solved other problems I had as well!
Pages: [1]
  ignore  |  Print  
 
 

 
hadezbladez (276 views)
2018-11-16 13:46:03

hadezbladez (154 views)
2018-11-16 13:41:33

hadezbladez (287 views)
2018-11-16 13:35:35

hadezbladez (69 views)
2018-11-16 13:32:03

EgonOlsen (2124 views)
2018-06-10 19:43:48

EgonOlsen (2148 views)
2018-06-10 19:43:44

EgonOlsen (1361 views)
2018-06-10 19:43:20

DesertCoockie (1957 views)
2018-05-13 18:23:11

nelsongames (1598 views)
2018-04-24 18:15:36

nelsongames (2246 views)
2018-04-24 18:14:32
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!