- Home /
SetPixel on Texture2D help needed
Hello.
I have an image that is a cupcake that I am trying to take a "bite" out of.
To accomplish this I simply call SetPixel() on the cupcake texture to Color.Clear to fill the bite to alpha transparency.
This works fine EXCEPT it leaves an outline border around the area I am clearing out. (see attached image).
Does anyone know what's causing this outline/border to show up?
Here is my code:
public void OnPointerDown()
{
Vector3 mousePosition = Input.mousePosition;
Color col = new Color (0,0,0,0);
int startX = (int)mousePosition.x - 50;
int startY = (int)mousePosition.y - 50;
// This is the pattern I want to follow to make the bite mark.
Texture2D texture = Resources.Load("Bite") as Texture2D;
for (int y = 0; y < texture.height; y++)
{
for (int x = 0; x < texture.width; x++)
{
if (texture.GetPixel (x, y).a == 1)
{
_cupcakeEatingTexture.SetPixel (startX + x, startY + y, Color.clear);
}
}
}
_cupcakeEatingTexture.Apply ();
}
cupcake.png
(135.5 kB)
Comment
Answer by Eric5h5 · Jan 07, 2016 at 11:46 PM
Presumably the result of anti-aliasing in the image. Either don't use that, or allow for alpha that's less than 1, rather than using ".a == 1".
Your answer
![](https://koobas.hobune.stream/wayback/20220612055405im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
SetPixels PROBLEM (trying to put decals) 0 Answers
Fastest way to update Texture2D 0 Answers
Math to have a bullet penetrate stuff in 2D? 1 Answer