# Publish android game only for 800 x 480 resolution in portrait mode

I have developed a game in libgdx. I worked for long and after finishing, I found that the game runs perfectly only on devices with resolution 800 × 480. I found this solution:

<compatible-screens>
<!-- all small size screens -->
<screen android:screenSize="small" android:screenDensity="ldpi" />
<screen android:screenSize="small" android:screenDensity="mdpi" />
<screen android:screenSize="small" android:screenDensity="hdpi" />
<screen android:screenSize="small" android:screenDensity="xhdpi" />
<!-- all normal size screens -->
<screen android:screenSize="normal" android:screenDensity="ldpi" />
<screen android:screenSize="normal" android:screenDensity="mdpi" />
<screen android:screenSize="normal" android:screenDensity="hdpi" />
<screen android:screenSize="normal" android:screenDensity="xhdpi" />
</compatible-screens>


But it allows various other resolutions too; Is there any way that I can publish my game only for 800 × 480 resolution?

• Why would you want to do that? If your game doesn't work properly with other resolutions, fix it. – aaaaaaaaaaaa Apr 13 '14 at 7:41
• Are you using libgdx cameras? If you would use those you could easily make it look nicely on any size screen. If you only target 800x480 resolution you are going to lose a lot of potential people to install your game – KodyVanRy Apr 15 '14 at 14:35

There are ways to restrict the screen types your app will be distributed to, as described here, but I don't think it gets as specific as you want, and I'm not sure why you would want to make it that specific. It would restrict your market to a very tiny subset of all Android users. You can put a warning in the description that it only works on certain screen resolutions, if you want, or you can change things to support a larger set of resolutions.

In the latter case, there are plenty of other questions and answers on this site addressing that issue. I recommend this answer in particular, to get you started.

I use a framework called MTX that works on top of LibGDX, so my answer may be different. I am not saying to redo your whole game in MTX, that would be silly. However the framework is open-source, so you can figure out how everything is done with a little bit of looking.

You mainly need to look at 2 main things:

• Resolution
• Aspect Ratio

You mentioned a target resolution of 800 x 480, therefore the aspect ratio is ~1.666667. I would set these in some global class made just for resolution:

TARGET_WIDTH = 800;
TARGET_HEIGHT = 480;
TARGET_ASPECT_RATIO = TARGET_WIDTH / TARGET_HEIGHT;


Now we need the current information:

CURRENT_ASPECT_RATIO = Gdx.graphics.getWidth() / Gdx.graphics.getHeight();


What we want to do here is to scale everything while maintaining the aspect ratio. So not every screen is going to be 5:3 specifically, but we can fit the game into 5:3 as best we can and simply constrain the gameplay elements within that area. Anything outside of that area can be background so as not to waste the space.

I am assuming that any device is forced into landscape mode.

WORLD_SCALE = 1;
WORLD_WIDTH = SCREEN_WIDTH;
WORLD_HEIGHT = SCREEN_HEIGHT;

if(CURRENT_ASPECT_RATIO < TARGET_ASPECT_RATIO)
{
//Filler is on top and bottom
WORLD_SCALE = Gdx.graphics.getWidth();
WORLD_HEIGHT = TARGET_HEIGHT * WORLD_SCALE;
}
else if(CURRENT_ASPECT_RATIO > TARGET_ASPECT_RATIO)
{
// Filler is on left and right
WORLD_SCALE = Gdx.graphics.getHeight() / TARGET_HEIGHT;
WORLD_WIDTH = TARGET_WIDTH * WORLD_SCALE;
}


What this does is finds out your working area. It will fit to whatever size screen, either by length or by height. By applying world scale, we also ensure that your objects scale up for larger screens as well.

For example, my phone has a screen that is 1920x1080. It has a higher aspect ratio than 800x540, and therefore we need to put some bars on the side. This would give me a WORLD_SCALE of 2, a WORLD_HEIGHT of 1080, and a WORLD_WIDTH of 1600, trimming 160 pixels off both sides.

Now it's too late at night for me to go into detail about how to use these values specifically, but it's pretty straightforward. You construct a Viewport object using the newfound values to size and center it. Ensure that your worldWidth and worldHeight for the viewport match your TARGET_WIDTH and TARGET_HEIGHT. Then you can construct your Stage using the new Viewport.

This stage should now be correctly fitted to maintain your desired aspect ratio, while scaling everything to fit the screen as much as possible without messing up the aspect ratio of your game.

• Actually I am using MTX too. It's fine for landscape mode... runs well on all devices. But if I am trying to create a portrait game.. MTX works too bad. Can you tell me on what should be target_width & target_height in AppSettings. – Vishal Kumar Apr 16 '14 at 17:56
• My games run in portrait mode and I have no issue. Make sure to set the proper target_width and target_height, and also make sure to change android:screenOrientation="landscape" to android:screenOrientation="portrait" in your AndroidManifest.xml. – user39686 Apr 16 '14 at 21:56
• Actually if you want to see an example of a Live Wallpaper that I published, here's the full source code and eclipse project. It uses LibGDX 0.9.9 and MTX 2.1, so if your project uses newer version I would suggest just copy-pasta anything you need. – user39686 Apr 16 '14 at 21:59