Hello Guest

Author Topic: How to load a v2 Sprite Animation in C#  (Read 4276 times)

partyson

  • Newbie
  • *
  • Posts: 2
    • View Profile
How to load a v2 Sprite Animation in C#
« 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!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: How to load a v2 Sprite Animation in C#
« Reply #1 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");

partyson

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: How to load a v2 Sprite Animation in C#
« Reply #2 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!