- Home /
Question by
RusticRapter · Oct 13, 2021 at 11:55 AM ·
c#spritetexture2d
Texture2D.Apply() not updating pixels
I am creating a new texture and setting each pixel before calling apply. However, the texture is still a fully semi-transparent grey rectangle the matches a fully blank new texture. Here is the code: horizontalResilution is 320 and verticalResilution is 200. Vram is a 4 x 16384 array holding all the pixels in a byte format
Texture2D newTex = new Texture2D(horizontalResilution, verticalResilution);
for (int i = 0; i < verticalResilution; i++)
{
for (int j = 0; j < horizontalResilution; j++)
{
if (i * horizontalResilution + j - curBank * 16384 >= 16384)
{
curBank++;
}
Byte curPixel = vram[curBank, (i * horizontalResilution + j) - (curBank * 16384)];
if (oldVram[curBank, i * horizontalResilution + j - (curBank * 16384)] != curPixel)
{
newTex.SetPixel(i, j, Color.black);
}
}
}
newTex.Apply();
Debug.Log(newTex.GetPixel(1, 1).a);
Sprite newSprite = Sprite.Create(newTex, new Rect(0, 0, horizontalResilution, verticalResilution), new Vector2(0.5f, 0.5f));
spriteRenderer.sprite = newSprite;
Comment