2D Toolkit Forum

2D Toolkit => Support => Topic started by: partyson on June 12, 2013, 07:24:22 am

Title: How to load a v2 Sprite Animation in C#
Post 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!
Title: Re: How to load a v2 Sprite Animation in C#
Post by: unikronsoftware on June 12, 2013, 09:46:06 am
Here you go

Code: [Select]
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");
Title: Re: How to load a v2 Sprite Animation in C#
Post by: partyson on June 15, 2013, 11:12:09 pm
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:
Much thanks for the speedy reply!