Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

So the problem I'm having is that when using Nick Gravelyn's tiledlib pipeline for reading and drawing tmx maps in XNA, the transparency color I set in Tiled's editor will work in the editor, but when I draw it the color that's supposed to become transparent still draws.

Magenta Overflow onto House

The closest things to a solution that I've found are -

1) Change my sprite batch's BlendState to NonPremultiplied (found this in a buried Tweet).

2) Get the pixels that are supposed to be transparent at some point then Set them all to transparent.

Solution 1 didn't work for me, and solution 2 seems hacky and not a very good way to approach this particular problem, especially since it looks like the custom pipeline processor reads in the transparent color and sets it to the color key for transparency according to the code, just something is going wrong somewhere. At least that's what it looks like the code is doing.

TileSetContent.cs
    if (imageNode.Attributes["trans"] != null)
        {
            string color = imageNode.Attributes["trans"].Value;
            string r = color.Substring(0, 2);
            string g = color.Substring(2, 2);
            string b = color.Substring(4, 2);
            this.ColorKey = new Color((byte)Convert.ToInt32(r, 16), (byte)Convert.ToInt32(g, 16), (byte)Convert.ToInt32(b, 16));
        }
        ...

TiledHelpers.cs
    // build the asset as an external reference
            OpaqueDataDictionary data = new OpaqueDataDictionary();
            data.Add("GenerateMipMaps", false);
            data.Add("ResizetoPowerOfTwo", false);
            data.Add("TextureFormat", TextureProcessorOutputFormat.Color);
            data.Add("ColorKeyEnabled", tileSet.ColorKey.HasValue);
            data.Add("ColorKeyColor", tileSet.ColorKey.HasValue ? tileSet.ColorKey.Value : Microsoft.Xna.Framework.Color.Magenta);
            tileSet.Texture = context.BuildAsset<Texture2DContent, Texture2DContent>(
                new ExternalReference<Texture2DContent>(path), null, data, null, asset);
       ...

I can share more code as well if it helps to understand my problem. Thank you.

share|improve this question
1  
#1 does something completely different to what you want. #2 is a perfectly reasonable solution - although what you've written seems backwards: pixels of the colour key (ie: magenta) get set to transparent by TextureProcessor. Have you tried the Content Pipeline Debugger? –  Andrew Russell Nov 6 '12 at 13:51
    
I tried this after reading this comment, however, it doesn't stop on any problems and I've stepped through the processes and not seeing where it might be failing since everything is being set as it should. –  Adam LaBranche Nov 6 '12 at 22:35
add comment

1 Answer 1

up vote 1 down vote accepted

What I would do is open the tiles in an image editing program (like GIMP), and select all of that pink layer and delete it, leaving only a transparent background layer. Then no more worrying is necessary about using those tiles with colored backgrounds.

share|improve this answer
    
Yes, I forgot about this as I do most simple things. I will try it and let you know. I just wish I could get Nick's code to work for me as it was intended. –  Adam LaBranche Nov 6 '12 at 22:40
    
Making the colors already transparent instead of a color like Magenta to be removed by the processor worked when used in combination with BlendState.NonPremultiplied. If set to AlphaBlend it still does not work. This solution should work for me. Thank you for reminding me I could do this! I was very tunnel visioned. –  Adam LaBranche Nov 7 '12 at 0:33
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.