Porting from WP7 to WP8 and Android (Monogame) - Screen Scaling

I have ported a game across from WP7 to 8 and noticed the game didn’t auto scale so the game was just over a quarter of the screen. which lead me to the following code to auto scale the screen

    int? scaleFactor = null;
var content =  new System.Windows.Interop.Content();

content = App.Current.Host.Content;

var scaleFactorProperty = content.GetType().GetProperty("ScaleFactor");

if (scaleFactorProperty != null)
    scaleFactor = scaleFactorProperty.GetValue(content, null) as int?;

if (scaleFactor == null)
    scaleFactor = 100;

double scale = ((double)scaleFactor) / 100.0;

if (scaleFactor == 150)
{
    MainPage.Instance.xnaSurface.Margin = new System.Windows.Thickness(10 / scale, 0, 0, 0);
}

ScaleTransform scaleTransform = new ScaleTransform();
scaleTransform.ScaleX = scaleTransform.ScaleY = scale;
MainPage.Instance.xnaSurface.RenderTransform = scaleTransform;

now I am trying to get it to run on android and I cant find a solution that scales the screen (maybe I am not looking in the right places) Could anyone point me in the right direction or give me some pointers on how I could do this? Thank you in advance :slight_smile:

Here is an image of how it looks on an android device Click here

You have to scale it manually when you draw.

To expand on this, there’s no magic way to just scale everything up the way you are doing on WP (that I’m aware of anyway), you need to do it for each individual sprite when you draw them.

You will need to calculate the ratio of scaling required on both the width and height, ie.

Width ratio = Actual device width / Device width your graphics were created for.
Height ratio = Actual device height / Device height your graphics were created for.

You can get the actual device dimensions from GraphicsDeviceManager.PreferredBackBufferWidth and PreferredBackBufferHeight.

You will then need to pass these values as a Vector2 to the SpriteBatch.Draw method with the scale parameter:

http://msdn.microsoft.com/en-us/library/ff433989.aspx

There are other things that need to be thought about (positioning and aspect ratio) but this should be a good starting point in getting your game to scale to the full screen.

Hope this helps,
Ronny.