Author Topic: TweenPosition duration -1  (Read 4138 times)

nah0y

  • Sr. Member
  • ****
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 430
  • \o/
    • View Profile
TweenPosition duration -1
« on: August 14, 2012, 11:00:51 AM »
Hi,

In some version, you've added the possibility to set a negative time (-1 for example) to a duration of a TweenPosition so that the effect is done instantly when receiving an event.

But as you can see in the video below, there is some latency between the button change sprite (using ImageButton) and the label going down (using TweenPosition).
Are you sure that having a negative duration is instantly triggered ?

http://www.youtube.com/watch?v=0S_XZxvHBrk

Thanks !

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TweenPosition duration -1
« Reply #1 on: August 14, 2012, 03:24:31 PM »
UITweener's Begin function:
  1. if (duration <= 0f)
  2. {
  3.         comp.Sample(1f, true);
  4.         comp.enabled = false;
  5. }
Keep in mind that sprites get updated in LateUpdate, so depending on where you trigger the Begin function from, it may or may not happen on the same frame.

nah0y

  • Sr. Member
  • ****
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 430
  • \o/
    • View Profile
Re: TweenPosition duration -1
« Reply #2 on: August 14, 2012, 03:41:26 PM »
Hum OK that makes sense but if I want everything on the same frame I should do the calls in LateUpdate
I just have to set a bool and read it in the LateUpdate ?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TweenPosition duration -1
« Reply #3 on: August 14, 2012, 03:48:44 PM »
Late update may or may not be called before panel's late update, which rebuilds the geometry, so I suggest making sure that everything you do happens in normal update instead.

nah0y

  • Sr. Member
  • ****
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 430
  • \o/
    • View Profile
Re: TweenPosition duration -1
« Reply #4 on: August 14, 2012, 04:07:05 PM »
Okay so instead of doing things in OnPress and OnClick I should do that in Update.

(Just for confirmation)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TweenPosition duration -1
« Reply #5 on: August 15, 2012, 02:13:07 AM »
OnPress and OnClick are called from Update as well. UICamera.Update to be precise. If you want to force a rebuild the same frame, use UIPanel.Refresh().

nah0y

  • Sr. Member
  • ****
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 430
  • \o/
    • View Profile
Re: TweenPosition duration -1
« Reply #6 on: August 16, 2012, 03:43:48 AM »
Yes but that requires that every object in the scene that has OnPress or OnClick have a reference to the UIPanel they're inside.

Is there a quick things to do that ? Like widget.getPanel() ? or do I have to declare it public and pass it through the Inspector every time ?

nah0y

  • Sr. Member
  • ****
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 430
  • \o/
    • View Profile
Re: TweenPosition duration -1
« Reply #7 on: August 16, 2012, 05:27:39 AM »
Or I could just use :

  1. NGUITools.FindInParents<UIPanel>(this.gameObject);

Last question though, should I call this before or after doing my stuff (Play Tweens etc...) on the OnPress ?
I suppose it's after, but want to make sure.

nah0y

  • Sr. Member
  • ****
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 430
  • \o/
    • View Profile
Re: TweenPosition duration -1
« Reply #8 on: August 16, 2012, 05:30:57 AM »
Also, calling UIPanel.Refresh "trigger" a TweenPosition script because it broadcast the "Update"... so what should we do about that ?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TweenPosition duration -1
« Reply #9 on: August 16, 2012, 10:23:03 AM »
Before the tween.

Is there any particular reason why you need to use a tween for this? I mean, you are doing an instant transition after all. So why not just transition yourself by doing whatever it is the tween is supposed to do instantly? Set the position, set the color... whatever it is.

nah0y

  • Sr. Member
  • ****
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 430
  • \o/
    • View Profile
Re: TweenPosition duration -1
« Reply #10 on: August 16, 2012, 11:08:25 AM »
Hum... the reason is because there is a script that I can easily configure through the inspector to do that.
But omg you're f****g right, I could just create some simple script of mine to do that...