Author Topic: New Anchor system- need some help regarding scaling  (Read 3792 times)

puneetk

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 8
    • View Profile
New Anchor system- need some help regarding scaling
« on: November 01, 2014, 10:40:41 AM »
Hi guys,

I just recently updated to NGUI 3.7.5 from the free version which I used in a previous project to try out. I really loved it and that's why I just bought the latest one.

I was trying to place a UI2Dsprite, exactly at 30% of the height from the top of the panel, and exactly in the center of the Screen's X axis (left -50%)
This was very easy with the old anchoring system, but the new system seems to keep scaling my UISprite2D every time I change the slider values from 0-1 or the number next to the '+' sign. And If I set it to something that's acceptable to me, when I change the screen resolution, the sprite moves to the wrong position.

Is there any way to do this in the new system?

Also in the new anchor system, what does the slider of 0-1 mean? I read the docs but that isn't clear enough to me.
Same for the number next to the '+' sign.

Thanks

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: New Anchor system- need some help regarding scaling
« Reply #1 on: November 02, 2014, 03:21:03 AM »
0 to 1 is the relative position. For example taking horizontal placement, 0 means left, 1 means right, 0.5 means center, 0.25 is 25% from the left, etc. The other number is simply added to this calculated value. So if it's 100, it means it's whatever the calculated value is plus 100 pixels.

If you don't want something to resize, anchor both sides to the same side. For example, left to left, right to left. This will make them both stick to the left side of the target widget, and prevent resizing.

puneetk

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 8
    • View Profile
Re: New Anchor system- need some help regarding scaling
« Reply #2 on: November 03, 2014, 02:59:58 PM »
Hi, thanks. I guess I kind of figured this out through trial and error.

Just a question though, is there a drawback to using the old anchoring system? In some cases where I want scale, I find the new one much easier but in other cases where all I want to do is anchor to the screen, this new system easily turns into a mess.
ESPECIALLY for UILABELS

I still have not been able to place my labels properly the way I want to with the new anchors. If I have 2 labels one called 'Score' and other called 'High Scores' and want to place them exactly under eachother in a line, I can't do that. Setting the horizontal position for both to say 0.10 does not align them - even if both are anchored to left.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: New Anchor system- need some help regarding scaling
« Reply #3 on: November 04, 2014, 09:50:11 AM »
Anchoring to screen is trivial. Just anchor to the UI camera. You can still use the old system if you wish though.

Relative positions are just that -- relative to whatever you are anchoring them to. 0.1 means 10%. This 10% will vary depending on the size of the screen. 10% of 640x480 is very different from 10% of 1920x1080.

Keep it simple. If you want something on the left side, anchor it to the left. Set the relative to 0 (or stick to Left instead of Custom to begin with!), then give it a pixel-based offset. If the first label is 100 pixels wide, second label would have the same offset +100. Simple, no?