我试图让我的 SplashScreen 状态首先出现,这在我使用我的 Thread.Sleep(2300); 之前起作用。但现在它总是先进入菜单状态。我需要帮助让它在菜单之前进入 SplashScreen 状态并等待 2300 毫秒然后进入菜单状态。
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using System.Threading;
namespace Obsession
{
/// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
enum _gameState { Splashscreen, Menu, Options, DLC, Playing , Exit };
_gameState currentState;
Vector2 caravanPos = new Vector2(0, 0);
Texture2D caravanSplash;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
/// <summary>
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
/// </summary>
protected override void Initialize()
{
Window.Title = "Obsession DB 1.0";
graphics.PreferredBackBufferWidth = 800;
graphics.PreferredBackBufferHeight = 600;
//if (graphics.IsFullScreen != true)
//graphics.ToggleFullScreen();
base.Initialize();
}
/// <summary>
/// LoadContent will be called once per game and is the place to load
/// all of your content.
/// </summary>
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
caravanSplash = this.Content.Load<Texture2D>("data/textures/splash1");
currentState = _gameState.Splashscreen;
}
/// <summary>
/// UnloadContent will be called once per game and is the place to unload
/// all content.
/// </summary>`
protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}
/// <summary>
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
switch (currentState)
{
case _gameState.Splashscreen:
{
SplashScreenUpdate();
break;
}
case _gameState.Menu:
{
MenuUpdate();
break;
}
}
base.Update(gameTime);
}
/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
switch (currentState)
{
case _gameState.Splashscreen:
{
SplashScreenDraw();
break;
}
case _gameState.Menu:
{
MenuDraw();
break;
}
}
spriteBatch.End();
base.Draw(gameTime);
}
private void SplashScreenUpdate()
{
Thread.Sleep(2300);
currentState = _gameState.Menu;
/*for (int i = 0; i < 5; i++)
{
if (Keyboard.GetState().IsKeyDown(Keys.A) == true)
{
Thread.Sleep(3000);
currentState = _gameState.Menu;
return;
}
}*/
}
private void SplashScreenDraw()
{
spriteBatch.Draw(caravanSplash, caravanPos, Color.White);
}
private void MenuUpdate()
{
if (Keyboard.GetState().IsKeyDown(Keys.A) == true)
{
currentState = _gameState.Splashscreen;
return;
}
}
private void MenuDraw()
{
GraphicsDevice.Clear(Color.White);
}
}
}