NFurtwangler

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.




Re: XNA Game Studio Express XNA sprite behavior -- weird side effect

Eli Tayrien - MSFT

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.






Re: XNA Game Studio Express XNA sprite behavior -- weird side effect

Shazen

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




Re: XNA Game Studio Express XNA sprite behavior -- weird side effect

NFurtwangler

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!






Re: XNA Game Studio Express XNA sprite behavior -- weird side effect

Shazen

Sorry Eli,

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