C# – XNA: Applying SpriteBatch.Draw(…) color only to non-transparent pixels


I have a sprite loaded from a PNG that has an alpha channel. The image contains an opaque disk, and the rest of it is transparent.

I want to use the color argument of SpriteBatch.Draw(...) to change the tint of the disk. However, the default blending behavior applies the color to the entire sprite, so I end up with an opaque square outline around the tinted disk.

Is there any way to change the blend mode so that transparent pixels are not affected by the color argument?

Best Solution

I've never seen this happen, and I've been working with transparent PNGs like this since the beginning in XNA. Are you mixing 2D and 3D? If so, your 3D render setting may be confusing SpriteBatch, but I thought SpriteBatch was supposed to set these properly for you. Maybe there's something wrong with the PNG image you're using?

Related Question