別のクラスでExit()を使用するにはどうすればよいですか?Introクラスで使用したいのですが、「menuinterface.Menu.exit」が割り当てられることはなく、常にデフォルト値の「null」エラーメッセージが表示されます。なにが問題ですか?
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
private IState currentState;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
currentState = new Intro();
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
currentState.Load(Content);
}
protected override void Update(GameTime gameTime)
{
currentState.Update(gameTime);
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;
private Game1 exit;
Texture2D introscreen;
public void Load(ContentManager content)
{
introscreen = content.Load<Texture2D>("intro");
}
public void Update(GameTime gametime)
{
KeyboardState kbState = Keyboard.GetState();
if (kbState.IsKeyDown(Keys.Space))
currentState = new Menu();
if (kbState.IsKeyDown(Keys.Escape))
exit.Exit();
}
public void Render(SpriteBatch batch)
{
batch.Draw(introscreen, new Rectangle(0, 0, 1280, 720), Color.White);
}
}