Search code examples
libgdx

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!


Solution

  • 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.