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?
closed as too broad by Andrew Russell, bummzack, Sean Middleditch, Trevor Powell, Seth Battin Oct 16 '13 at 4:54
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
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 ... spriteBatch.End(); GraphicsDevice.Viewport = originalViewport;
Note that the above code is untested. Also, I've left the maths for figuring out
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
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).