Hello Guest

Author Topic: How can I change the anim in a tk2dAnimatedSprite?  (Read 3876 times)

kliqingk

  • Newbie
  • *
  • Posts: 14
    • View Profile
How can I change the anim in a tk2dAnimatedSprite?
« on: May 24, 2013, 09:29:56 am »
Hey:
    I created a tk2dAnimatedSprite with the function Instantiate.  How can I change the anim in the instance?

    public tk2dAnimatedSprite prefab;
    tk2dAnimatedSprite temp = Instantiate(prefab, new Vector3(0,0,0), Quaternion.identity) as tk2dAnimatedSprite;

    Then I want to use another tk2dSpriteAnimation instead of the default. How to do it?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: How can I change the anim in a tk2dAnimatedSprite?
« Reply #1 on: May 24, 2013, 04:31:59 pm »
temp.anim = newAnim; // load using resources.load, etc.

in tk2d 2.0 - we've changed it to be a bit more sensible.
temp.Library = newAnimLibrary; // again load in using resources.load.

You can also play clips without setting the library -
temp.Play( newAnim.GetClipByName("clipname") );

 

kliqingk

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: How can I change the anim in a tk2dAnimatedSprite?
« Reply #2 on: May 27, 2013, 03:23:33 am »
How to using resources.load?

temp.anim = Resources.Load("SpriteAnimationName", typeof(tk2dSpriteAnimation));

There is an error : Cannot implicityly convert type 'UnityEngine.Object' to 'tk2dSpriteAnimation'.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: How can I change the anim in a tk2dAnimatedSprite?
« Reply #3 on: May 27, 2013, 11:38:28 am »
Resources.Load returns a UnityEngine.Object, simply cast to tk2dSpriteAnimation.

temp.anim = Resources.Load("SpriteAnimationName", typeof(tk2dSpriteAnimation)) as tk2dSpriteAnimation;
http://docs.unity3d.com/Documentation/ScriptReference/Resources.Load.html

Don't forget that the sprite animation must be in a resources folder for this to work.