How to support multiple Aspect Ratio?

Anything libgdx related goes here!

How to support multiple Aspect Ratio?

Postby DiegoMaxwell » Wed Jan 15, 2020 9:34 am

What I usually do is create two constants WIDTH and HEIGHT let say 1280x720, this is a 16:9 aspect ratio and then I just do camera.setToOrtho(false, Constant.WIDTH, Constant.HEIGHT). So my assets is created based on that aspect ratio. But today mobile devices have 19:9 aspect ratio, how can I support wider aspect ratio but the assets will look the same as 16:9 but the user will see more of the world?the game looks the same as when its run on older phones 16:9 but on 19:9 you see more of the world. And also do I have to create multiple assets for multiple resolution?whatsapp web 192.168.0.1 routerlogin
Last edited by DiegoMaxwell on Sat Jan 18, 2020 8:08 am, edited 1 time in total.
DiegoMaxwell
 
Posts: 1
Joined: Wed Jan 15, 2020 9:30 am

Re: How to support multiple Aspect Ratio?

Postby shatterblast » Wed Jan 15, 2020 1:39 pm

I suggest that you look into either ScalingViewport or ExtendViewport. With ExtendViewport, you will need to add an OrthographicCamera yourself and use...
Code: Select all
yourCamera.setToOrtho( false,
                yourExtendViewport.getWorldWidth(),
                yourExtendViewport.getWorldHeight() );

You only need to set it once as you configure your stuff as normal. Everything else works as it should in that respect. The reason involves if you frequently switch between Viewport types or even at all, which ExtendViewport I know does not like.

After that, you only adjust the width and height values of your ExtendViewport object to make things easier if you go that path.

ScalingViewport just makes it easier to adjust ratios. It helps for zooming effects.

1) https://github.com/libgdx/libgdx/wiki/V ... ngviewport
shatterblast
 
Posts: 653
Joined: Sun Jul 06, 2014 1:14 pm


Return to Libgdx

Who is online

Users browsing this forum: No registered users and 1 guest

cron