I am currently developing a game in C# and XNA, and I want it to look right at all resolutions. How would I get started with doing that?

  • \$\begingroup\$ You need to define what kind of game you're making, and what "look right" means specifically. \$\endgroup\$ – Andrew Russell Oct 12 '13 at 8:19
  • \$\begingroup\$ At the moment when I make the resolution bigger, everything in the game stays the same size and gets pushed to the top left hand corner of the screen. On the bottom right there is just the window colour I am drawing. I want it to scale to fill the window at all times. \$\endgroup\$ – user35753 Oct 12 '13 at 8:35
  • \$\begingroup\$ @Matthew: sounds like you need to scale the positions and sizes of your sprites according to the viewport size. \$\endgroup\$ – me-- Oct 12 '13 at 9:45
  • \$\begingroup\$ Thanks for the help. Could you please give me an example on how I would do that? \$\endgroup\$ – user35753 Oct 12 '13 at 9:54
  • \$\begingroup\$ I probably should have asked specifically - but you should say how you are drawing. I assume SpriteBatch? Can you please edit your question to include all this information - for anyone who comes along later? (And to avoid your question getting closed.) \$\endgroup\$ – Andrew Russell Oct 13 '13 at 1:27

First, you have to decide how are you going to actually do the scaling? Do you need to handle aspect ratio? (It sounds like you do.)

If you are using SpriteBatch, you can pass a scaling matrix to Begin. You can also set the Viewport to letterbox or pillarbox off the screen you don't want to render to. Here is an example:

int backbufferWidth = GraphicsDevice.PresentationParameters.BackBufferWidth;
int backbufferHeight = GraphicsDevice.PresentationParameters.BackBufferHeight;

Viewport originalViewport = GraphicsDevice.Viewport;
GraphicsDevice.Viewport = new Viewport((backbufferWidth - viewWidth)/2
        (backbufferHeight - viewHeight)/2, viewWidth, viewHeight);

Matrix scaleMatrix = Matrix.CreateScale(scale, scale, 1);
spriteBatch.Begin(0, null, null, null, null, null, scaleMatrix);

// ... draw your sprites ...


GraphicsDevice.Viewport = originalViewport;

Note that the above code is untested. Also, I've left the maths for figuring out scale and viewWidth and viewHeight as an exercise - it will depend on how you actually want the scaling to look.

(My answer on that question I linked might give you a starting point. Don't forget to use Math.Floor to set viewWidth/Height, so it doesn't round up and extend outside the backbuffer!)


You can create a menu with an option to change the resolution. Include all the standard resolutions. When the user clicks on that option, change the resolution via

graphics.PreferredBackBufferWidth = 1920; //Your width
graphics.PreferredBackBufferWidth = 1080; //Your height
graphics.ApplyChanges(); //When calling this from outside the constructor, apply all the changes.

And if you want to scale up everything, render it into a RenderTarget with fixed size and then render the RenderTarget to the screen (and scale it up).

  • \$\begingroup\$ It would be better to get the available resolutions dynamically from GraphicsAdapter.DefaultAdapter.SupportedDisplayModes, rather than making potentially invalid settings available. \$\endgroup\$ – Andrew Russell Oct 13 '13 at 1:25
  • \$\begingroup\$ I didn't know something like that existed. But I'd really appreciate if you changed my answer or created your own one. \$\endgroup\$ – jalgames Oct 13 '13 at 9:01