auto scaling in monogame for windows store games using xna and xaml
-
21-12-2019 - |
Domanda
Is there any best way to do auto scaling for windows store games developed in monogame,I am facing many problems ,Currently i am doing this. following is two lines of code which is useful for keeping my games windows to fixed scale.
graphics.PreferredBackBufferHeight = 768;
graphics.PreferredBackBufferWidth = 1024;
but this is solving my problem.
Soluzione
see bleow code for autoscaling for your store game two vars scalesx and scaley , divide the current deveice width and height by your required resolution i am taking 1024 and 768 because in pc's this smallest resolution those which will run windows 8 OS. when you pass x and y co-ordinates for rectangles and vectors multiply it scalex and scaley and the pos according to 1024*768 resolution
i have taken x of rect (int)(scalex*102) ------>by this, x of rect is at 102px but for autoscale multiply it by scalex.
` public static float scaley,scalex;
scalex = (float)graphics.GraphicsDevice.Viewport.Width / 1024;
scaley = (float)graphics.GraphicsDevice.Viewport.Height / 768;
jumposition = new Rectangle((int)(scalex*102),(int)(scaley*320),(int)(scalex*250),(int)(scaley* 250));`