0

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?

artganify
  • 683
  • 1
  • 8
  • 23
  • Just an idea: Try to call spritebatch.Start and End just once in the main draw method of the game, and not in every scene? – Kai Hartmann Dec 04 '15 at 12:04
  • @KaiHartmann What difference does that make? I am completely new to XNA and game development in general so I am not sure yet what the exact purpose of the individual components is or what their invocations do. – artganify Dec 04 '15 at 12:22
  • I'm just talking out of experience; I always use just one Begin() and End() and do all my draw calls in between, so it's just a guess. Begin() starts a new batch operation for drawing, and you might just get the last one on screen each time. – Kai Hartmann Dec 04 '15 at 12:45
  • @KaiHartmann I tried multiple approaches now (with begin/end on every scene or globally and one sprite batch vs batch for every scene) and nothing seems to work. The window just stays black. There might be something wrong with how I manage my update/draw cycles, but I'm failing to figure out what it could be. – artganify Dec 04 '15 at 14:43

0 Answers0