- Home /
The question is answered, right answer was accepted
tk2d change tk2dSprite's Sprite value at runtime
Hi
I have a tk2dsprite that is showing correctly inside a gameobject at runtime, but I would like to change the Sprite to another image in the same collection at runtime. Is this possible, an if so...how?
Any help would be greatly appreciated, thanks!
Answer by aphexyuri · Jan 26, 2012 at 12:25 AM
I actually got a reply from the creator. The most efficient way to handle this is by: iconSprite.spriteId = iconSprite.GetSpriteIdByName("iconName");
You only have to change the spriteId property of the thesprite, and you can pass the sprite name with GetSpriteIdByName() to get the id :)
Answer by OutRage_Studios · Jan 25, 2012 at 02:36 AM
Personally i would simply create an animation of the two sprites, this would allow you to call the animation when nessecary within your code which in turn would change your sprite.
Answer by Pechyonkin · Jan 16, 2014 at 03:55 PM
Also you can set property for that Sprite if you want to change SpriteCollection, where it will search sprite with yours new spriteId
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Sprite Overlap why? 0 Answers
The sprite editor renders images weird 0 Answers