C# 名称';内向型';在当前上下文中不存在

C# 名称';内向型';在当前上下文中不存在,c#,xna,C#,Xna,我在Game1类的开关块中得到了这三条错误消息,但我不知道如何修复它们。怎么了? 当前上下文中不存在名称“IntroState” 当前上下文中不存在名称“MenuState” 当前上下文中不存在名称“MaingameState” 此外,我在Intro类中收到以下错误消息: 当前上下文中不存在名称“IntroState” public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics;

我在Game1类的开关块中得到了这三条错误消息,但我不知道如何修复它们。怎么了? 当前上下文中不存在名称“IntroState” 当前上下文中不存在名称“MenuState”
当前上下文中不存在名称“MaingameState”

此外,我在Intro类中收到以下错误消息: 当前上下文中不存在名称“IntroState”

public class Game1 : Microsoft.Xna.Framework.Game
{
    GraphicsDeviceManager graphics;
    SpriteBatch spriteBatch;
    IState currentState;

    public enum GameStates
    {
        IntroState = 0,
        MenuState = 1,
        MaingameState = 2,
    }


    public void ChangeGameState(GameStates newState)
    {
        switch (newState)
        {
            case IntroState:
                currentState = new Intro(this);
                break;
            case MenuState:
                currentState = new Menu(this);
                break;
            case MaingameState:
                currentState = new Maingame(this);
                break;
        }
        currentState.Load(Content);
    }


    public GameStates CurrentState
    {
        get { return currentGameState; }
        set { currentGameState = value; }
    }

    private GameStates currentGameState = GameStates.IntroState;


    public Game1()
    {
        graphics = new GraphicsDeviceManager(this);
        Content.RootDirectory = "Content";
    }

    protected override void Initialize()
    {
        currentState = new Intro(this);
        base.Initialize();
    }

    protected override void LoadContent()
    {       
        spriteBatch = new SpriteBatch(GraphicsDevice);
        currentState.Load(Content);
    }

    protected override void Update(GameTime gameTime)
    {
        currentState.Update(gameTime);     
        KeyboardState kbState = Keyboard.GetState();
        base.Update(gameTime);
    }

    protected override void Draw(GameTime gameTime)
    {
        GraphicsDevice.Clear(Color.CornflowerBlue);
        spriteBatch.Begin();
        currentState.Render(spriteBatch);
        spriteBatch.End();

        base.Draw(gameTime);
    }
}

public interface IState
    {
        void Load(ContentManager content);
        void Update(GameTime gametime);
        void Render(SpriteBatch batch);
    }


public class Intro : IState
{
    Texture2D Introscreen;
    private Game1 game1;       

    public Intro(Game1 game)
    {
        game1 = game;
    }

    public void Load(ContentManager content)
    {
       Introscreen = content.Load<Texture2D>("intro");
    }

    public void Update(GameTime gametime)
    {
        KeyboardState kbState = Keyboard.GetState();
        if (kbState.IsKeyDown(Keys.Space))
          game1.ChangeGameState(IntroState);
    }

    public void Render(SpriteBatch batch)
    {
        batch.Draw(Introscreen, new Rectangle(0, 0, 1280, 720), Color.White);
    }
}
公共类游戏1:Microsoft.Xna.Framework.Game
{
图形管理器图形;
SpriteBatch SpriteBatch;
IState当前状态;
公共枚举游戏状态
{
内部状态=0,
MenuState=1,
MaingameState=2,
}
公共无效更改游戏状态(游戏状态新闻状态)
{
交换机(新闻状态)
{
案例介绍:
当前状态=新的介绍(本);
打破
案例说明:
currentState=新菜单(此菜单);
打破
案例状态:
currentState=新的主游戏(此);
打破
}
currentState.Load(内容);
}
公共游戏状态当前状态
{
获取{return currentGameState;}
设置{currentGameState=value;}
}
私有游戏状态currentGameState=GameStates.IntroState;
公共游戏1()
{
graphics=新的GraphicsDeviceManager(此);
Content.RootDirectory=“Content”;
}
受保护的覆盖无效初始化()
{
当前状态=新的介绍(本);
base.Initialize();
}
受保护的覆盖void LoadContent()
{       
spriteBatch=新spriteBatch(图形设备);
currentState.Load(内容);
}
受保护覆盖无效更新(游戏时间游戏时间)
{
更新(游戏时间);
KeyboardState kbState=Keyboard.GetState();
更新(游戏时间);
}
受保护覆盖无效绘制(游戏时间游戏时间)
{
图形设备。清晰(颜色:矢车菊蓝);
spriteBatch.Begin();
currentState.Render(spriteBatch);
spriteBatch.End();
基础。抽签(游戏时间);
}
}
公共接口IState
{
无效加载(ContentManager内容);
无效更新(游戏时间游戏时间);
无效渲染(SpriteBatch批处理);
}
公共课简介:IState
{
纹理2d内屏幕;
私人游戏1游戏1;
公开介绍(游戏1)
{
游戏1=游戏;
}
公共无效加载(ContentManager内容)
{
Introscreen=content.Load(“intro”);
}
公开作废更新(游戏时间游戏时间)
{
KeyboardState kbState=Keyboard.GetState();
if(kbState.IsKeyDown(Keys.Space))
游戏1.改变游戏状态(内含状态);
}
公共无效渲染(SpriteBatch批处理)
{
批处理绘制(屏幕内部,新矩形(0,0,1280,720),颜色为白色);
}
}
试试:

IntroState
MenuState
MaingameState
属于枚举

尝试:


IntroState
MenuState
MaingameState
属于枚举

只有在类型名称前加前缀时才能使用
enum
值:

  //case IntroState:
    case GameStates.IntroState:

您不能单独使用
IntroState

只有在类型名称前加前缀时才能使用
enum
值:

  //case IntroState:
    case GameStates.IntroState:

你永远不能单独使用
IntroState

你应该将
IntroState
称为
GameStates.IntroState
。这同样适用于其他两种情况。

您应该将
IntroState
称为
GameStates.IntroState
。其他两个也一样