Hello Guest

Author Topic: Sequencing Sprite Animations in Javascript/unityscript  (Read 4237 times)

destro

  • Newbie
  • *
  • Posts: 5
    • View Profile
Sequencing Sprite Animations in Javascript/unityscript
« on: April 19, 2013, 06:01:01 pm »
Hi
I can't figure out how to sequence animation using javascript
i tried convert script from demo scene but i failed :/
i want to play one animation in loop after mouse click play another animation one and after that another loop, how to do that?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Sequencing Sprite Animations in Javascript/unityscript
« Reply #1 on: April 19, 2013, 11:23:08 pm »
Where did you get stuck? The JS syntax is really straightforward -

Code: [Select]


function TestFunc(sprite : tk2dAnimatedSprite, clip : tk2dSpriteAnimationClip, frame : tk2dSpriteAnimationFrame, frameNum : int)
{
Debug.Log("Hello");
}

function TestComplete(sprite : tk2dAnimatedSprite, clipId : int) {
    Debug.Log("Complete");
}

// elsewhere in your code, maybe in Start
animSprite.animationEventDelegate = TestFunc;
animSprite.animationCompleteDelegate = TestComplete;

« Last Edit: April 19, 2013, 11:24:50 pm by unikron »

destro

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Sequencing Sprite Animations in Javascript/unityscript
« Reply #2 on: April 24, 2013, 03:05:44 am »
thanks for reply but how to use it to sequence animation?  in demo scene there is something like this

         animSprite.Play("demo_once");
         animSprite.animationCompleteDelegate = delegate(tk2dAnimatedSprite sprite, int clipId)
            {
               animSprite.Play("demo_pingpong");
               animSprite.animationCompleteDelegate = null;
            };


how do this in javascript, i manage to make animations work using functions for every clip, with additional variables to control which animation is playing and  which should play next and also checking "if (animSprite.IsPlaying ..." to play in update function but its dirty and clunky in so many ways, it should be very simple but i missing something


unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Sequencing Sprite Animations in Javascript/unityscript
« Reply #3 on: April 24, 2013, 11:43:10 am »
This is pretty much how you do that.

Code: [Select]
animSprite.animationCompleteDelegate = function (sprite : tk2dAnimatedSprite, clipId : int) {
    Debug.Log("Complete");
}

The code to chain stuff is almost identical.