【发布时间】:2014-01-27 07:53:46
【问题描述】:
我使用 MonoGame 库编写了一个简单的游戏。据我所知,MonoGame(与 XNA 不同)不会自动支持更改手机的方向,因此有必要使用 RenderTarget2D 然后以正确的方向绘制它。为此,我需要检测手机的当前方向。
为了获得 OrientationChanged 事件,我必须允许 GamePage.xaml 使用不同的方向:
SupportedOrientations="PortraitOrLandscape" Orientation="Portrait"
问题在于,在这种情况下,我的 GamePage 开始自动更改方向,并且横向位置的精灵被水平拉伸。似乎在横向位置手机认为它沿水平方向的像素数与纵向方向相同(480 像素)。
此效果无需任何手动旋转即可发生。绘图代码为:
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 在横向模式下更改其坐标轴。
【问题讨论】: