Ignas Ražanskas
Ignas Ražanskas

Reputation: 53

Viewport issue for multiple screens

I'm making a little game and now I encountered a problem with viewport the best viewport to use for me is the fitViewport but it makes sides empty on specific sizes due to screen ratio. This is what the "problem" is : enter image description here

This is what I'am trying and need to achieve: enter image description here

Maybe anyone have encountered this with your own game, or have any solution to it so I could achieve what I need,

thanks sincerely Ignas.

Wasnt using extend screen properly, the extend screen helped!

Upvotes: 1

Views: 314

Answers (3)

Micheal O'Dwyer
Micheal O'Dwyer

Reputation: 1261

There are a few good options for using Viewports in LibGDX. The images are you very helpful to narrow down the options!

  1. FitViewport - Maintains the aspect ratio and scales accordingly. Fills the rest of the screen with black bars.

  2. ScreenViewport - Maintains aspect ratio but it does so by showing more or less of the game world according to the screen size / screen resolution.

  3. ExtendViewport - Maintains the aspect ratio in one direction. The world is scaled in one direction and the shorter side is lengthened to fill the rest of the screen.

  4. FillViewport - Similar to the ExtendViewport. Scales the world up to the size of the viewport while maintaining the aspect ratio. Some of the world might be off the screen.

  5. StretchViewport - Stretches the world to take up the entire screen and doesn't maintain aspect ratio.

It seems that the best option is the ExtendViewport or FillViewport. I wouldn't recommend using the StretchViewport because of how it doesn't maintain any of the aspect ratio.

Depending on your game and what you want exactly you should achieve the results you want with either the ExtendViewport or FillViewport.

If you have any further questions feel free to leave a comment below!

Upvotes: 2

AAryan
AAryan

Reputation: 20140

You're using FitViewport having -

Pros :

  1. Virtual screen size
  2. Maintain aspect ratio

Cons :

Black bar may be appear on screen.


According to your pictorial representation, StretchViewport fit your requirement but in this viewport object become stretched and also aspect ratio not maintained.

I'll recommend you to use ExtendViewport because It keeps the world aspect ratio without black bars. Check this answer.

Upvotes: 4

Shox
Shox

Reputation: 84

There are 5 viewports available -

ExtendViewport FitViewport FillViewport StretchViewport ScreenViewport

Maybe what you are trying to achieve can be done by extend viewport.

Upvotes: 3

Related Questions