我的所有三个屏幕/状态都可以正常工作,但是,我实现了第四个作为信息屏幕。到目前为止还不错,但是当我运行游戏并按“H”键时,它不会将屏幕更改为另一个背景(到目前为止我所做的)。下面是代码:
public void UpdateInformation(GameTime currentTime)
{
if (Keyboard.GetState().IsKeyDown(Keys.H))
{
GameState = 4;
} // GAMESTATE 4 which is the instruction/Information screen.
}
这是更新方法中游戏状态的代码:
protected override void Update(GameTime gameTime)
{
switch (GameState)
{
case 1: UpdateStarted(gameTime);
break;
case 2: UpdatePlaying(gameTime);
break;
case 3: UpdateEnded(gameTime);
break;
case 4: UpdateInformation(gameTime);
break;
}
base.Update(gameTime);
}
在这里,我正在绘制屏幕。
public void DrawInformation(GameTime currentTime)
{
spriteBatch.Begin();
spriteBatch.Draw(InfoBackground, Vector2.Zero, Color.White);
spriteBatch.End();
}
以下是各州的抽奖信息代码:
protected override void Draw(GameTime gameTime)
{
switch (GameState)
{
case 1: DrawStarted(gameTime);
break;
case 2: DrawPlaying(gameTime);
break;
case 3: DrawEnded(gameTime);
break;
case 4: DrawInformation(gameTime);
break;
}
}
我希望这会有所帮助,只是我的 H 键没有响应,但我的 S 键响应良好并开始游戏。四个状态/屏幕是否与“Gamestate”兼容?谢谢你。