【问题标题】:MonoGame GraphicsDevice.DisplayMode not working [duplicate]MonoGame GraphicsDevice.DisplayMode 不工作 [重复]
【发布时间】:2015-01-15 22:39:26
【问题描述】:

我使用 MonoGame(3.2 版,撰写本文时的最后官方版本)创建了一个简单的测试应用,但我无法让应用全屏显示。

我在别处找到了这段代码:

protected override void Initialize()
{
    graphics.IsFullScreen = true;
    graphics.PreferredBackBufferWidth = GraphicsDevice.DisplayMode.Width;
    graphics.PreferredBackBufferHeight = GraphicsDevice.DisplayMode.Height;
    graphics.ApplyChanges();

    Window.IsBorderless = true;
    Window.Position = new Point(0, 0);

    base.Initialize();
}

但问题是GraphicsDevice.DisplayMode 总是返回800x600 的屏幕尺寸。此外,GraphicsAdapter.Adapters 集合仅包含一个适配器,具有一个支持的显示模式 (800x600)。

这可能是什么问题?我当前的分辨率是 1920x1080,如果我将两台显示器连接为扩展桌面(这是我通常的设置),我会得到相同的结果。

更新

最后我只是简单地添加了对System.Windows.Forms 的引用并使用了:

graphics.IsFullScreen = true;
graphics.PreferredBackBufferWidth = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;
graphics.PreferredBackBufferHeight = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;
graphics.ApplyChanges();

我仍然想知道为什么 MonoGame 没有正确检测到任何适配器/屏幕。

更新 2this answer 所述,该问题已在非官方版本中修复(在撰写本文时)。

【问题讨论】:

  • 尝试将该代码移动到 Game 构造函数的末尾
  • @Vlad:这行不通,因为 GraphicsDevice 在 ctor 内部为空(至少在 MonoGame 中,我认为这在 XNA 中的行为不同)。
  • 我刚刚在base.Initialize() 之后设置了graphics.IsFullScreen = truenothing else,它按预期工作。您正在使用 winforms 来解决这个问题,所以我猜您使用的是 Windows,而不是 Linux/Mac。你介意确认哪个版本吗?我去搭建一个虚拟机看看
  • @Joe:谢谢!是的,它是 Windows 8.1(64 位,如果重要的话)。嗯,现在我也发现了同样的问题here。我会检查一下,如果它有效,我会重复投票。
  • @Joe:好的,构建最新的开发分支解决了这个问题。 commit linked in the other answer 修复了 GraphicsAdapter 中的问题,投票以重复关闭。

标签: c# fullscreen monogame


【解决方案1】:

尝试将graphics 代码移动到base.Initialize 调用之后 - 这是因为系统尚未初始化,并且已初始化为一些默认设置。通常,我们希望能够在游戏过程中(即初始化之后)更改图形,以防用户更改游戏中的任何设置。

【讨论】:

  • 没有帮助。事实上,即使在 UpdateDraw 方法中,GraphicsDevice.DisplayMode 也是 800x600。它始终保持在 800x600,即使我将 graphics.PreferredBackBufferWidthHeight 硬编码为不同的分辨率。
猜你喜欢
  • 1970-01-01
  • 2017-07-25
  • 2015-04-21
  • 2017-12-12
  • 2012-11-15
  • 2018-03-29
  • 2015-01-20
  • 2014-09-14
  • 1970-01-01
相关资源
最近更新 更多