In my gamestate management system I've got a screen manager and a menuscreen, both added to my current game. The screen manager opens a spritebatch then calls the draw methods of all of the subscribed screens, but when I get to the first SpriteBatch.Draw call in my first subscribed screen I get an error saying that a SpriteBatch.Begin must be called previously, which it was.
ScreenManager Draw Code:
public override void Draw(GameTime gameTime)
{
SpriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
for (int i = 0; i < ScreenList.Count; i++)
{
if (ScreenList[i].Visible)
ScreenList[i].Draw(gameTime);
}
SpriteBatch.End();
base.Draw(gameTime);
}
and my MenuScreen Draw Code:
public override void Draw(GameTime gameTime)
{
SpriteBatch.Draw(Background, new Rectangle(0, 0, ScreenManager.Game.Window.ClientBounds.Width, ScreenManager.Game.Window.ClientBounds.Height),
null, Color.White, 0f, new Vector2(Background.Width / 2, Background.Height / 2), SpriteEffects.None, 1f);
SpriteBatch.DrawString(Font, Text, Position, Color, 0f, Origin, Scale, SpriteEffects.None, 0f);
foreach (MenuEntry entry in EntryList)
{
entry.Draw(gameTime);
}
}
and finally my base game initialize code where I create all these components:
protected override void Initialize()
{
screenManager = new ScreenManager(this, Content.Load<SpriteFont>("Fonts/DefaultFont"), Content.Load<Texture2D>("Images/Background"));
Components.Add(screenManager);
screenManager.AddScreen(new MainMenuScreen(screenManager, "Tanks", new Vector2(screenManager.Game.Window.ClientBounds.Width / 2, 100)));
base.Initialize();
}
NOTE: MainMenuScreen inherits from MenuScreen which is an abstract class. Also my MenuScreen class gets passed a spritebatch from the ScreenManager class so they should be the same spriteBatch.