2D Toolkit Forum

2D Toolkit => Support => Topic started by: destro on April 19, 2013, 06:01:01 pm

Title: Sequencing Sprite Animations in Javascript/unityscript
Post by: destro 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?
Title: Re: Sequencing Sprite Animations in Javascript/unityscript
Post by: unikronsoftware 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;

Title: Re: Sequencing Sprite Animations in Javascript/unityscript
Post by: destro 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

Title: Re: Sequencing Sprite Animations in Javascript/unityscript
Post by: unikronsoftware 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.