How to get rid of dark line on the edge of transparent pixels?

I have a sprite sheet that has each sprite in a 32x32 pixel area. I am using the Tiled map editor, that exports sprite map data as XML, allowing me to build game maps in that editor. In Unity, I’ve written a script that takes the map XML, and the sprite sheet(s) that is(are) imported, and pieces together a new Texture2D based on the map XML and applies it to a sprite to generate the map and layers, etc.

There’s one issue that I cannot figure out, and it’s this dark line that shows up on the border between a tile, and a transparent space. Here is the image that describes my problem.

alt text

I have messed with various import settings already, such as the following:

  • Disable mip maps
  • Set filtering mode to Point
  • Clamp instead of wrap
  • Turn off compression, set to RGBA32
  • My texture is power of 2
  • My texture fits in the size of 4096, it IS 4096.

I’ve also read through this thread which details a problem that sounds very similar to mine, except there is no spare space around the tiles in the sprite sheet to stretch out colors to smooth stuff out, and I’m piecing together the final Texture2D in code.

The last tidbit that I think might be relevant is the fact that when I run in to a non-tile, in the map, e.g. if there’s “nothing” in that area on the layer, I put a blank/clear tile in that spot with Texture2D.SetPixels() with a full Color of Colors.clear.

Thanks in advance for any help!

You may want to check the Wrap Mode value for the texture. Select the texture (not object/prefab) from your project folder, and switch the Wrap Mode between Clamp and Repeat. This picture illustrates a bug similar to yours, though it isn’t using XML. It may be helpful to your situation.

[25840-repeat+vs+clamp.png|25840]

The above answer addresses one issue in this instance, but it didn’t cure it for me. If this method doesn’t work for you, the other fix is to click the actual texture (Mine are all set to 2D sprites because I’m working with solid pixel art), when the texture/sprite asset is selected, look at your inspector and change the filter mode to Point instead of Bilinear or Trilinear. The point filter will cure that blur and get rid of those weird lines along the border of the actual sprite. In the above answer, their assets are textures.

TLDR, if you’re working with sprites and your asset’s texture types are set to “sprite”, change the filter mode to Point to avoid any artifacting and loss of image info to your art!

peace