Author Topic: UITweener.Play Implementation Question  (Read 2486 times)

Ferazel

  • Full Member
  • ***
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 150
    • View Profile
UITweener.Play Implementation Question
« on: April 16, 2014, 05:39:39 PM »
Hi Aren,

We're using your tween library a lot in our game, which seems to be working pretty well except for a situation that occurs sometimes. When we are using a tween's PlayForward and PlayReverse we sometimes run into situations where the mFactor not being reset when calling PlayForward or PlayReverse would cause the tweens to sometimes not play because the first update would think that it is already done. This would occur in situations where you call PlayForward and then call PlayForward again. It would not start from the beginning but rather just immediately terminate.

Is there a reason why the UITweener's mFactor is not reset in the Play() method like so?
  1. public void Play (bool forward)
  2. {
  3.         mAmountPerDelta = Mathf.Abs(amountPerDelta);
  4.         if (!forward) mAmountPerDelta = -mAmountPerDelta;
  5.         mFactor = (mAmountPerDelta < 0f) ? 1f : 0f; //NEW CODE HERE
  6.         enabled = true;
  7.         Update();
  8. }
  9.  

Without that I found us doing things like this which ended up rather ugly.
  1. mTweenVisible.PlayForward(); //Need to put the delta amount in the correct direction
  2. mTweenVisible.ResetToBeginning(); //Reset the mFactor
  3. mTweenVisible.PlayForward(); //Now play through correctly
  4.  

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UITweener.Play Implementation Question
« Reply #1 on: April 17, 2014, 11:06:40 AM »
What if you were playing a tween forward, then halfway there would call the PlayReverse function? In your case it would immediately warp to the end instead of continuing from where it is, just reversing the direction. If you want to reset it, calling the ResetToBeginning first is the right way to go. I'm not sure why you are calling PlayForward twice. Once is enough.

Isamson

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 52
    • View Profile
Re: UITweener.Play Implementation Question
« Reply #2 on: May 01, 2014, 01:32:13 PM »
I'm having a similar problem with a tween. 2 things can happen with this tween:

1. The tween slides in (from -> to) then is called later to slide out (to -> from)
2. The tween slides in (from -> to) but is not called in reverse. It is later called to slide in again (from -> to)

The problem I have is that resetToBeginning doesn't help me at all since I don't know in which direction is finished.

Could you create a resetToBeginning(Bool forward) where the tween would be automatically reset to play either forward or in reverse?

Edit: I got help from a coder, but it would be nice to see this feature added. Here is the code:
  1.     public void ResetToBeginning (bool forward)
  2.     {
  3.         mStarted = false;
  4.         mFactor = forward ? 0f : 1f;
  5.         Sample(mFactor, false);
  6.     }
« Last Edit: May 01, 2014, 01:42:01 PM by Isamson »
Unity 4.5.3f
NGUI 3.7.0

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UITweener.Play Implementation Question
« Reply #3 on: May 02, 2014, 08:26:04 AM »
Use PlayForward() / PlayReverse(). Set the OnFinished to trigger PlayReverse() and everything should work as expected without any modifications.