2

我正在编写一个使用 MonoGame 3.01 和 SwapChainBackgroundPanel 与 XAML 集成的 Windows 8 游戏。我的资产针对 16:9 纵横比进行了优化,但由于 Win8 设备分辨率的变化,我也需要支持 4:3。

目前我面临以下问题:

  1. 将游戏拖到第二台显示器不会调整屏幕大小

        _graphics.PreferredBackBufferWidth = (int)width;
        _graphics.PreferredBackBufferHeight = (int)height;
        _graphics.ApplyChanges();
    

在 SwapChainBackgroundPanel (GamePage) 我对大小变化做出反应

    void GamePage_SizeChanged(object sender, SizeChangedEventArgs e)
    {
        Game.SetBackBuffer(e.NewSize.Width, e.NewSize.Height);
    }

但是什么也没发生,似乎只应用了初始(在游戏初始化之后)后台缓冲区更改。

  1. 有没有办法保持纵横比而不是拉伸填充,例如。通过信箱?

在 Windows 8(包括快照视图)上支持多种分辨率的最佳做法是什么?

编辑:只是为了澄清 - GamePage_SizeChanged 正在执行,它只是 _graphics.ApplyChanges() 似乎没有效果

4

1 回答 1

0

为什么不尝试将 Client Size Changed Event 添加到 Game 构造函数中。

例子:

public Game1()
{
    _graphics = new GraphicsDeviceManager(this);
    this.Windows.ClientSizeChanged += Window_ClientSizeChanged;
}

void Window_ClientSizeChanged(object sender, EventArgs e)
{
    int currentWidth = this.Window.ClientBounds.Width;
    int currentHeight = this.Windows.ClientBounds.Height;
}

您还可以为 ApplicationViewChanged 添加一个事件处理程序,通过将 ViewChangeArgs 与 Windows8 中的 ApplicationViewState 枚举进行比较来检测 Snapped、Filled 和 Full ViewStates。您可以从 _graphics.SwapChainPanel 属性访问游戏的 SwapChainBackgroundPanel。最后,您还有 _graphics.GraphicsDevice.DisplayMode 具有 AspectRatio、Height、Width。

于 2013-03-11T08:16:06.347 回答