2D Toolkit Forum
2D Toolkit => Support => Topic started by: partyson on June 12, 2013, 07:24:22 am
-
I have v2. And I have a sprite animation in my resources folder, but cannot figure out how to load it in C#, give it a position, and play it.
The closest answers I've found are:
http://unikronsoftware.com/2dtoolkit/forum/index.php/topic,36.msg6599.html#msg6599
http://unikronsoftware.com/2dtoolkit/forum/index.php/topic,1739.msg8580.html#msg8580
Thanks!
-
Here you go
tk2dSpriteAnimation library = Resources.Load("TheSpriteAnimation", typeof(tk2dSpriteAnimation)) as tk2dSpriteAnimation;
GameObject go = new GameObject("NewSprite");
go.AddComponent<tk2dSprite>();
tk2dSpriteAnimator animator = go.AddComponent<tk2dSpriteAnimator>();
animator.Library = library;
animator.Play("ClipName");
-
Ah ha! Ok, I think I was putting a "Sprite with Animator" in my resources folder, not the "Sprite Animation" library. Took me a while to figure out the difference between Collections, Animations, Sprites, and Sprite Animators.
In case someone else gets stuck, here's some help:
- Create a Sprite Collection: http://www.unikronsoftware.com/2dtoolkit/docs/2.00/tutorial/creating_a_sprite_collection.html
- Create a Sprite Animation (Library): http://www.unikronsoftware.com/2dtoolkit/docs/2.00/tutorial/creating_a_sprite_animation.html
- Drag that Sprite Animation Library into your Resources folder. Then the code above will work.
- ...
- Profit!
Much thanks for the speedy reply!