1
Support / Re: Change the material of each sprite in SpriteDefinition at run time.
« on: April 01, 2015, 09:31:04 am »
Thanks for the link.
I found an idea from one of your answers here http://2dtoolkit.com/forum/index.php?topic=356.0#msg_1529
So now I am doing following.
1] Keep the tk2dsprite already added to the gameobject and set the expected sprite collection. , earlier I was adding it at run time.
2] Now at run time decide upon which animation to play and set its animation library.
3] Now, on this gameobject's tk2dSprite do following :-
One most important thing its doing is getting "current" sprite definitions. and that is all I wanted. Directly modifying the sprite definitions which are currently loaded in memory. It works like charm.
my only concern now is that : Whether this approach can break things ? as I am not changing the material any where but only textures.My earlier approach corrupted the sprite collection and I had to create sprite collection again. Once you confirm this I am good to go
I found an idea from one of your answers here http://2dtoolkit.com/forum/index.php?topic=356.0#msg_1529

So now I am doing following.
1] Keep the tk2dsprite already added to the gameobject and set the expected sprite collection. , earlier I was adding it at run time.
2] Now at run time decide upon which animation to play and set its animation library.
3] Now, on this gameobject's tk2dSprite do following :-
Code: [Select]
sprite.GetCurrentSpriteDef ().material.SetTexture ("_MainTex", Resources.Load (pathForShirt + "atlas0") as Texture);One most important thing its doing is getting "current" sprite definitions. and that is all I wanted. Directly modifying the sprite definitions which are currently loaded in memory. It works like charm.
my only concern now is that : Whether this approach can break things ? as I am not changing the material any where but only textures.My earlier approach corrupted the sprite collection and I had to create sprite collection again. Once you confirm this I am good to go

