许多游戏示例/教程仅专注于主游戏的渲染,而没有显示游戏的其余部分,例如第一个登陆页面,启动屏幕,高分页面,积分页面等.
Many game examples/tutorials focus only on the rendering of the main game and don't show the rest of the game, like the first landing page, splash screen, high scores page, credits page and so on.
对于DirectX和XNA之类的东西,这些其他屏幕是如何创建/渲染的?
For something like DirectX and XNA, how are these other screens created/rendered?
推荐答案对于Davidsbro提到的Microsoft示例,如果要创建自己的基本游戏状态管理系统,则可以使用枚举开关来实现.对于这种方法,您将声明一个枚举类型并设置其默认值,在这种情况下,默认值可以是游戏的主菜单.在XNA中,它看起来类似于以下内容:
Alternatively to the Microsoft sample mentioned by Davidsbro, if you wanted to create your own basic game state management system you could do so through the use of an enum switch. For this approach you would declare an enum type and set it's default value, in this case the default value could be the main menu of a game. In XNA this would look something like the following:
enum GameScene { menu, game }; GameScene scene = GameScene.menu;在游戏更新方法内,您将实现一个switch语句,该语句负责处理两个枚举状态:
Inside of the games update method you would then implement a switch statement which would be responsible for handling both enum states:
protected override void Update(GameTime gameTime) { switch (scene) { case GameScene.menu: { // Perform menu scene logic break; } case GameScene.game: { // Perform game scene logic break; } } base.Update(gameTime); }然后,您需要在draw方法中实现与上面的枚举开关类似的另一个开关.
You would then need to implement another switch within the draw method similarly to the enum switch above.
protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); switch (scene) { case GameScene.menu: { // Draw menu scene break; } case GameScene.game: { // Draw game scene break; } } base.Draw(gameTime); }此外,您将需要实现某种形式的逻辑以在不同游戏状态之间进行转换.这可以通过用户输入或某种形式的游戏计时器来实现.
Additionally you would need to implement some form of logic to transition between the different game states. This could be achieved through user input or some form of game timer.
更多推荐
如何在游戏中创建多个页面视图?
发布评论