XNA Creators Club Online
Page 1 of 1 (4 items)
Sort Posts: Previous Next

Layer Depth Issues

Last post 11/13/2009 8:53 PM by Storm Kiernan. 3 replies.
  • 11/13/2009 4:58 PM

    Layer Depth Issues

    I figured this problem was solved in my previous thread : http://forums.xna.com/forums/t/42241.aspx
    I went from : http://img200.imageshack.us/img200/2369/screenshotyhq.png
    To : http://img194.imageshack.us/img194/3921/screenie2a.png

    So far, so good. Until my GUI gets its share of the thunder: http://img338.imageshack.us/img338/8391/screenie3.png
    This didn't happen until I changed my draw code from:

            public override void Draw(GameTime gameTime) 
            { 
                _spriteBatch.Begin(); 
                if (!_paused) 
                { 
                    _tileManager.Draw(gameTime); 
                    _entityManager.Draw(gameTime); 
                    _guiManager.Draw(gameTime); 
                } 
                _spriteBatch.End(); 
     
                base.Draw(gameTime); 
            } 

    To:
            public override void Draw(GameTime gameTime) 
            { 
                _spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.FrontToBack, SaveStateMode.None); 
                if (!_paused) 
                { 
                    _tileManager.Draw(gameTime); 
                    _entityManager.Draw(gameTime); 
                    _guiManager.Draw(gameTime); 
                } 
                _spriteBatch.End(); 
     
                base.Draw(gameTime); 
            } 

    In the last example, my actors draw correctly, but the GUI messes up.... What should I do?
  • 11/13/2009 5:13 PM In reply to

    Re: Layer Depth Issues

    I have fixed the problem temporarily by adding another SpriteBatch and calling a different Begin() method. This works, but now there are two sprite batch calls instead of one. :( Is there a better way?
  • 11/13/2009 5:29 PM In reply to

    Re: Layer Depth Issues

    Storm Kiernan:
    What should I do?


    Either:

    • Use immediate or deferred sort mode, and issue your draw calls in the order you want things to appear
    • Use front-to-back or back-to-front sort mode, and make sure that every draw call includes a sensible layer depth value
    • Use more than one sprite batch
    XNA Framework Developer - blog - homepage
  • 11/13/2009 8:53 PM In reply to

    Re: Layer Depth Issues

    Shawn Hargreaves:
    Storm Kiernan:
    What should I do?


    Either:

    • Use immediate or deferred sort mode, and issue your draw calls in the order you want things to appear
    • Use front-to-back or back-to-front sort mode, and make sure that every draw call includes a sensible layer depth value
    • Use more than one sprite batch
    I used two sprite batches, one with normal, one with front-to-back. Works.
Page 1 of 1 (4 items) Previous Next