“按回车键开始游戏"XNA 介绍画面 [英] "Press Enter to start the game" XNA INTRO SCREEN

查看:39
本文介绍了“按回车键开始游戏"XNA 介绍画面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个带有按 Enter 开始游戏"的介绍屏幕,(并退出)当然退出没问题,但让游戏开始有点困难.有什么建议吗?

解决方案

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

<前>枚举游戏状态{标题屏幕 = 0,游戏开始,游戏结束,}

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

<前>GameState currentGameState = GameState.TitleScreen;

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

<前>void Draw(GameTime 时间){if(currentGameState == GameStarted){//然后在这里处理游戏绘图代码}}

更新方法看起来基本一样

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?

解决方案

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

这篇关于“按回车键开始游戏"XNA 介绍画面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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