Hello Guest

Author Topic: Is it possible to create an animation via code?  (Read 10051 times)

shaz68

  • Newbie
  • *
  • Posts: 19
    • View Profile
Is it possible to create an animation via code?
« on: February 22, 2012, 10:26:25 pm »
This post has been really helpful, but I'm wondering if I can take it further.  Is it possible to create the anim via code - selecting the sprite collection, setting up the clips, listing the frames for each clip?  I had a go, but I got as far as not being able to create a tk2dSpriteAnimation using new because it's a MonoBehaviour and needs to be attached as a component.  At this point, I'm trying to create the animation so I can attach it to objects as a component.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Is it possible to create an animation via code?
« Reply #1 on: February 22, 2012, 10:47:17 pm »
No it isn't currently possible (well it is, really, but its a massive pain). This is the first time someone has asked for this - how important would you rate it, and what kind of situations would you use it in?

shaz68

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Is it possible to create an animation via code?
« Reply #2 on: February 22, 2012, 11:52:32 pm »
I have 30 different animations to make, but they all use exactly the same sized spritesheets, in exactly the same layout.  Making them manually is incredibly tedious, and if I make a mistake (which I've done), I have to do them over again.  If I could do it in code, it would be a matter of incrementing a couple of variables for each one and calling the same function.

For me, it would be a huge time saver.  Whether it would make a different to project size and performance (both very important) would also have to be taken into account.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Is it possible to create an animation via code?
« Reply #3 on: February 23, 2012, 10:11:07 am »
I have attached an editor script which will do just this. You can extend this to do what you need.
Hope it helps!

Let me know if it does what you need it to, I will put this in the FAQs (no one has asked for it before, but its got a useful code snippet in there)

shaz68

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Is it possible to create an animation via code?
« Reply #4 on: February 23, 2012, 09:18:08 pm »
thank you.  I will look at this today and let you know how it goes :)

db82

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Is it possible to create an animation via code?
« Reply #5 on: March 07, 2012, 03:32:58 pm »
Hi

Just purchased 2D Toolkit and impressed so far!

But I am in a similar position, I need to create 9 Sprite Animation objects which are all identical, only difference is each one uses a different Sprite Collection.

Would be great if we could duplicate a Sprite Animation and set (or drag onto it) a Sprite Collection to auto update the frames!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Is it possible to create an animation via code?
« Reply #6 on: March 07, 2012, 06:18:32 pm »
Hi,

I have a revamp of the interface in the pipeline, but that wont be in the next 1 or 2 releases. In the mean time, I suggest taking a look at the solution I posted 2 posts up, you can basically create your sprite animation in code from it - that way you can batch create all 8 or any others you need to as well.

Hope it helps