XNA - 如何从主比其他类游戏退出? [英] XNA - How to Exit Game from class other than main?
本文介绍了XNA - 如何从主比其他类游戏退出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你如何使它所以本场比赛可以退出,但不能在主类中的代码,有它在不同的类?
How do you make it so the game can exit but not have the code in the main class, have it in a different class?
推荐答案
您可以创建一个方法:
//Inside of game1.cs
public void Quit()
{
this.Exit()
}
我'M假设你想退出菜单组件上的游戏,在这种情况下,你需要GAME1的实例传递给组件,也许它添加为菜单组件更新方法的参数。
I'm assuming you want to quit the game on a menu component, in which case you will need to pass the instance of game1 to the component, perhaps add it as a parameter in the menu components update method.
public void Update(GameTime gameTime, Game1 game)
{
if(key is pressed)
{
game.Quit();
}
}
我不知道是否有任何其他的方法......也许寻找一种方法来强制关闭按钮按
I'm not sure if there are any other ways... Perhaps finding a way to "force" the close button to press.
为了送game1.cs的实例:
In order to send the instance of game1.cs:
//in game1.cs
//in your update method
public void Update(GameTime gameTime)
{
//sends the current game instance to the other classes update method, where
// quit might be called.
otherClass.Update(gameTime, this);
//where 'this' is the actual keyword 'this'. It should be left as 'this'
}
这篇关于XNA - 如何从主比其他类游戏退出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文