需要帮忙!将Windows窗体链接到游戏类。 [英] Need help! Linking a Windows Form to a Game class.

查看:74
本文介绍了需要帮忙!将Windows窗体链接到游戏类。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。



我是一个相当新的编码,并且没有足够的学费来到达我所在的地方,但我非常坚持这个关于我最新大学任务的问题。



首先,我获得了从大学开始合作的框架,因此,项目类型是一个类库,但它作为游戏运行。游戏本身是一个简单的侧滚动射击游戏,类似于经典的R-Type游戏系列。该项目本身并不需要显示那么多技术,所以它只是一个2D游戏,主要使用我已经给过的图形。



As一种显示额外功劳的方法,我正在尝试使用Windows窗体实现一系列菜单屏幕。我有一个在启动应用程序时创建的开始菜单。它有2个按钮。一个启动游戏(通过关闭窗体并使用this.PlayScene(场景)方法播放场景。第二个按钮应该退出游戏,但我不知道如何让这个工作。< br $>


到目前为止,我尝试了以下方法:



Hi everyone.

I''m fairly new to coding and have had very little tuition to get to where I am, but I am very stuck with this problem on my latest University assignment.

First of all, I was given the framework to start working with from the University and as such, the project type is a Class Library, but it runs as a game. The game itself is a simple side-scrolling shooter similar to the classic R-Type game series. The project itself doesn''t have to display that many techniques, so it''s only a 2D game using mostly graphics I''ve been given.

As a way to show extra credit, I''m trying to implement a series of menu screens using Windows Forms. I have one that is created when the application is launched to be the opening menu. It has 2 buttons. One which launches the game (by closing the form and playing the scene using a this.PlayScene(Scene) method. The second button is supposed to exit the game, but I don''t know how to get this one to work.

So far, I have tried methods such as:

public void button2_Click(object sender, EventArgs e)
{
    this.Close();
    mKernel.Exit();
}







In Form1:
int _counter = 0;

public int setCounter(int counter)
{
    counter = _counter;
    return counter;
}

public void button2_Click(object sender, EventArgs e)
{
    _counter++;
    this.Close();
}

In Kernel:
int counter = 0;

form1.ShowDialog();
form1.Focus();

counter = form1.setCounter(counter);

if (counter != 0)
{
    this.Exit();
}





在这两种情况下,Kernel类都是主要的XNAGame类。在我尝试的每次尝试中,单击按钮只需关闭表单并正常运行场景。在表单关闭后单击此按钮以关闭它时,有什么方法可以让Kernel类退出游戏吗?



In both cases, the Kernel class is the main XNAGame class. In every attempt I''ve tried, clicking the button simply closes the form and runs the scene as normal. Is there any way I could possibly get the Kernel class to exit the game after the form is closed and this button was clicked in order to close it?

推荐答案

有许多其他方式...请参阅游戏状态管理,如果你想继续使用winforms .....尝试使用System.Diagnostic.Process.Start(C:\ Windows \ System32 \taskkill.exe,/ f / im [yourappname] / silent);而不是this.Exit();
there are lots of other ways...see Game State Management and if you want to continue with winforms.....try using "System.Diagnostic.Process.Start("C:\Windows\System32\taskkill.exe","/f /im [yourappname] /silent");" instead of "this.Exit();"


这篇关于需要帮忙!将Windows窗体链接到游戏类。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆