Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm struggling with getting the depth layer to work properly. No matter what I do, the line is drawn over the top of the circle texture.

public void Draw(SpriteBatch spriteBatch)

        // Draw all planets
        foreach (PlanetNode p in planets)


PlanetNode's Draw:

public void Draw(SpriteBatch spriteBatch)
    // Draw forwarding line
    if (resourceForward)
        double dist = Math.Sqrt(Math.Pow(location.X - forwardTo.location.X, 2) +
                                Math.Pow(location.Y - forwardTo.location.Y, 2));
        float angle = Utility.GetAngle(location, forwardTo.location);
        spriteBatch.Draw(Textures.BlackPixel, new Rectangle((int)location.X, (int)location.Y, (int)dist, 1), null, Color.Black, angle, Vector2.Zero, SpriteEffects.None, 0.9f);

    // Draw Planet
    if (mouseOver)
        Color c = new Color(color.R + 0.2f, color.G + 0.2f, color.B + 0.2f);
        spriteBatch.Draw(Textures.Planet, position, null, c, 0f, texOrigin, SpriteEffects.None, 0.5f);
        spriteBatch.Draw(Textures.Planet, position, null, color, 0f, texOrigin, SpriteEffects.None, 0.5f);

    // Draw overlay text
    Vector2 size = Textures.TextFont.MeasureString(resources.ToString());
    spriteBatch.DrawString(Textures.TextFont, resources.ToString(), new Vector2(position.X - size.X / 2, position.Y - size.Y / 2), Color.Black);
share|improve this question
Only thing I can spot is are you missing GraphicsDevice.Clear(Color.CornflowerBlue); at the start of your Draw(). Otherwise your sort mode and layer values look fine to me. With sort mode set to BackToFront the smaller layer value should be on top which is what you seem to have done. – TerryB Feb 10 '12 at 2:28
up vote 1 down vote accepted

To be honest, judging by the way you're drawing your sprites (which all look fine to me, by the way) it may be better to just switch to SpriteSortMode.Deferred and keep a constant layerDepth.

Doing this and keeping your layerDepths at 0 will produce the result you want.

So, a quick sample:

 spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
 //Draw your line here

 //Draw your Planet(s) here with layerDepth set to 0


If, for some reason, you desperately need to use layerDepth, I will take another look and update my answer for you.

share|improve this answer
Ahhh it seems that the planets are sort of semi-transparent. Thank you all for the help though, but I'm pretty sure that its this transparency issue. Thats what I get for downloading a texture from the internet.. – Ben Feb 10 '12 at 4:09
:) I was gonna suggest that but then I thought "nahhhh" – TerryB Feb 10 '12 at 5:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.