“按 Enter 开始游戏” XNA 简介屏幕

发布于 2024-09-28 00:26:01 字数 70 浏览 0 评论 0原文

我创建了一个介绍屏幕,其中包含“按 Enter 开始游戏”,(然后退出)当然退出没有问题,但让游戏开始有点困难。有什么建议吗?

I created an introscreen with "Press Enter to start the game",(and exit) ofcourse exit is no problem but to let the game start its a bit harder. Any advice?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

秋日私语 2024-10-05 00:26:01

最简单的方法是设置状态机。看起来真的很简单。

enum GameState 
{
TitleScreen = 0,
GameStarted,
GameEnded,
}

然后,在 Game1.cs 中,或者在处理此按钮单击的任何位置,您可以在类中放置一个变量来存储您所处的当前游戏状态。

GameState currentGameState = GameState.TitleScreen;

然后,在对实际游戏进行绘制或更新之前你编码后,你可以检查当前的游戏状态

void Draw(GameTime time)
{
   if(currentGameState == GameStarted)
   {
       //Then handle the game drawing code here

   }
}

更新方法基本上看起来是一样的

The easiest way to do this would be to set up a State Machine. It would look really simple.

enum GameState 
{
TitleScreen = 0,
GameStarted,
GameEnded,
}

Something then in the Game1.cs, or wherever you're handling this button click, you can put a variable in you class to store the current game state that you are in.

GameState currentGameState = GameState.TitleScreen;

Then, before you do a draw or update on the actual game you coded, you can check the current game state

void Draw(GameTime time)
{
   if(currentGameState == GameStarted)
   {
       //Then handle the game drawing code here

   }
}

The update method would basically look the same

醉南桥 2024-10-05 00:26:01

正如 ninename 所说,状态机是解决问题的方法。不过,我建议您查看此示例 - http://create。 msdn.com/en-US/education/catalog/sample/game_state_management - 由 Microsoft 提供,而不是您自己提供。
非常容易实现和更改,几乎涵盖了您想做的所有事情,包括输入处理。

As ninename says a state machine is the way to go here. I would however sugest that you look at this sample - http://create.msdn.com/en-US/education/catalog/sample/game_state_management - provided by microsoft rather than roling your own.
Very easy to implment and change whist covering prety much everything you could want to do, including input handling.

终陌 2024-10-05 00:26:01

我使用的系统运行良好(对我来说)

设置一个名为 IContext 之类的接口。其中有 void Draw() 和 void Update()。

然后在游戏中有一个称为 Context 的公共 IContext。您只需在提供的游戏循环中调用 context.update() 和 context.draw() 即可。

然后菜单屏幕只需实现 IContext。您通过游戏对象的构造函数传入对游戏对象的引用,这使您可以更改插入的任何对象的上下文。

因此,当您收到调用的 Enter 键时,您可以插入“menu”并插入菜单up this.game.context = new level01();

希望这是有道理的。

缺口

The system I use works well (for me)

Setup an interface called something like IContext. in this have void Draw() and void Update().

then in game have a public IContext called Context. you simply call context.update() and context.draw() in the supplied gameloop.

Then a menu screen simply has to implement IContext. You pass in a reference to your game object through its constructor which lets you change the context from any object you plug in.

So you plug in "menu" and in menu when you recive the Enter key you call up this.game.context = new level01();

Hope this makes sense.

Nick

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文