我目前正在尝试在C#中使用monogame和winforms创建一个mapeditor。我正在使用Windows 7机器上的Visual Studio 2015。我创建了一个winforms项目,并添加了以下参考:MonoGame.Framework,OpenTk和OpenTK.GLControl。然后我包含了XNA Winforms Sample的以下文件:GraphicsDeviceControl.cs,GraphicsDeviceService.cs和ServiceContainer.cs。完成此操作后,我沿着this tutorial将XNA Sample移植到MonoGame。这一切都有效。用winforms使用monogame
然后我创造了这个测试类,看看它的工作原理:
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TileMapEditor
{
class Test : GraphicsDeviceControl
{
ContentManager content;
SpriteBatch spriteBatch;
Texture2D t;
protected override void Initialize()
{
content = new ContentManager(Services, "Content");
spriteBatch = new SpriteBatch(GraphicsDevice);
t = content.Load<Texture2D>("Gameplay/Player");
}
protected override void Draw()
{
spriteBatch.Begin();
spriteBatch.Draw(t, new Rectangle(10, 10, t.Width, t.Height), Color.White);
spriteBatch.End();
}
}
}
然后我建项目,使这个类将在窗体设计工具箱显示出来。这也起到了作用,所以我继续在设计器中将这个类拖到表单上。这也是正常的。然后我再次构建了这个项目,并希望我的纹理能够显示出来,然而,我只有一个黑色的窗口和我在设计器中添加的类一样大,看到这张图片:prnt.sc/b33my9(自从我创建第三个链接后没有足够的代表) 我还可以提到Visual Studio 2015说GraphicsDeviceService.cs中的字段'GraphicsDeviceService.parameters'从不使用。我不知道这是否是我的问题的一部分。 我也试图与这条线,以取代在Draw函数我的代码:
GraphicsDevice.Clear(Color.Blue);
,但我仍然得到了同样的黑色窗口。 我也尝试了位于此gitub repo中的MGWinFormsControls项目中的移植的xna示例:github.com/jaquadro/MonoGame-WinFormsControls,结果是'GraphicsDeviceService.parameters'警告消失了,但除黑色窗口外,我仍无法获取任何内容。
有没有人知道我应该怎么做才能解决这个问题?
在此先感谢!
谢谢!它经过大量研究和麻烦终于在工作:D – TS1997
链接被破坏,版本库似乎不存在 – MGZero