3
votes

I am an experienced developer, but a total noob to graphics/game programming, so please - explain it to me like I'm a 5 year old.

I am writing a simple game in order to learn game programming. I created a *.png image using Paint.NET, and made the image 50% transparent. When I load the image however, it seems to render without any transparency. The object looks like a solid color. (Just to be clear, I'm trying to make the whole image semi-transparent or "see through", not just make a solid image with a transparent background. Although I'd like to be able to do that as well.)

I'm happy to show whatever code might help, although you can assume I'm not doing anything fancy here. For example, loading a texture:

var Texture = content.Load<Texture2D>("Gamepiece");

And drawing it:

spriteBatch.Draw(Texture, Location, Color.White);

My begin statement uses the defaults. I'm not passing in any parameters (I have no understand of them anyway).

spriteBatch.Begin();
1
It's not too late to accept the answer :)increddibelly

1 Answers

5
votes

The trick is in the parameters to the SpriteBatch.Begin method. In your case you want to set the BlendState. Sooner or later you'll probably want to use some of the other parameters too but for now you can get away with the 2 parameter overload. If you are pre-compiling your assets into XNB files you'll probably want either BlendState.AlphaBlend or BlendState.Additive like this:

_spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);

Or if you are loading the png directly you'll probably want BlendState.NonPremultiplied. Play around with the values to see what effect suits you best.