简体   繁体   English

如何在WPF中使用XNA?

[英]How to use XNA in WPF?

So... I want to make a game, and I want to write it in C#. 所以...我想制作一个游戏,我想用C#编写它。 In the past, I've made a mario clone using C++ and OpenGL. 在过去,我使用C ++和OpenGL制作了马里奥克隆。 I quite like OpenGL, but I don't know how well it's supported inside C#/WPF. 我非常喜欢OpenGL,但我不知道它在C#/ WPF中的支持程度如何。 Also, it might be beneficial to use an actual game library? 此外,使用实际的游戏库可能是有益的吗? I guess XNA is the game library for C#, so maybe I'll invest a bit of time learning that. 我猜XNA是C# 游戏库,所以也许我会投入一些时间来学习它。

However, I want to use WPF form controls for my level editor... is there any way that I can embed an XNA (DirectX?) window inside a WPF app? 但是,我想在我的关卡编辑器中使用WPF表单控件...有什么方法可以在WPF应用程序中嵌入一个XNA(DirectX?)窗口?

Specifically, I don't need any buttons or things inside the XNA/DirectX widget, just around it, so no mixing required...just need to get a graphics widget in my WPF form. 具体而言,我不需要任何按钮或事物的XNA / DirectX的窗口小部件里面 ,只是周围 ,所以无需混合...只需要得到一个图形在我的WPF表单控件。

Nick Gravelyn explains how to do it on his blog. Nick Gravelyn在他的博客上解释了如何做到这一点。

Although, if it's just for an editor, you may find using WinForms is easier and better supported. 虽然,如果它只是一个编辑器,你可能会发现使用WinForms更容易和更好的支持。

WPF uses DirectX, and you can do direct "interop" here is a codeProject article on the subject. WPF使用DirectX,你可以直接“interop” 这里是关于这个主题的codeProject文章 Here is an article i dug up where the author is using win-forms and WPF controls in an XNA project. 这是一篇我挖出的文章 ,作者在XNA项目中使用win-forms和WPF控件。 Might be worth a look for you. 可能值得一看。

First of all, you should ask this on gamedev.stackexchange.com. 首先,你应该在gamedev.stackexchange.com上问这个问题。 But I've seen a tutorial embedding XNA. 但是我看过嵌入XNA的教程。

You should check this question and this page. 你应该检查这个问题和这个页面。 They are on Windows Forms, but they'll help. 它们在Windows窗体上,但它们会有所帮助。

Also check this and this articles. 还要检查这个这个文章。

Keep in mind one thing. 请记住一件事。 XNA is meant to be used for the whole game, integration would be useful on making level editors like you say, but not for a full game. XNA旨在用于整个游戏,集成对于像你说的那样制作关卡编辑器是有用的,但不适用于完整的游戏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM