# How can I support different resolutions with Monogame? [duplicate]

I want to support the following 4 resolutions in my Windows Phone 8 game: 480 × 800, 768 × 1280, 720 × 1280, 1080 x 1920. How can I do that with Monogame? If I draw a sprite with Monogame, the sprite is not drawn on the right place in every resolution. For example, with a resolution of 768 × 1280, the sprite is drawn in the center of the screen, but if I use another resolution, the sprite is no more drawn in the center of the screen.

What should I do so that the sprite is in every resolution on the same place?

## marked as duplicate by Josh♦Jan 31 '14 at 22:03

You must resize all your image, and use some maths for positions.

I don't know XNA, but I will give you a code that you will adapt with this lib.

Images

1. You will do everything based on 1 screen resolution, and scale your images, relative to this.

float Reference_Screen_X = 1280;
float Reference_Screen_Y = 720;


2. You will get your current screen resolution

float Screen_X = GetScreenWidth(); //your function to get the screen width
float Screen_Y = GetScreenHeight();


3. You will resize all your image this way

float size_x = image.getwidth() * ( Screen_X / Reference_Screen_X );
float size_y = image.getheight() * ( Screen_Y / Reference_Screen_Y );
image.setSize(size_x, size_y);


OR with scale methods

float scale_x = 1 * ( Screen_X / Reference_Screen_X );
float scale_y = 1 * ( Screen_Y / Reference_Screen_Y );
image.setScale(scale, scale);


Positions

4. You have to keep in mind that every value you will set, will be in a Reference_Screen coordinate.

For exemple if you want go to the middle of the screen :

image.x = 640 * ( Screen_X / Reference_Screen_X );


Shortcuts

You should use global variables like :

  float refToScreen_x = ( Screen_X / Reference_Screen_X );
float refToScreen_y = ( Screen_Y / Reference_Screen_Y );


Then you just multiply them to the number you want :

 x = 500 * refToScreen_x;