I'm trying to separate the individual parts of my game into states (scenes) so I can manage them more easily. While everything works in terms of initializing and handling game logic within the update loop, I somehow fail to draw something within the draw loop using sprite batches.
Some excerpts:
Scene
public class Scene : DrawableGameComponent {
private List<GameComponent> _children = new List<GameComponent>();
public override void Draw(GameTime gameTime) {
// invoke draw on all enabled & visible drawable children
}
public override void Update(GameTime gameTime) {
// invoke update on all enabled children
}
}
TitleScene
public class TitleScene : Scene {
private readonly SpriteBatch _spriteBatch;
private Texture2D _titleBackground;
public TitleScene(Game game)
: base(game)
{
_spriteBatch = new SpriteBatch(game.GraphicsDevice);
}
public override void LoadContent() {
_titleBackground = Game.Content.Load...
}
public override void Draw(GameTime gameTime) {
_spriteBatch.Begin();
// draw _titleBackground
_spriteBatch.End();
}
Nothing fancy here. The draw methods get's correclty invoked, however the screen stays black! When I put everything drawing related (loading content, beginning/ending spritebatch) into the draw method of the main game (type deriving from Game
), it get's rendered fine.
Is a game only allowed to have one SpriteBatch
? Or am I missing something here?
Full source of
Scene
,SceneManager
andTitleScene
: http://pastebin.com/5CkbipzCMain game type: http://pastebin.com/pgbrjhna