Author Topic: Strange behavior with advanced anchors  (Read 16597 times)

MoProductions

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 45
    • View Profile
Strange behavior with advanced anchors
« on: July 21, 2017, 01:05:29 PM »
We're sorting out our multiple aspect ratio issues and came across a weird effect of anchors. I've set up a simplified scene to show off exactly what the issue is so don't mind the Atari 2600 looking art.
The scene is a rectangular blue widget (Menubar) with two square widgets (Pink, Dark Blue) anchored to it's sides.  There's also a white rectangle which represents where these objects are supposed are supposed to be for this aspect ratio, so when the scene starts the Menubar widget's size and transform's position get set via copying the values from the white rectangle, then the anchors are supposed to take care of the two side objects.  We need those two objects on the side to always be anchored to the sides and remain square. 



The way I set up the Pink anchor is I anchored it's left side to the Menubar left, it's top and bottom to Menubar top and bottom, then left the right anchor blank and set the Aspect value on the widget to be Based on Height, which gave me what I needed.



I did the same thing for the Dark Blue but anchored the right instead of left. As you can see in the image above, it looks fine, and changing aspect ratios in the editor looks fine as well.  The issues begin when the scene actually starts or gets loaded at runtime (I've tested this on devices as well).  What's happening is that while the squares end up where they are supposed to be, they don't snap there right away like all the other anchors I've used (and i've used plenty heh).  What happens is that it animates into position over about a half a second. Not much, but certainly noticeable.  The only thing I can think of that's causing it is that missing anchor, because when I anchor all sides to Dark Blue, it doesn't give me the position I need but it does happen automatically.



I've taken a video of what happens when i start the scene and as you can see the Dark Blue square snaps immediately but to the wrong spot, while the Pink square goes to the right spot it just animates. Neither one is what we're looking for.

https://www.youtube.com/watch?v=77P9P8e1v0g&feature=youtu.be

So what I'm wondering is either a) how to get the behavior we need another way or b) stop the animation part for happening.

Any help appreciated!  Thanks!
-Mike

MoProductions

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 45
    • View Profile
Re: Strange behavior with advanced anchors
« Reply #1 on: July 21, 2017, 01:45:08 PM »
UPDATE: So my boss took a look and figured out that to stop the Pink widget from animating, you set it's anchor to left.  And for the right side Dark Blue widget set the anchor to right.  I'm not exactly sure why this works but we're going with it for now.  Is there reason why this works?  Seems like a good op to learn more about the nuts 'n bolts of NGUI.
Thanks!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Strange behavior with advanced anchors
« Reply #2 on: July 22, 2017, 02:56:33 PM »
If you want something to anchor to the left, set it to left. Kind of obvious, so I don't think I understood your last post properly... I'm glad you got it working though.

MoProductions

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 45
    • View Profile
Re: Strange behavior with advanced anchors
« Reply #3 on: July 25, 2017, 07:32:51 AM »
Well the question was why does the object animate to it's position when it's not set to left justify.  We got the issue solved but we're not sure why.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Strange behavior with advanced anchors
« Reply #4 on: August 03, 2017, 03:34:24 AM »
Probably due to the order of updates, such as being anchored to a widget that effectively moves due to anchor updates of its own.

See this post for a full explanation: http://www.tasharen.com/forum/index.php?topic=15398.msg67070#msg67070
« Last Edit: August 03, 2017, 04:07:01 AM by ArenMook »