我目前正在嘗試在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