Hello
I am trying to create sprite from Texture like , but the size of the sprite is improper . (I guess something to do with pixel meter ?)
Also i saw many methods to create sprite , but all the methods need tk2dSpriteCollectionData .
Can you tell me what is wrong in the below code or let me know if there is a easier method to create a simple 2d sprite from Texture2D , also i didn't get the point Use the texture from sprite component as I mentioned before, and call Create on it when updating the texture.
tk2dBaseSprite spriteInstance = null;
Texture2D runtimeTexture = new Texture2D (4,4);
runtimeTexture.LoadImage (imageTextAsset.bytes);
Debug.Log ("runtimeTexture.width" + runtimeTexture.width + runtimeTexture.height);
string[] names = new string[] {
"Full sprite",
};
Rect[] regions = new Rect[] {
new Rect (0, 0, runtimeTexture.width, runtimeTexture.height)
};
Vector2[] anchors = new Vector2[] {
new Vector2 (.5f, .5f),
};
tk2dSpriteCollectionSize spriteCollectionSize = tk2dSpriteCollectionSize.Explicit (runtimeTexture.width, runtimeTexture.height);
tk2dSpriteCollectionData spriteCollectionInstance = tk2dSpriteCollectionData.CreateFromTexture (runtimeTexture, spriteCollectionSize, names, regions, anchors);
spriteCollectionInstance.halfTargetHeight = 0.5f;
spriteCollectionInstance.invOrthoSize = 2.0f;
GameObject go = new GameObject ("sprite");
go.transform.localPosition = new Vector3 (0,0,0);
spriteInstance = go.AddComponent<tk2dSprite> ();
spriteInstance.SetSprite (spriteCollectionInstance, 0);
In-between i also saw a feature called dicing , it works great in saving Atlas space . Whether using dicing in the atlas increased loading time or any performance issue ?
Thanks