Virtual game dimensions - how to implement?

I'm creating a fighting game in LibGDX with a static board, camera moves only right<>left.

There are 5 screen aspect ratios in Android and Apple so I have created 5 different background graphics:

• 2560x1440 16:9
• 2560x1920 4:3
• 2700x1800 3:2
• 3000x1800 5:3
• 3200x2800 8:5

Each background width is multiplied by 1.5, cause I need to zoom-out the game when players are too far away from each other, so for example 16:9 isn't 2560x1440 but 3840x1440. (I just realised that I should expand the height too LOL, gamedev is a fantastic place).

When I load the background I check the screen size and scale the background to fit.

The thing I need to implement is: Virtual Coordinates which are the same for each device.

Let's get the screen below:

I need to set virtual board dimensions to for example 2000x1000 units/meters whatever.

When the server sends a message: Spawn a bomb on (1000,1000), left device spawns it at x=512, right device at x=960 (both on the half).

I think working on pixels is a bad idea, cause I would need to calculate things with each move, jump etc.

If someone could help me, how should I achieve this, I would be grateful for pointing me a way.

Thanks!

• If you get width and height of specific device, you can divide it for example by 1000, and as a result you have a "point" which size is very similiar to others on other devices. – johnyX Jun 28 '16 at 17:59

Take a look at Viewports. Many of the Viewport subclasses take virtual height and width in their constructors. There are different flavors of viewport depending on how well you want Libgdx to keep to your desired aspect ratio.