I'm drawing each of my Tiled Map Layers separately so as to create the illusion of depth. I'd like my character sprite to be between the background tiles but in front of the building tiles. I'm using "FronttoBack" spritesortmode for my spritebatch. and the optional layer parameter for my playersprite. For my layers I'm also using the optional layer float parameter.

 public override void Draw(GameTime gameTime, SpriteBatch spriteBatch, TiledMapRenderer renderer)
    {



        if (player.Health > 0)
        {
            spriteBatch.Begin(SpriteSortMode.FrontToBack, transformMatrix: cam.GetViewMatrix());



            renderer.Draw(backGround, cam.GetViewMatrix(),depth: (float).1);

            player.anim.Draw(spriteBatch, new Vector2(player.Position.X, player.Position.Y), (float).3);

            renderer.Draw(buildings, cam.GetViewMatrix(), depth: (float).2);
            renderer.Draw(midGround, cam.GetViewMatrix(), depth: (float).4);
            renderer.Draw(foreGround, cam.GetViewMatrix(), depth: (float).5);
            renderer.Draw(alwaysFront, cam.GetViewMatrix(), depth: (float).6);

But for some reason it doesn't matter what I change the numbers to, the player is always drawn first and the layers are drawn in the order they are coded, not according to their layerdepth. The spritebatch layerdepth works between the player and other spritebatch-drawn sprites, but not with the tiledlayers.

Anyone know what's happening here? I'm not sure why the layerdepth for the renderer.draw() isn't working.

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.