Hello Guest

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - astrobread

Pages: [1]
1
Support / One SpriteAnimation as template for multiple sprites
« on: August 04, 2014, 05:19:22 pm »
I have several items the player can wear, and each have a spritesheet so they can shift around properly during the walk animation. I loaded all the spritesheets into one SpriteCollection, and then was faced with the task of making a walk animation for each and every one.

Instead, I made a single animation prefab and then wrote a script to repurpose it for every item.

So my question based on researching similar posts: is there a reason I should be using Resources.Load instead of tk2dSpriteAnimation.Instantiate? Are there any other potential issues using this method? Thanks!

Code: [Select]
tk2dSpriteAnimator theAnimator = gameObject.AddComponent<tk2dSpriteAnimator>();
theAnimator.Library = (tk2dSpriteAnimation)tk2dSpriteAnimation.Instantiate(genericAnimationPrefab);
for (int i = 0; i < theAnimator.Library.clips.Length; i++)
{
   for (int j = 0; j < theAnimator.Library.clips[i].frames.Length; j++)
   {
      int oldId = theAnimator.Library.clips[i].frames[j].spriteId;
      int newId = TransformOldIdToNewId(oldId); // pseudo-code placeholder function
      theAnimator.Library.clips[i].frames[j].spriteId = newId;
   }
}

Pages: [1]