How to get tilemap transparency color working with TiledLib's Demo implementation?
Posted
by
Adam LaBranche
on Game Development
See other posts from Game Development
or by Adam LaBranche
Published on 2012-11-06T11:08:17Z
Indexed on
2012/11/06
17:23 UTC
Read the original article
Hit count: 423
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.
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.
© Game Development or respective owner