【问题标题】:Supporting multiple resolutions in MonoGame Windows 8 XAML app在 MonoGame Windows 8 XAML 应用程序中支持多种分辨率
【发布时间】:2013-03-10 22:36:09
【问题描述】:

我正在编写一个使用 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() 似乎没有任何效果

【问题讨论】:

    标签: windows-8 xna winrt-xaml monogame


    【解决方案1】:

    为什么不尝试将 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 ViewState。您可以从 _graphics.SwapChainPanel 属性访问游戏的 SwapChainBackgroundPanel。最后,您还有 _graphics.GraphicsDevice.DisplayMode 具有 AspectRatio、Height、Width。

    【讨论】:

    • 谢谢,我知道在哪里对大小变化做出反应,但问题是更改 PreferredBackBufferWidth 没有效果。而且我不知道如何在不进行手动转换的情况下使内容比例保持纵横比。
    • 对于 Windows 8,PreferredBufferWidth 在 MonoGame 中预设为 1366、760。您可以访问当前的 GraphicDevice 和用于开始和结束 DeviceChanging 的事件处理程序,因此您应该能够在那里更改设备大小。让我在我的游戏中测试一下,然后我会发布代码。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多