Libgdx Android iOS : Best way for setting up the code to fit screensizes

Hi,

I was wondering what would be a good way for setting up you’re code in such a way that it looks good on different device sizes with different aspect ratio’s in particular so it fits tablets as well as smartphones.

I was reading this jgo article:
http://www.java-gaming.org/index.php?topic=25685.0

which mainly focusses on keeping the aspect ratio, but i was wondering if that is really the way to go.

Some questions that i was pondering on:

  1. if i choose to maintain aspect ration and center the game on my device I could get black bars (or i have to fill up the extra space with something). This is probably not what you want. I could maybe create textures/maps wider than the virtual width and height, but that doesnt always looks good (game dependant).

  2. If I DO decide to maintain aspect ration, I was wondering how to adjust my virutal on-screen controller. F.e. in my PacManbow game i created button on left & right side of the screen which are drawn relative to the screensize (and also the touchinput is read out that way). If for example I maintain aspect ratio and when centered the virtual origin (x=0,y=0) is drawn on screen at x=0,y=10 f.e. to keep aspect ratio I’ll get issues with my virtual controller. How to address this?

  3. What size do i create my images/textures? And if I create multiple version for different screensizes, how many of them do i create. I want my game to look good on 4,5" smartphones, but also on 10"+ tablets.

What you want is a Viewport https://github.com/libgdx/libgdx/wiki/Viewports. Have a look at the different types of viewports and decide which one suits your game.

Norakomi - Out of interest - how did you implement the AI of your packman game?

@NoFixedAbode: O my, lol, only seeing your reply now. :slight_smile:

I got the ideas for the AI of my Packman game (https://play.google.com/store/apps/details?id=mambow_jr.android) mostly from this video:

sQK7PmR8kpQ

And from the pacman dossiers which is an awesome resource for anything pacman related :
http://home.comcast.net/~jpittman2/pacman/pacmandossier.html#Chapter_4