Handle multiple resolutions

I googled this but couldn’t find the correct answer. Does anyone know how to handle this?


Sometimes it’s just a matter of knowing the right terms to search :smiley:


I’ve implemented this for my own game and it does the trick. Just make sure to give the scale matrix to whatever sprite batch you open.

If your game is 3D, the math is the same, but I’d imagine you’d have to implement this in your view matrix and maybe clip the view? I feel like there’s a way to do this but I’ve never played with it before.

1 Like

I wrote a blog post explaining how to support multiple resolution for phone & tablet, and also some cool letterboxing tricks instead of just plain black bars:

It uses all open source stuff and just a few lines of code to set up. Hope this helps, Cheers!

1 Like

Thanks for the reply. Link is not working.

It occurs to me that there’s no real reason I can’t just share my code with you. Here’s my implementation based on the article from David Amador above.

Here’s an example of how I create this object in my main Activity’s OnCreate method. Note that in this case, I’m creating a world that is 1280x720 pixels and that will scale to whatever the device’s display is set to.

Android.Graphics.Point displaySize = new Android.Graphics.Point();

IScreenManager screenManager = new ScreenManager();
screenManager.World = new Point(1280, 720);
screenManager.Screen = new Point(displaySize.X, displaySize.Y);
screenManager.IsFullScreen = true;

I then pass this to my game as a dependency, allowing it to call BeginDraw before it draws anything.

Anyway, good luck!

sorry bout that, fixed link :open_mouth:

Hi, I’m trying to use ResolutionBuddy. My background image size is 1440*960.
IResolution resolution = new ResolutionComponent(this, graphics, new Point(1280, 720), new Point(1024, 768), false, true);
what should be the (new Point(1280, 720), new Point(1024, 768)) values?

The first point passed in is the “virtual resolution” of your game… It sounds like your game is built around a resolution of 1440*96, so that is what you should pass in. I always just pass in the same values for both points. At that aspect ratio it should do pillarbox on phone (which are usually 16:9ish) and letterbox on tablet (3:4ish). Make sure you set the game up to only play in landscape mode on Android!!!
Let me know if that doesn’t work out. Cheers!

Not working,

Anyway, I defined preferred background width and height in the constructor and works fine in any device. But sprite sizes not correct.

graphics.IsFullScreen = true;
graphics.PreferredBackBufferWidth = 1440;
graphics.PreferredBackBufferHeight = 960;

spriteBatch.Draw(_background, new Rectangle(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight), Color.White);

Sorry it’s not working, what exactly is it doing? Could you post a screenshot?

Hi all, I found this one https://github.com/chengcong/ScalingClever
works fine in any device.