Microsoft Game Technologies: XNA sprite behavior -- weird side effect

  • nfurtwangler / 100 / Sun, 31 Jan 2010 10:33:00 GMT / Comments (4)
  • Hello, I'm new to XNA as well as DirectX and am experiencing some weird side effects when drawing a sprite that I can't account for. I have a 3D ship that I can fly around using the Xbox360 controller (completed the XNA tutorials 1-3) and decided to see if I could implement pausing.

    Well, i got everything working how I want it and even made a 2d sprite that loads a texture asset and draws it to the screen when the player pauses (just a blue rectangle with the word "Paused..." written on it). That works great too, except by drawing the sprite to the screen my 3d model suddenly becomes semi-transparent! Even when the sprite is no longer being drawn the model remains semi-transparent until I restart the game.

    I am developing in XNA Game Studio Express and deploying onto my Xbox360.

    I am confused by this side-effect of drawing the sprite. The 3d model references a .tga for it's texture but it is completely separate from my .bmp texture (which has been added through the content pipeline).

    Here's the code that causes the effect (by commenting it out I no longer see the Pause sprite but also no longer get semi-transparency on the model):

    spriteBatch.Begin(SpriteBlendMode.None);

    spriteBatch.Draw(pauseTexture,

    new Rectangle(graphics.GraphicsDevice.Viewport.Width/2 - pauseTexture.Width/2,

    graphics.GraphicsDevice.Viewport.Height/2 - pauseTexture.Height/2,

    pauseTexture.Width,

    pauseTexture.Height),

    Color.White);

    spriteBatch.End();

    At first I didn't use a SpriteBlendMode but thought maybe by explicitly using SpriteBlendMode.None I would avoid any possible transparency confusion, but it has no effect.

  • Keywords:

    xna, sprite, behavior, weird, side, effect, microsoft, game

  • http://msdn.itags.org/microsoft-game/244603/«« Last Thread - Next Thread »»
    1. You might find these links helpful:

      http://blogs.msdn.com/shawnhar/archive/2006/11/13/spritebatch-and-renderstates.aspx

      http://msdn2.microsoft.com/en-us/library/bb203941.aspx

      After drawing using SpriteBatch, why do my 3D objects draw incorrectly?

      By default, SpriteBatch.Begin does not save your current render state, and will change certain render state properties that may make 3D objects render incorrectly. You can choose to either reset the render state yourself after the call to SpriteBatch.End, or call SpriteBatch.Begin and pass in SaveStateMode.SaveState, which will restore the render state after sprites are drawn.

      elitayrien_msft | Mon, 03 Sep 2007 23:17:00 GMT |

    2. Eli,

      Are there any performance considerations to which option to choose? I certainly find it easier to set the SaveStateMode than to manually adjust my device, but I wonder if it would ever be prudent to manually change just the device settings necessary?

      shazen | Mon, 03 Sep 2007 23:19:00 GMT |

    3. I ended up using a different SpriteBatch.Begin overload as follows:

      spriteBatch.Begin(SpriteBlendMode.None,SpriteSortMode.BackToFront,SaveStateMode.SaveState);

      and now it works as I expect!

      Thanks Eli!

      nfurtwangler | Mon, 03 Sep 2007 23:20:00 GMT |

    4. Sorry Eli,

      I posted the last post before reading Shawn's blog you referenced. Never mind. ;-)

      shazen | Mon, 03 Sep 2007 23:21:00 GMT |

  • Microsoft Game Technologies Questions

    • XNA Overview Webcast

      Register ...

      By jimperry

    • XNA Parallax Engine

      Hi,I hope this doesn't break any of the rules, I have checked and I don't think that it does.The par...

      By kinlan

    • XNA is really great

      Hello! My first post on the forum. My name is Phantasy, I like fantasy so that is why. I am sure XNA...

      By phantasy

    • XNA Podcast

      XBL Radio.com has put out their roundtable on XNA with myself and a couple of developers. Check it o...

      By jimperry