简体   繁体   English

运行XNA游戏时运行Windows窗体

[英]Run windows form while running an XNA game

I am currently designing a RPG game which requires me to utilize an inventory system. 我目前正在设计一款RPG游戏,要求我使用库存系统。 Ideally, the user would press a key and make the the character's inventory window open. 理想情况下,用户可以按一个键并打开角色的库存窗口。

example: 例:

protected override void Update(GameTime gameTime)
{
    if ((GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
    || (Keyboard.GetState().IsKeyDown(Keys.Escape))) // to exit game, press Esc button
    { this.Exit(); }

    if (Keyboard.GetState().IsKeyDown(Keys.E))
    {
      //insert window from lunch code here...
    }

    // TODO: Add your update logic here
    base.Update(gameTime);
}

I am designing the inventory screen using a window form. 我正在使用窗口表单设计库存屏幕。 However, i have no idea whatsoever on how to load the window form into the Game1 file. 但是,我不知道如何将窗体加载到Game1文件中。 Any advise would be appreciated. 任何建议将不胜感激。

您需要在XNA项目中设计库存屏幕,就像创建精灵并在Update方法中捕获用户输入一样。

There are two relatively straightforward routes you can go with this that I could recommend: 我可以推荐两种相对简单的路线:

  1. Do everything in XNA. 在XNA中做一切。 This means all your UI (such as inventory window) would have to be done using XNA techniques. 这意味着您必须使用XNA技术完成所有UI(例如库存窗口)。 This option is going to give you the best design because, let's be honest, WinForms can be a bit ugly especially when they are forced into something that doesn't look anything like a WinForm 这个选项会给你最好的设计,因为,说实话,WinForms可能有点难看,特别是当他们被迫进入看起来不像WinForm的东西时

  2. Do everything in WinForms. 在WinForms中做一切。 Basically your game would have to be in a WinForm so that all your WinForms can easily communicate through their normal means. 基本上你的游戏必须在WinForm中,这样你的所有WinForms都可以通过正常方式轻松进行通信。 The good news is that you can embed an XNA screen inside a WinForm. 好消息是你可以在WinForm中嵌入一个XNA屏幕。 Basically any XNA level editor tutorial will show you how to do this but here is one example on codeplex and some sample code from Microsoft's collection of examples . 基本上任何XNA级别的编辑器教程都会向您展示如何执行此操作,但这里有一个关于codeplex的 示例以及Microsoft的示例集合中的一些示例代码 From this you should be able to get everything talking. 从这个你应该能够让一切都在谈论。 This approach is less than ideal due to performance reasons and aesthetics, but it should be functional if your game is simple enough. 由于性能原因和美观,这种方法不太理想,但如果您的游戏足够简单,它应该是有用的。

I would highly recommend option one above but if all else fails option two does work. 我强烈推荐上面的选项一,但如果一切都失败,选项二确实有效。

It would be better if you save yourself the trouble and just draw everything out in XNA. 如果你省去麻烦并在XNA中绘制所有东西会更好。 Basically have two classes, one that has all the items, and the other for your inventory. 基本上有两个类,一个包含所有项目,另一个包含库存。 You should also have a List to manage things easier. 您还应该有一个List来更轻松地管理事物。

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

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