加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – XNA – 如何从主要课外退出游戏?

发布时间:2020-12-16 00:23:04 所属栏目:百科 来源:网络整理
导读:你怎么做到这样游戏可以退出但没有主类中的代码,让它在不同的类? 解决方法 您可以创建一个方法: //Inside of game1.cspublic void Quit(){ this.Exit()} 我假设您想要在菜单组件上退出游戏,在这种情况下,您需要将game1的实例传递给组件,或者将其作为菜单组
你怎么做到这样游戏可以退出但没有主类中的代码,让它在不同的类?

解决方法

您可以创建一个方法:

//Inside of game1.cs
public void Quit()
{
    this.Exit()
}

我假设您想要在菜单组件上退出游戏,在这种情况下,您需要将game1的实例传递给组件,或者将其作为菜单组件更新方法中的参数添加.

public void Update(GameTime gameTime,Game1 game)
{
     if(key is pressed)
     {
          game.Quit();
     }
}

我不确定是否还有其他方法……也许找到一种方法来“强制”按下关闭按钮.

为了发送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'
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读