2D Toolkit Forum
2D Toolkit => Support => Topic started by: kliqingk 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?
-
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") );
-
How to using resources.load?
temp.anim = Resources.Load("SpriteAnimationName", typeof(tk2dSpriteAnimation));
There is an error : Cannot implicityly convert type 'UnityEngine.Object' to 'tk2dSpriteAnimation'.
-
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.