Author Topic: Animating from one anchor to another?  (Read 4447 times)

no-tec

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
Animating from one anchor to another?
« on: January 21, 2014, 12:53:31 AM »
I'm trying to animate an element from one side of the screen to the other, for example Anchor left side of screen to Anchor right side of screen, is this possible with NGUI somehow? I can easily anchor left then animate 500px to the right, but I would like it to work the same way on all resolutions.

Thanks for the help.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Animating from one anchor to another?
« Reply #1 on: January 21, 2014, 01:05:33 AM »
Knowing the "to" position, start a tween (TweenPosition.Begin) to go there. You can't do it from inspector, but it's pretty much one line of code.

no-tec

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: Animating from one anchor to another?
« Reply #2 on: January 23, 2014, 02:32:08 AM »
Correct. How do I know where the 'to' position is with an anchor though? Since the anchor is already setting the 'from' position and you can only set one anchor. Or am I overlooking something?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Animating from one anchor to another?
« Reply #3 on: January 23, 2014, 05:25:12 AM »
Anchors simply change the position of a widget. Widget has a position, so that would be your "to" position.

no-tec

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: Animating from one anchor to another?
« Reply #4 on: January 23, 2014, 01:29:47 PM »
Correct, I understand you can use the anchor to set the to position, but then how do I set the 'from' position? For example, if I want the animation to go from the right anchored side of the screen [regardless of resolution] to the left side of the anchored screen, how could I accomplish that?

Thanks again for the help ArenMook.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Animating from one anchor to another?
« Reply #5 on: January 24, 2014, 08:50:55 AM »
The "from" position is always set automatically using the current position of the object you're tweening.

no-tec

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 7
    • View Profile
Re: Animating from one anchor to another?
« Reply #6 on: January 28, 2014, 11:45:44 PM »
Correct, but that's based on a static positioning, right?

So how would I create an animation to go from one anchor positioning to another anchor's positioning?
I guess I need guidance on how that would look in the code, since the inspector can only house one anchor positioning from the animation widget.

Thanks for the help!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Animating from one anchor to another?
« Reply #7 on: January 29, 2014, 09:48:55 AM »
Anchors simply modify the object's position and rectangle. If you're trying to animate positions, just tween it from point A to point B, where point A is one object's position, and B is another. The only tricky thing is that TweenPosition is based on local position, so the two objects must be siblings. That, and both A and B need to be local coordinates as well (transform.localPosition).