LibGDX ViewPorts and why you should love them

The LibGDX ViewPort is an extremely useful feature which I really really like. Basically it gives you a virtual screen with fixed width and height (800×600 for example). You tell the virtual screen to fit itself onto the real screen with different sets of rules. I tell my game Insane Tower Builders to stretch out onto the real screen.

The great thing with this is that you can design your UI on only one screen (the virtual one), and let LibGDX take care of fitting it onto all different sizes of mobile screens out there. Of course the end result might look a bit different on screens with different width / height ratios than the virtual one. If the virtual screen width / height ratio is chosen right, this should not be a big issue except for some edge cases.

Different virtual screens can be chosen depending on the real world screen size to mitigate edge case problems and give high resolution displays better graphics.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s