Author Topic: Tween with zero Duration stays in "Playing" mode?  (Read 4727 times)

jgodfrey

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
Tween with zero Duration stays in "Playing" mode?
« on: January 06, 2014, 05:47:47 PM »
I have several a tweens (specifically, TweenTransforms) with 0 duration (these used to have positive durations, but I'm testing something).  I noticed that when the zero-duration tweens are played using UIPlayTween, they don't seem to shift out of playing mode on their own (even though they're set to PlayStyle = Once).  In UIPlayTween, I had to set "If already playing" to "Restart" in order to use them multiple times.

Is that expected?  Is setting a tween's duration to 0 considered valid? 

BTW, I'm not sure how to verify the version of NGUI I'm running, though it's only a week or two old.

Thanks,

Jeff


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tween with zero Duration stays in "Playing" mode?
« Reply #1 on: January 06, 2014, 09:35:40 PM »
Try adding this to the end of UITweener.Update function:
  1. // Disable the tween if the duration is zero
  2. if (duration == 0f) enabled = false;

jgodfrey

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: Tween with zero Duration stays in "Playing" mode?
« Reply #2 on: January 06, 2014, 09:48:10 PM »
Thanks for the input.  I've added the code and I assume it should take care of the problem.  I'll try to set up a test case soon to verify that.

While I was in there though, I wonder if the "onFinished" delegate will get properly called in the zero-duration case or if it might need an adjustment also?

Jeff

jgodfrey

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: Tween with zero Duration stays in "Playing" mode?
« Reply #3 on: January 06, 2014, 09:51:30 PM »
Try adding this to the end of UITweener.Update function:
  1. // Disable the tween if the duration is zero
  2. if (duration == 0f) enabled = false;

In addition to the above comments... Are you OK with the "duration == 0f"?  I'm just always leery of testing for equality with non-integer values.

Jeff

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tween with zero Duration stays in "Playing" mode?
« Reply #4 on: January 06, 2014, 09:52:58 PM »
Yes, zero comparison is just fine in this case. Epsilon float comparison is only needed when there are calculations involved. Setting the value directly is not an issue.

I suggest changing the end of that function to the following btw:
  1. // If the factor goes out of range and this is a one-time tweening operation, disable the script
  2.                 if ((style == Style.Once) && (duration == 0f || mFactor > 1f || mFactor < 0f))
  3.                 {
  4.                         mFactor = Mathf.Clamp01(mFactor);
  5.                         Sample(mFactor, true);
  6.  
  7.                         current = this;
  8.  
  9.                         // Notify the listener delegates
  10.                         EventDelegate.Execute(onFinished);
  11.  
  12.                         // Deprecated legacy functionality support
  13.                         if (eventReceiver != null && !string.IsNullOrEmpty(callWhenFinished))
  14.                                 eventReceiver.SendMessage(callWhenFinished, this, SendMessageOptions.DontRequireReceiver);
  15.  
  16.                         current = null;
  17.  
  18.                         // Disable this script unless the function calls above changed something
  19.                         if (duration == 0f || (mFactor == 1f && mAmountPerDelta > 0f || mFactor == 0f && mAmountPerDelta < 0f))
  20.                                 enabled = false;
  21.                 }
  22.                 else Sample(mFactor, false);

jgodfrey

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: Tween with zero Duration stays in "Playing" mode?
« Reply #5 on: January 06, 2014, 09:56:28 PM »
Thanks.  Yeah, I like that better as the onFinished delegate should fire correctly now.

I'll update my code.  I guess I'd expect this to be rolled into the release at some point?

Jeff

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tween with zero Duration stays in "Playing" mode?
« Reply #6 on: January 06, 2014, 09:57:04 PM »
Yup.

jgodfrey

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: Tween with zero Duration stays in "Playing" mode?
« Reply #7 on: January 06, 2014, 09:59:09 PM »
Perfect - thanks for the great support!

Jeff