Author Topic: Tween Between Anchor Positions  (Read 5748 times)

pfranza

  • Guest
Tween Between Anchor Positions
« on: June 26, 2013, 08:58:35 AM »
I have been looking for a solution for a little while and everything I find just seems a little bit to weird so I'm not sure I'm thinking about it correctly.

I have a panel that is anchored to the top-left, and I want to be able to temporarily tween the position so that it slides to the center of the screen (and potentially back to its original position)

I've been trying to do the calculations using the panel offsets but always seem to be wrong when using different screen resolutions. 

Is there a best practice for attacking this problem?  Does anybody have a code snippet they could share?

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Tween Between Anchor Positions
« Reply #1 on: June 26, 2013, 10:48:16 AM »
I think the easiest would be to look into the UIAnchor code and use the way it is calculating positions to calculate the target for your tween, instead of using actual UIAnchors.

tripclaw

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: Tween Between Anchor Positions
« Reply #2 on: June 26, 2013, 02:31:14 PM »
I think you could just add a child to the anchor, the child should have UILagPosition, and then everything else becomes a child of that. Then just set the anchor to Top, Center, etc. and it should "tween" there using the LagPosition...


Malzbier

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 93
    • View Profile
Re: Tween Between Anchor Positions
« Reply #3 on: June 27, 2013, 02:36:40 AM »
For a slide out menu i created a script that uses 2 empty gamobject with anchor for getting the proper slided in and out positions.

Just tween between the position between the position of though gamobjects.

At start i did set the position delayed by one frame to one of the gamobjects positions.