微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

创建具有多个屏幕的 MonoGame 应用程序

如何解决创建具有多个屏幕的 MonoGame 应用程序

我正在尝试创建一个可在 1-8 个屏幕上运行的 MonoGame 基础应用。

我试图通过在每台显示器上创建多个游戏对象并渲染它们来做到这一点 通过运行负责调用“RunOneFrame”方法的内部while循环 每场比赛。

它工作正常,但我看到“RunOneFrame”方法仅用于测试和调试目的。 另外,我有一些滞后......

满足该要求的最佳做法是什么?甚至可以在 MonoGame 上使用吗?

谢谢:)

解决方法

在 WindowsDX 平台(仅)Monogame 上有一个函数叫做 GameWindow.CreateWindow()

您可以在game1.cs中使用以下代码:

//Additional using statement at the top of file
using System.Windows.Forms;

//...

//class level variables
private const int SCREENX = 800,SCREENY = 600;
private SwapChainRenderTarget[] _swapChain = new SwapChainRenderTarget[7];  // 7 + main window

//...

protected override void Initialize()
{
     GameWindow _otherWindow;

     for(int x = 0; x < 7; x++)
     {    
     _otherWindow = GameWindow.Create(this,SCREENX,SCREENY);
     Form _newForm = Form.FromHandle(_otherWindow.Handle);

     // move to target window based on desktop layout
     _newForm.Location = new System.Drawing.Point(SCREENX * (x + 1) % 4,SCREENY * (x + 1) / 4); 
     //  assuming all of the screens are the same size and in a 4 wide by 2 high config
     //  with the the primary in the top left
     
     _newForm.Visible = true; // show the form
     _newForm.WindowState = FormWindowState.Maximized;

     _swapChain[x] = new SwapChainRenderTarget(this.GraphicsDevice,_otherWindow.Handle,_otherWindow.ClientBounds.Width,_otherWindow.ClientBounds.Height,false,SurfaceFormat.Color,DepthFormat.Depth24Stencil8,1,RenderTargetUsage.PlatformContents,PresentInterval.Default);
    }
base.Initialize();
}

//...

protected override void Draw(GameTime gameTime)
    {
        for (int i = 0; i < 7; i++) 
        {
            GraphicsDevice.SetRenderTarget(_swapChain[i]);
            GraphicsDevice.Clear(Color.Black);
            // TODO Add screen i draw code here(0-7)
            _swapChain[i].Present(); 
        }

        GraphicsDevice.SetRenderTarget(null);
        GraphicsDevice.Clear(Color.Black);
        // TODO Draw primary screen here
        base.Draw(gameTime);
    }

鼠标控制很棘手,可能值得提出不同的问题。 基本思想是每个屏幕都有自己的 MouseState。所以代码是Mouse.GetState(_otherWindow)

所有屏幕的坐标系(包括鼠标)都是局部的,即 (0,0) 位于每个屏幕的左上角。

您将需要具有大量 VRAM 的强大 GPU。此代码将需要 8 倍的 CPU-GPU 数据传输带宽。我会在 gameTime.IsrunningSlowly == true 上进行测试,看看渲染时间是否过长,如果是,请将 TargetElapsedTime 设置为较慢的速率(60 FPS 的默认值为 16.67 毫秒)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。