Hello Guest

Author Topic: Change clip Id SpriteAnimator at runtime  (Read 5624 times)

Tina

  • Newbie
  • *
  • Posts: 4
    • View Profile
Change clip Id SpriteAnimator at runtime
« on: June 19, 2013, 10:54:12 pm »
Hi,

I'm currently working in a 2d game in the newest version of the 2d toolkit and I would like to know how to change the clip Id of the Sprite Animator at runtime?
I mean, I have five different collections each one with different sprites. I also have a Sprite Animator for each collection and inside of my Sprite Animator I have two different clips.
When the game start automatically runs the first animation, but I need that at runtime when some variables change my animation also changes to the second one.
How can I do that? I hope to have been clear with my explication.

Thanks  ;)

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Change clip Id SpriteAnimator at runtime
« Reply #1 on: June 20, 2013, 11:04:55 am »
Hi,

You don't change the clip id - you simply call .Play( newClip ) to play the clip you want. If you need to switch libraries - then do this:
anim.Library = newLibrary (you need a reference somehow, using Resources.Load, etc)
then call
anim.Play("clipName") to play the new clip.

OlivieL

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • OlivierLouet
Re: Change clip Id SpriteAnimator at runtime
« Reply #2 on: December 10, 2013, 06:29:52 pm »
private List<tk2dSpriteAnimator> ListPortraitsAnimator;
public tk2dSpriteAnimation   newLibraryPortraitAnimations;
void OnGUI(){
ListPortraitsAnimator = new List<tk2dSpriteAnimator>();
GameObject portrait = Util.FindChild(this.gameObject, "Portrait");      
GameObject obj = (GameObject)Instantiate(portrait);                 
obj.name = "Portrait_PnjApelle";
obj.transform.parent = this.gameObject.transform;
obj.transform.localPosition = Vector3.zero;
tk2dSpriteAnimator portraitAnimator = obj.GetComponent<tk2dSpriteAnimator>();
//Here
portraitAnimator.Library = newLibraryPortraitAnimations;
//Here
ListPortraitsAnimator.Add(portraitAnimator);
tk2dSpriteAnimationClip clip = portraitAnimator.GetClipByName("Bulle2Dialogue_quest_Empty");
obj.SetActive(true);
}

It’s work ! thx
 ;D
Made one games "Akhiris"