I am writing a simple game using the MonoGame library. As far as I know, MonoGame (unlike XNA) does not support automatically changing the orientation of the phone, and you need to use RenderTarget2D, and then draw it with the correct orientation. To do this, I need to determine the current orientation of the phone.
To get the OrientationChanged event, I have to allow GamePage.xaml to use different orientations:
SupportedOrientations="PortraitOrLandscape" Orientation="Portrait"
The problem is that in this case my GamePage automatically changes orientation and in the landscape arrangement the sprites are stretched horizontally. It seems that in the landscape position the phone believes that it has the same number of horizontal pixels as in portrait orientation (480 pixels).


. :
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
spriteBatch.Draw(t, Vector2.Zero, null, Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 1);
spriteBatch.End();
base.Draw(gameTime);
}
- GamePage.xaml:
SupportedOrientations="Portrait" Orientation="Portrait"
OrientationChanged (GamePage.OrientationChanged Game.Window.OrientationChanged). Game,
graphics.SupportedOrientations = DisplayOrientation.Portrait |
DisplayOrientation.PortraitDown |
DisplayOrientation.LandscapeLeft |
DisplayOrientation.LandscapeRight;
graphics.ApplyChanges();
this.Window.OrientationChanged += OrientationChanged;
, , OrientationChanged GamePage .