Demigiant Forum
Unity Assets => DOTween & DOTween Pro => Topic started by: amigueloferreira on October 29, 2015, 01:10:00 PM
-
Hi,
Loving DOTween so far, really great product.
I've been having some trouble figuring out how to correctly kill an infinite loop sequence. If I just kill it, even with the complete parameter set to true, the tween just suddenly stops.
What I wanted was to basically prevent any future loops on the sequence, and kill it only after a full loop has completed.
Is there any simple way to this without having to resort to sequence callback tricks?
Regards,
-
Hi!
Uhmmm you could use a trick there. Instead of making an infinite loop, make a single loop tween, with autoKill set to false and an OnComplete callback that tells it to restart when it's complete. Then, when you want to "smooth kill it", set its autoKill to false, and its OnComplete to null. Didn't test it but it should definitely work.
Cheers,
Daniele
-
P.S. sample code (again, didn't test it but it should be ok):
Tween myTween;
void CreateTween()
{
myTween = image.DOColor(myColor, 1).SetAutoKill(false);
myTween.OnComplete(myTween.Restart);
}
void SmoothKillTween()
{
myTween.OnComplete(null);
myTween.SetAutoKill(true);
}
-
I like this
Tween myTween;
void CreateTween()
{
myTween = image.DOColor(myColor, 1).SetAutoKill(false);
myTween.OnComplete(myTween.Restart);
}
void SmoothKillTween()
{
myTween.OnComplete(null);
myTween.SetAutoKill(true);
}
But it returns an error: cannot convert from method group to TweenCallback, i think you should use something like
myTween.OnComplete(()=>myTween.Restart());
And...still ,why not something like this?:
Tween myTween;
void CreateTween()
{
myTween = image.DOColor(myColor, 1).SetLoops(-1,LoopType.Restart);
}
void SmoothKillTween()
{
myTween.SetLoops(0);
myTween.Complete();
myTween.Kill(); //?
}
-
You're right about the TweenCallback, I forgot that Restart has overloads, so it requires to be a lambda.
void SmoothKillTween()
{
myTween.SetLoops(0);
myTween.Complete();
myTween.Kill(); //?
}
This won't work, because you're simply forcing the tween to complete instantly. With the method I wrote instead, you're telling the tween to go on playing until the end of the loop, and then it will kill itself automatically (which sounds creepy written like this :D).
-
I see, how about just setting the loops to 0?
-
That would "crop" the tween and complete it immediately, since it would find itself at a bigger loop than it currently is. Also, SetLoops has no effects once a tween has already started.
-
Oh, ok, thanks for this