- Home /
Sprites and textureformats on Android
Hi,
I am experiencing something strange..
What I am trying is to create a UI Sprite at runtime using the following code:
Texture2D texture = new Texture2D(512, 512, TextureFormat.ARGB32, true);
texture.LoadImage(Convert.FromBase64String(SpriteBase64));
Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0, 0));
As you can see I am using the ARGB32 format, this is because I am creating a sprite of a PNG formatted file with transparency.
When I run my game on my Android device or PC it displays as a ARGB32 which is good I guess but the textures are acting weird (see pic).
Note: The green/yellow stripes are part of the background image but the blue/purple icon is the glitchy texture. It looks like this on both Android and PC
Now when I define a new image in the editor manually, create the sprite manually and assign it manually then it will have an ARGB32 format on Android but on PC it will display as a RGBA4444.
Now the texture looks perfect on Android as well as on my PC:
Note: I've placed this image on the sky of the background image, that's why the stripes are blue'ish. It looks like this on both Android and PC
In short
When I create an image manually, create a sprite manually and manually assign it my texture looks perfect on all devices, why doesn't this work when I assign my sprite generated by code to my image on the instantiated prefab?