我正在尝试在 Xna 4.0 中制作游戏,但我坚持使用游戏菜单。
protected override void Update(GameTime gameTime)
{
MouseState ms = Mouse.GetState();
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
if (ms.LeftButton == ButtonState.Pressed && ((ms.X >= 280 && ms.X <= 540) && (ms.Y >= 150 && ms.Y <= 200)))
current_screen = ScreenState.Difficulty;
if (current_screen == ScreenState.Title)
{
if (ms.LeftButton == ButtonState.Pressed && ((ms.X >= 280 && ms.X <= 540) && (ms.Y >= 360 && ms.Y <= 410)))
this.Exit();
}
if (current_screen == ScreenState.Difficulty)
{
if (ms.LeftButton == ButtonState.Pressed && ((ms.X >= 300 && ms.X <= 520) && (ms.Y >= 100 && ms.Y <= 130)))
current_screen = ScreenState.Title;
if ((ms.LeftButton == ButtonState.Pressed && oldMouseState.LeftButton == ButtonState.Released) && ((ms.X >= 280 && ms.X <= 540) && (ms.Y >= 150 && ms.Y <= 200)))
{
current_screen = ScreenState.MainGameNovice;
}
}
base.Update(gameTime);
oldMouseState = ms;
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend);
switch (current_screen)
{
case ScreenState.Title:
spriteBatch.Draw(mybg, GraphicsDevice.Viewport.Bounds, Color.White);
spriteBatch.Draw(new_game_button, new Vector2(280, 150), Color.White);
spriteBatch.Draw(load_game_button, new Vector2(280, 220), Color.White);
spriteBatch.Draw(how_to_play_button, new Vector2(280, 290), Color.White);
spriteBatch.Draw(quit_game_button, new Vector2(280, 360), Color.White);
break;
case ScreenState.Difficulty:
spriteBatch.Draw(diff_bg, GraphicsDevice.Viewport.Bounds, Color.White);
spriteBatch.Draw(novice_button, new Vector2(280, 150), Color.White);
spriteBatch.Draw(inter_button, new Vector2(280, 220), Color.White);
spriteBatch.Draw(expert_button, new Vector2(280, 290), Color.White);
break;
case ScreenState.LoadGame:
break;
case ScreenState.HowtoPlay:
break;
case ScreenState.MainGameNovice:
//main game
spriteBatch.Draw(expert_button, new Vector2(580, 290), Color.White);
break;
case ScreenState.MainGameIntermediate:
///main game
break;
case ScreenState.MainGameExpert:
////Main game
break;
}
spriteBatch.End();
base.Draw(gameTime);
}
每当我单击新游戏按钮时,它都会显示难度级别。
问题是当我单击新手按钮时,它不会进入看起来像纯蓝屏的屏幕。它通过它,只需几秒钟,它就会回到难度级别菜单。你能帮我么?我在这里被困了大约一天,我已经搜索了类似的问题,但仍然无法正常工作。