Reputation: 53
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 :
This is what I'am trying and need to achieve:
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
Reputation: 1261
There are a few good options for using Viewports in LibGDX. The images are you very helpful to narrow down the options!
FitViewport - Maintains the aspect ratio and scales accordingly. Fills the rest of the screen with black bars.
ScreenViewport - Maintains aspect ratio but it does so by showing more or less of the game world according to the screen size / screen resolution.
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.
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.
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
Reputation: 20140
You're using FitViewport having -
Pros :
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
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