2D Toolkit Forum
2D Toolkit => Support => Topic started 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?
-
Where did you get stuck? The JS syntax is really straightforward -
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;
-
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
-
This is pretty much how you do that.
animSprite.animationCompleteDelegate = function (sprite : tk2dAnimatedSprite, clipId : int) {
Debug.Log("Complete");
}
The code to chain stuff is almost identical.