Hello Guest

Author Topic: Is it possible to assign a clip to a class property?  (Read 3393 times)

LaserDinosaur

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 38
    • View Profile
Is it possible to assign a clip to a class property?
« on: May 17, 2014, 09:58:08 pm »
Hi all

I have a script called "Health" which just does some general health tracking on the game object. It also has a method inside it called "Killed()", which fires when the health drops below 1. My plan was to have a class property which takes a Clip from the tk2d animator and then play it. The problem is there doesn't seem to be a property that allows me to just assign a Clip to a script.

I had a look at the Mole tutorial and it appears in there they have a game object which contains a tk2d sprite animator (for the dust animation), then they instantiate that game object whenever they need an animation. I guess this would work, but it seems a little redundant to have a collection of clips in my animation collection (ie. Running, Jumping, Dying), but then have to create a second set of prefabs also called Running, Jumping, Dying, which are instantiated as needed.

Can clips be chosen directly as class properties? If not, is creating a list of matching prefabs and animation clips the best way to go? Is there a cleaner way to do this?

Cheers!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Is it possible to assign a clip to a class property?
« Reply #1 on: May 18, 2014, 06:44:52 pm »
Clips can't be referenced outside the animation collection, but it is a serializable class. You should be able to copy it into your class if you want. Alternatively, you can store the reference to an animation collection + clip index. That is what the sprite animator does.

LaserDinosaur

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 38
    • View Profile
Re: Is it possible to assign a clip to a class property?
« Reply #2 on: May 19, 2014, 06:25:45 am »
Sorry to be a dummy, but what do you mean by animation collection being a serializable class? I have a rough idea of what a serializable class is, but I'm not sure how it would help.  :o

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Is it possible to assign a clip to a class property?
« Reply #3 on: May 19, 2014, 11:17:25 am »
What I meant is that you can store the data locally to your class instead of having to be in the animation collection. The simplest option is to just store the index into the animation collection. You can use tk2dSpriteAnimator.GetClipIdByName to do that, and at runtime you can get the clip by using GetClipById.