- Home /
Tiled Map Display Problem
Hi,
I load a tiled map made by Tiled Map Editor, but there are black edges around each tile, how to fix it?
The script I used is similar to UniTMX, here is the generating uv part:
private List<Vector2> GenUV (ref TileSet tileset)
{
List<Vector2> uv = new List<Vector2> ();
int horizontalCellCount = (tileset.SourceWidth - tileset.Margin) / (tileset.TileWidth + tileset.Spacing);
int verticalCellCount = (tileset.SourceHeight - tileset.Margin) / (tileset.TileHeight + tileset.Spacing);
float cellWidth = ((float)(tileset.TileWidth) / tileset.SourceWidth);
float cellHeight = ((float)(tileset.TileHeight) / tileset.SourceHeight);
int dataValue;
for (int y = 0; y < Height; y++)
{
for (int x = 0; x < Width; x++)
{
if (Data[y, x] != 0)
{
dataValue = Data[y, x] - tileset.FirstGID;
int posY = dataValue / verticalCellCount;
int posX = dataValue % horizontalCellCount;
float u = ((float)(tileset.Margin + (tileset.TileWidth + tileset.Spacing) * posX) / tileset.SourceWidth);
float v = 1.0f - ((float)(tileset.Margin + (tileset.TileHeight + tileset.Spacing) * posY) / tileset.SourceHeight);
uv.AddRange (new Vector2[] {
new Vector2 (u, v),
new Vector2 (u, v - cellHeight),
new Vector2 (u + cellWidth, v),
new Vector2 (u + cellWidth, v - cellHeight),
});
}
}
}
return uv;
}
My tileset has 4 pixels for both spacing and margin.
Thank you for your help.
do you have edge on the texture?
if you do than that's normal
Thanks for your reply, sdgd. Here is my texture:
As you can see there is no edge. I used TexturePacker to create this texture.
Try setting spacing and/or margin to zero and see what that gives you.
I tried to use a texture without spacing and margin, but there are still edges. Here is a screenshot:
Are you using shadows/baked shadows? What happens when you set the tiles to simple diffuse?
Answer by westwind · Mar 30, 2013 at 02:49 AM
Hi, I've found a solution. It seems a texture problem. I found someone asked a similar question at here: link text
However, the answer doesn't work for me. Instead, I found if I set the texture's Filter Mode to Point, there will be no dark lines. I don't know why, but it dose solve the problem.
Your answer
![](https://koobas.hobune.stream/wayback/20220613094852im_/https://answers.unity.com/themes/thub/images/avi.jpg)