- Home /
Black border around 2D sprite
There seems to be some kind of graphical/rendering bug. I am making different themes for my video game and for some reason, when I switch themes(a different sprite sheet), there's a black border around it. I made sure the rendering options are the same on both sprite sheets, and both sprites were the same resolution. Can someone please explain why this is happening?
The original themed buttons
The new themed buttons
Answer by Koen-Matthijs · Jan 25, 2017 at 11:09 PM
Hi
I had a few of these occur as well. The actual black line is because the background of your cam is black and Unity is not so happy with your sprite size.
A few things you should check:
Your sprite should be NPOT. If it isn't make it so and fill the added space with transparency.
Check the filtering and use Point Filtering
Play with the pixel-to-unit size (set it 1-on-1 just to see what happens and adjust from there)
Switch on pixel snapping (i.e. go pixel perfect) or use a custom material with the default sprite shader
Hope these may help you out.
Kind regards,
Koen Matthijs
Playing around with these setting worked beautifully, thanks!
Answer by liortal · Aug 30, 2017 at 09:02 PM
Setting the created texture to use point filtering seems to give better results:
public static Sprite LoadPNGToSprite(string filepath)
{
Texture2D texture = LoadPNG(filepath);
texture.alphaIsTransparency = true;
texture.wrapMode = TextureWrapMode.Repeat;
texture.filterMode = FilterMode.Point;
float pixelsPerUnit = 100;
return Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0, 0), pixelsPerUnit);
}
Answer by jrwalz · Mar 23, 2018 at 11:30 PM
I was actually thinking about spending some time learning this Unity graphics engine. So I thought that I would start out with something simple, like putting a border around a sprite then manually creating a map from each sprite with that border. Well that would have been a lot of work for a graphics engine that is supposed to represent 2018, but then I realized what would seem completely illogical. There isn't a way to put a border around the sprite, wow. I'll wait for the next future, the real one.
Your answer
Follow this Question
Related Questions
Smoothing Directionally between three materials 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
2D Sprite Graphics Glitching, Skewing, Flickering, Crazy, Haywire 1 Answer
Strange artifacts in builds 0 Answers