简体   繁体   English

退出另一个游戏后是否可以运行XNA游戏?

[英]Is it possible to run a XNA game after exiting another?

Is it possible to run a XNA game after exiting another? 退出另一个游戏后是否可以运行XNA游戏?
I tried to write at the default XNA's "Program.cs": 我试图用默认的XNA的“ Program.cs”编写:

using (Game1 game = new Game1())
{
    game.Run();
}

using (Game2 game = new Game2())
{
    game.Run();
}

but after exiting the first game the second was running once and then just exited the game.... 但是退出第一个游戏后,第二个运行了一次,然后退出了游戏。

edit: 编辑:
I found that when I try to exit the window with the X button (of the window...) the second game window starts... 我发现,当我尝试使用X按钮(该窗口的...)退出该窗口时,第二个游戏窗口开始...

You might want to use the OnExiting() method in your Game1 class to create a new instance of a game when one is closed. 您可能想在Game1类中使用OnExiting()方法在游戏关闭时创建一个新的游戏实例。

protected override void OnExiting(Object sender, EventArgs args)
{
    using (Game2 game = new Game2())
    {
        game.Run();
    }
    base.OnExiting(sender, args);
}

Chances are, you can accomplish what you are trying to do, by using Game Components instead. 您可以改用游戏组件来完成您想做的事情。

I'm not entirely sure what you are trying to do here, but more than likely there is a better solution. 我不确定您要在这里做什么,但是可能有更好的解决方案。

More information on game components here . 有关游戏组件的更多信息,请点击此处

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

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