Tuesday, October 2, 2018

xna - Alpha From PNGs Butchered


I have a pretty vanilla Monogame game. I'm using PNG for all my sprites (made in Photoshop). I noticed that XNA is butchering the aliasing; no matter what I do, my graphics appear jaggedy.


Below is a screenshot. The bottom half is what XNA shows me when I zoom in 2X using a Matrix on my GraphicsDevice (to make the effect more obvious). The top is when I pasted the same sprites from Photoshop and scaled them to 200%.


Note that partially transparent pixels are turning whiteish.


Is there a way to fix this? What am I doing wrong?


Here's the relevant call to draw to the SpriteBatch:


spriteBatch.Draw(this.texture, this.positionVector, null, Color.White, this.Angle, this.originVector, 1f, SpriteEffects.None, 0f);


(this.positionVector can easily be Vector.Zero; Color.White as 100% alpha, I think; this.Angle can be a real angle (small > in the image) or zero (the orb itself).


enter image description here



Answer



Ensure you're enabling blending in your SpriteBatch.Begin() call. I think for PNGs, BlendState.NonPremultiplied is probably the one you want.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...