SetResolution

Introduction

The SetResolution method sets the resolution (number of pixels wide and tall) of your game. This method can be called at any time after FlatRedBall is initialized.

Code Example

The following code resizes the screen to display a resolution of 320X240.

FlatRedBallServices.GraphicsOptions.SetResolution(320, 240);

Changing Resolutions

Resolutions can be changed by calling SetResolution multiple times. For example, the following code allows the user to press the 1 or 2 keys to change between two resolutions:

            if (InputManager.Keyboard.KeyPushed(Keys.D1))
            {
                FlatRedBallServices.GraphicsOptions.SetResolution(200, 200);
            }

            if (InputManager.Keyboard.KeyPushed(Keys.D2))
            {
                FlatRedBallServices.GraphicsOptions.SetResolution(500, 500);
            }

Camera behavior when calling SetResolution

By default if SetResolution is called, the Camera will adjust its DestinationRectangle according to the changed resolution. This automatic adjustment depends on the Camera's split screen viewport settings. For more information, see the SetSplitScreenViewport page.

Setting resolution to current resolution

One common piece of code that people use (incorrectly) to set the game resolution to the entire display's resolution is:

FlatRedBallServices.GraphicsOptions.SetResolution(GraphicsDevice.DisplayMode.Width,
    GraphicsDevice.DisplayMode.Height);

Last updated