Author Topic: Smooth transition between two different anchored positions  (Read 5192 times)

Seizon

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Smooth transition between two different anchored positions
« on: February 18, 2014, 10:19:09 AM »
Hi!
I'm currently working a lot with NGUI, and I seem to be running into the same problem over an over, so I decided that I better ask for some help.

Right now I'm making a minimap, which is square and sitting in top right corner without margin, and it's achored to the UIRoot like this:
Left -> Right
Right -> Right
Bottom -> Top
Top -> Top

Idea is for the minimap to enlarge into a large centered version, which is anchored to the UIRoot like this:
Left -> Center
Right -> Center
Bottom -> Center
Top -> Top

I got both positions down, and their anchor settings + the screen height calculation, in order to size it properly.
How can I best make a smooth transition between these two positions, which has different anchor settings? :)

Any help would be greatly appreciated!

Cheers,
Seizon

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Smooth transition between two different anchored positions
« Reply #1 on: February 18, 2014, 10:30:57 AM »
Well, you know where you want the widget to be when it starts -- top-right, so right and top of 0, left and bottom of -width and -height, respectively. You also know the width and height of your screen (Screen.width, etc), which lets you calculate half of that, so TweenPosition to that location should be trivial. You can switch the anchor afterwards, or just leave them top-right -- it doesn't matter much.

Seizon

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: Smooth transition between two different anchored positions
« Reply #2 on: February 18, 2014, 10:34:57 AM »
Seems logical! Thanks. :)
Bonus question: This will handle the whole moving the texture, but what about the resizing? Since it should slowly become larger, as it moves towards the center.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Smooth transition between two different anchored positions
« Reply #3 on: February 18, 2014, 10:50:27 AM »
TweenWidth, TweenHeight.

Seizon

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: Smooth transition between two different anchored positions
« Reply #4 on: February 19, 2014, 07:40:58 AM »
Thanks for the previous help. Decided to just keep the anchors in one place, as that seemed the logical thing to do.
New problem has popped up.
I do this:
  1.         TweenPosition.Begin(gameObject, 1f, -screenMiddle + transform.localPosition + new Vector3(MinimapTexture.width/2, MinimapTexture.height/2));
  2.                 TweenHeight.Begin(MinimapTexture, 1f, Screen.height - margin);

Which works fine until it finishes. The position stays, but the size does not, so it resizes itself to its original size when it's done. I'm guessing this is due to the fact that TweenPosition updates anchors as well, so this overrides the size?
Can you lend me a hand, once again? :)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Smooth transition between two different anchored positions
« Reply #5 on: February 19, 2014, 02:23:29 PM »
3.5.0 will feature anchors being updated by width and height changes. I should release it sometime later today.

Seizon

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: Smooth transition between two different anchored positions
« Reply #6 on: February 20, 2014, 03:14:20 AM »
Awesome, can't wait. :)
Thanks for the response.