在Windows窗体用户控件Embeding一的XNA Game [英] Embeding a XNA Game in a Windows Form User Control
问题描述
我写了一个简单的XNA 4.0游戏。我想制作一个Windows窗体用户控件,将渲染这个游戏,并提供必要的交互反馈(键盘和鼠标)回XNA。
我试过以下:
在XNA中:
-
将XNA的Game.GraphicsDevice
发出一个事件发送一个对象与KeyboardState和MouseState要填写Windows窗体,在Update
在WinForms中:
-
捕获事件,使用Windows窗体中通常的键盘和鼠标事件获得的数据填充KeyboardState和MouseState。
-
在OnPaint上调用Game.RunOnFrame
-
从游戏中获取RenderTarget2D(作为纹理)。
-
另一个想法只是调用Game.Run()(oa new
我发现了以下问题:
-
如果我调用Game.Run(),我无法隐藏游戏的窗口(显示为黑色,因为我重定向render )
-
Game.Run()必须在不同的线程上调用,因为它启动一个新的事件循环(它调用应用程序方法),然后我
-
使用Color,Vector4甚至Rgba32锁定RenderTarget2D不会影响我们的用户控件
任何想法?
提前感谢。
xna的网站上有一个关于嵌入xna在winform。它会带你通过所有的步骤。我为Xbox制作游戏,但我使用它为我们的引擎的级别编辑器。
I have a simple XNA 4.0 Game written. I want to make a Windows Form User Control that will render this game, and provide the necessary interaction feedback (keyboard and mouse) back to XNA. I have tried the following: In XNA: Redirect XNA's Game.GraphicsDevice to a RenderTarget2D. Emit an event sending an object with KeyboardState and MouseState to be filled in by Windows Forms, at the beginning of Update() In WinForms: Capture the event, filling in KeyboardState and MouseState with data obtained by the usual keyboard and mouse events in Windows Forms. On the OnPaint, call Game.RunOnFrame() Get the RenderTarget2D from the game (as a texture). Lock the texture's data, and try to paint it pixel by pixel in my user control's Graphics. Another idea was just calling Game.Run() (o a new Thread) and emit an event in Game sending the RenderTarget2D. I have found the following problems: If I call Game.Run() I have no way to hide the game's window (which appears black, because I'm redirecting the render) Game.Run() must be called on a different thread because it starts a new event loop (it calls Application methods), and then I'm painting in my user control from a different thread that it was created (bad, bad) Locking a RenderTarget2D with Color, Vector4, and even Rgba32 doesn't appear to work for me (it says 'wrong structure size') Any ideas? Thanks in advance. There is a great code sample on xna's site about embedding xna in a winform. It takes you through all the steps. I make games for xbox, but I use this for the level editor we've made for our engine. http://xbox.create.msdn.com/en-US/education/catalog/sample/winforms_series_1 这篇关于在Windows窗体用户控件Embeding一的XNA Game的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!