我正在尝试为我的游戏制作一个开始菜单,我的代码使用 Enum 来监控屏幕状态。
现在我想在我的背景类中更改主类中声明的屏幕状态
Screen screen = new Screen();
在 Game1 类中声明
Background(ref screen);
这是在背景类的更新方法中
KeyboardState keystate = Keyboard.GetState();
switch (screen)
{
case Screen.Start:
if (isPressed && keystate.IsKeyUp(Keys.Up) && keystate.IsKeyUp(Keys.Down) && keystate.IsKeyUp(Keys.Enter))
{
isPressed = false;
}
if (keystate.IsKeyDown(Keys.Down) && isPressed != true)
{
if (menuState == MenuState.Options)
menuState = MenuState.Credits;
if (menuState == MenuState.Play)
menuState = MenuState.Options;
isPressed = true;
}
if (keystate.IsKeyDown(Keys.Up) && isPressed != true)
{
if (menuState == MenuState.Options)
menuState = MenuState.Play;
if (menuState == MenuState.Credits)
menuState = MenuState.Options;
isPressed = true;
}
switch (menuState)
{
case MenuState.Play:
arrowRect.X = 450;
arrowRect.Y = 220;
if (keystate.IsKeyDown(Keys.Enter) && isPressed != true)
screen = Screen.Play;
break;
case MenuState.Options:
arrowRect.X = 419;
arrowRect.Y = 340;
if (keystate.IsKeyDown(Keys.Enter) && isPressed != true)
screen = Screen.Options;
break;
case MenuState.Credits:
arrowRect.X = 425;
arrowRect.Y = 460;
if (keystate.IsKeyDown(Keys.Enter) && isPressed != true)
screen = Screen.Credits;
break;
}
break;
}
}
出于某种原因,当我玩这个并按下回车按钮时,背景类的屏幕已更改,但主类的屏幕不是我该如何更改?