我已经研究了一段时间,无法理解。在某些Android设备上,当游戏启动时,我的游戏右侧会出现一个垂直的“死”空间,如果我将游戏发送到后台并重新激活,则会在右侧获得另一个。我在帖子中添加了两个GIFS来帮助说明这一点。
[当我检查GraphicsDevice.Viewport.X时,它不等于零,我可以将其设置为零,但是如果将游戏放到后台并将其放回原位,则X值会再次更改。我可以使用下面的代码对其进行更正,但是却在努力寻找应该放置它的位置,从而避免了每次更新都需要调用它。同样,视口的宽度会同时更改。
if (GraphicsDevice != null && (GraphicsDevice.Viewport.X != 0 ||
GraphicsDevice.Viewport.Width != GraphicsDevice.Adapter.CurrentDisplayMode.Width ||
GraphicsDevice.Viewport.Width != GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width))
{
Viewport view = GraphicsDevice.Viewport;
view.X = 0;
view.Width = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;
GraphicsDevice.Viewport = view;
}
我已将此代码放置在屏幕的Update()方法中,它已解决了该问题-但在每次更新中都调用它似乎过头了。我还尝试过在Activity和Game OnResume()和OnActivate()的覆盖中调用它,它会根据需要更改视口,但不保留并最终设置回导致“立即”变窄的值。
还值得注意的是,游戏正在全屏模式下运行。
非常感谢您提供的任何建议。
Game StartedGame resumed from background
注意:在视频中,我正在触摸移动蓝色标记。
为了完整起见,我将在此处找到我对问题的解决方案。在Monogame Community寻求帮助后,找到了解决方案。我从主Activity中的OnWindowFocusChanged()事件中调用了以下方法。
private void HideSystemUI()
{
// Apparently for Android OS Kitkat and higher, you can set a full screen mode. Why this isn't on by default, or some kind
// of simple switch, is beyond me.
// Got this from the following forum post: http://community.monogame.net/t/blocking-the-menu-bar-from-appearing/1021/2
if (Build.VERSION.SdkInt >= BuildVersionCodes.Kitkat)
{
View decorView = Window.DecorView;
var uiOptions = (int)decorView.SystemUiVisibility;
var newUiOptions = (int)uiOptions;
newUiOptions |= (int)SystemUiFlags.LowProfile;
newUiOptions |= (int)SystemUiFlags.Fullscreen;
newUiOptions |= (int)SystemUiFlags.HideNavigation;
newUiOptions |= (int)SystemUiFlags.ImmersiveSticky;
decorView.SystemUiVisibility = (StatusBarVisibility)newUiOptions;
this.Immersive = true;
}
}