*

amigueloferreira

  • *
  • 1
  • jxrge was here
    • View Profile
How to smoothly kill an infinite loop sequence
« 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,


*

Daniele

  • Dr. Admin, I presume
  • *****
  • 378
    • View Profile
    • Demigiant
Re: How to smoothly kill an infinite loop sequence
« Reply #1 on: October 29, 2015, 08:39:16 PM »
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

*

Daniele

  • Dr. Admin, I presume
  • *****
  • 378
    • View Profile
    • Demigiant
Re: How to smoothly kill an infinite loop sequence
« Reply #2 on: October 30, 2015, 08:03:30 PM »
P.S. sample code (again, didn't test it but it should be ok):

Code: [Select]
Tween myTween;

void CreateTween()
{
   myTween = image.DOColor(myColor, 1).SetAutoKill(false);
   myTween.OnComplete(myTween.Restart);
}

void SmoothKillTween()
{
   myTween.OnComplete(null);
   myTween.SetAutoKill(true);
}

Re: How to smoothly kill an infinite loop sequence
« Reply #3 on: November 23, 2015, 11:04:54 AM »
I like this

Code: [Select]
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
Code: [Select]
   myTween.OnComplete(()=>myTween.Restart());

And...still ,why not something like this?:
Code: [Select]
Tween myTween;

void CreateTween()
{
  myTween = image.DOColor(myColor, 1).SetLoops(-1,LoopType.Restart);
}

void SmoothKillTween()
{
   myTween.SetLoops(0);
   myTween.Complete();
   myTween.Kill(); //?
}

*

Daniele

  • Dr. Admin, I presume
  • *****
  • 378
    • View Profile
    • Demigiant
Re: How to smoothly kill an infinite loop sequence
« Reply #4 on: November 23, 2015, 12:04:35 PM »
You're right about the TweenCallback, I forgot that Restart has overloads, so it requires to be a lambda.

Code: [Select]
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).

Re: How to smoothly kill an infinite loop sequence
« Reply #5 on: November 23, 2015, 12:20:21 PM »
I see, how about just setting the loops to 0?

*

Daniele

  • Dr. Admin, I presume
  • *****
  • 378
    • View Profile
    • Demigiant
Re: How to smoothly kill an infinite loop sequence
« Reply #6 on: November 23, 2015, 12:47:24 PM »
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.

Re: How to smoothly kill an infinite loop sequence
« Reply #7 on: November 23, 2015, 01:18:16 PM »
Oh, ok, thanks for this