コードを変更しましたが、それでも機能しません。Introクラスで次のエラーメッセージが表示されます。'GameStates':式を介して型を参照できません。代わりに「menuinterface.Game1.GameStates」を試してください
なにが問題ですか?プレーヤーがスペースキーを押した場合、ゲーム状態をMenuStateに設定したいと思います。
Game1クラス:
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
private IState currentState;
public enum GameStates
{
IntroState = 0,
MenuState = 1,
MaingameState = 2,
}
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
{
private IState currentState;
Texture2D Menuscreen;
private Game1 game1;
public Intro(Game1 game)
{
game1 = game;
}
public void Load(ContentManager content)
{
Menuscreen = content.Load<Texture2D>("menu");
}
public void Update(GameTime gametime)
{
KeyboardState kbState = Keyboard.GetState();
if (kbState.IsKeyDown(Keys.Space))
game1.CurrentState = game1.GameStates.IntroState;
currentState = new Menu(game1);
}
public void Render(SpriteBatch batch)
{
batch.Draw(Menuscreen, new Rectangle(0, 0, 1280, 720), Color.White);
}
}