问题
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.
For something like DirectX and XNA, how are these other screens created/rendered?
回答1:
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;
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);
}
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.
来源:https://stackoverflow.com/questions/16825623/how-are-multiple-page-views-created-in-a-game