Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: no-tec on January 21, 2014, 12:53:31 AM

Title: Animating from one anchor to another?
Post by: no-tec 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.
Title: Re: Animating from one anchor to another?
Post by: ArenMook 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.
Title: Re: Animating from one anchor to another?
Post by: no-tec 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?
Title: Re: Animating from one anchor to another?
Post by: ArenMook 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.
Title: Re: Animating from one anchor to another?
Post by: no-tec 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.
Title: Re: Animating from one anchor to another?
Post by: ArenMook 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.
Title: Re: Animating from one anchor to another?
Post by: no-tec 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!
Title: Re: Animating from one anchor to another?
Post by: ArenMook 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).