When you’ve exhausted the possible…

Spent my lunch break troubleshooting something weird with a MonoGame-SDL2 (soon to be FNA) play project:

One of my sprites, *one* of them, was not rendering correctly.  Then entire upper half of it was rendering as a solid block.  The sprite itself is a tiny white explosion, which I was rendering with Color.Chartreuse for a Space Invaders knock off.  (Explosions in the bunker area should appear green, because it was a monochrome game with a color overlay on the screen, and I was simulating the exact game).

Now the first thing I though was that maybe there was a bug corrupting the sprite data.  But, I added a separate draw call to the loop, rendering the sprite with Color.Red so that it would stick out for me.  And… it looked fine.  Now, I was puzzled.

So, I was using the same texture in two places, but one draw consistently came out corrupt, and one consistently came out fine.

Changing the Color mask to white, the issue becomes apparent:  My sprite rendered in white… but the top half had a chartreuse background for some unknown reason.  In Gimp, the whole thing just looks transparent.

That’s when I realized that I had originally resized the canvas in Gimp.  Everything that was at the top half was part of the original image, and the bottom half had never had any pixels in it except the part of the sprite I had drawn.

I knew the alpha values of the texture were good, because I use the same texture as a mask when I destroy chunks of the bunker shields.

Apparently MonoGame (or at least MonoGame-SDL2) doesn’t honor the alpha value if there’s any color data.

Re-exporting the sprite with “save color values from transparent pixels” eliminates the problem.  Whew.