1
NGUI 3 Support / Textures offset when copying individual sprites from UIAtlas to a new texture
« on: September 21, 2016, 01:47:48 PM »
Hi,
I have a bunch of textures within a UIAtlas. I need to "extract" those textures from the atlas (in runtime) and have each one applied to a UITexture for a specific purpose. Textures are RGBA32.
However when I do the copying, the resulting textures are strangely offset by some non-constant Y value (around 512 in some cases). It's clear that something goes wrong around the GetPixels phase.
This is how I do it:
Please help!!
I have a bunch of textures within a UIAtlas. I need to "extract" those textures from the atlas (in runtime) and have each one applied to a UITexture for a specific purpose. Textures are RGBA32.
However when I do the copying, the resulting textures are strangely offset by some non-constant Y value (around 512 in some cases). It's clear that something goes wrong around the GetPixels phase.
This is how I do it:
- List<UISpriteData> spriteList = sourceAtlas.spriteList;
- Texture2D src_tex2d = Instantiate(sourceTex) as Texture2D;
- for (int i=0; i<spriteList.Count; i++) {
- UISpriteData data = spriteList[i];
- Color[] pix = src_tex2d.GetPixels(data.x, data.y, data.width, data.height);
- spriteTextures[i].SetPixels(pix);
- spriteTextures[i].Apply();
- }
Please help!!