Hi:
I was trying to create a simple image in runtime, I create a texture, and then use the Sprite.Create to create the sprite, but when I play the game, the texture is ok but the sprite is transparent, it has the pivot in the center and the correct dimensions, but the image isn’t here.
Here´s, the code:
private Texture2D drawMap (int dimX, int dimY, string mapa)
{
Texture2D aux = new Texture2D (dimX, dimY);
aux.filterMode = FilterMode.Point;
for (int i = 0; i < dimX; i++)
{
for (int j = 0; j < dimY; j++)
{
int cuadro = (int)(mapa [i * dimY + j] - '0');
if (cuadro >= 4 && cuadro <= 8)
aux.SetPixel (i, j, this.colorPared);
else //Error = pared
aux.SetPixel (i, j, this.colorSuelo);
}
}
aux.Apply ();
return aux;
}
public void changeImage (int dimX, int dimY, string mapa)
{
Texture2D tex = this.drawMap (dimX, dimY, mapa);
imagen.sprite = Sprite.Create (tex, new Rect (0, 0, tex.width, tex.height), new Vector2 (0.5f, 0.5f));
//imagen is a Image variable
}
(Sorry for some variable names in spanish)
I tried everything, but nothing has work, any idea?
Thanks