Author Topic: Question on Anchor Setups vs. Screen Ratios Scaling Issue  (Read 3958 times)

blitzer

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 52
    • View Profile
Question on Anchor Setups vs. Screen Ratios Scaling Issue
« on: February 05, 2015, 05:37:03 AM »
Hello everyone, I'm having some trouble understanding why in my case, two different elements with the same type of Anchor setup are being adjusted dramatically differently (see below).

In Detail:
I'm working with a Constrained UI Root set to 960x640 with both "Fit" boxes set to false. I've got 2 elements (To Battle, and Options) that use the same style of anchoring to anchor them to an element that encompasses the viewable screen. What I'm seeing when a change to a different screen setup (in this case from a iphone screen to an ipad screen), the To Battle element behaves as expected, but the Options element becomes very small, and I can't figure out why.

The Images:
Before and After simply show how the screen is setup, then what it looks like after the screen switch has been made (notice To Battle slightly adjusting as expected, but Options becoming very small even though it anchors itself as To Battle does).

Additionally, I'm noticing that it seems NGUI needs "some time" to adjust the elements (updating after "Play" is pressed after changing screen size/ratio. What I'm seeing this that after Play is stopped, some elements seem to move back towards where they started, and I have to press Play 3 or 4 times to get the elements to stay in their proper new position. If there is anything I can do to avoid this, please let me know.

As always, any ideas are appreciated, thank you for reading.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Question on Anchor Setups vs. Screen Ratios Scaling Issue
« Reply #1 on: February 05, 2015, 10:24:45 AM »
You are only anchoring right and bottom sides. Left and top aren't anchored, meaning they will stay exactly where you left them. You need to anchor left and top sides as well if you want the sprite to keep its size.

Left to right, right to right, bottom to bottom, top to bottom.

blitzer

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 52
    • View Profile
Re: Question on Anchor Setups vs. Screen Ratios Scaling Issue
« Reply #2 on: February 06, 2015, 04:10:49 AM »
I should have explained this better:

What I'm looking for is a behavior where compressing a "wide screen" ratio to a more standard ratio, in which each sub-element maintains its own shape, but becomes relatively smaller because your are loosing horizontal width (and I've tried "Fit" but that will not allow the elements to shrink).

You can see this happen on the other "To Battle" element. It also only has 2 anchors, but when the screen ratio changes, it becomes smaller (but still holds its shape). This is what I'm trying to get out of the "Options" element, but I can't get it to work.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Question on Anchor Setups vs. Screen Ratios Scaling Issue
« Reply #3 on: February 06, 2015, 09:50:37 PM »
Right but you are basing your sprite's aspect ratio on width... yet only the left side is anchored. Right is not. Meaning the sprite's height is based on something that isn't anchored properly. You need to use relative anchors for left/right. Anchor bottom, but leave top not anchored. To re-iterate: 3 sites should be anchored using relative anchors. 4th side will be calculated using the aspect ratio.

Don't use "left", "right", etc. Use Custom and specify a relative 0-1 range value. 0.25 means 25% from the left for example. That's relative anchoring.

blitzer

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 52
    • View Profile
Re: Question on Anchor Setups vs. Screen Ratios Scaling Issue
« Reply #4 on: February 06, 2015, 10:59:34 PM »
With your help, I think I've got it working now using 2 set anchors (left/bottom anchors), because I want the sides a set distance from the edges of the screen and Relative would end up putting it in the wrong position when the ratio changes. And 1 Relative (the right anchor).

I could swear I tried this before, but I'm guessing that in my frustration, I probably forgot to hit "Play" and let NGUI adjust the elements. Is there any way to avoid that (the second or two NGUI takes to adjust elements after a screen change)? Or am I better off just hiding it with a loading screen or something similar?

Thank you again, I always appreciate the help.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Question on Anchor Setups vs. Screen Ratios Scaling Issue
« Reply #5 on: February 08, 2015, 11:33:19 PM »
You can broadcast "UpdateAnchors" to have them update immediately. NGUITools.ImmediatelyCreateDrawCalls() is also a useful function. That said, the "second or two" delay after hitting Play has nothing to do with NGUI, and is due to Unity unloading/loading things. Transitioning from Edit mode to Play mode takes time.

blitzer

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 52
    • View Profile
Re: Question on Anchor Setups vs. Screen Ratios Scaling Issue
« Reply #6 on: February 11, 2015, 04:33:12 AM »
That said, the "second or two" delay after hitting Play has nothing to do with NGUI, and is due to Unity unloading/loading things. Transitioning from Edit mode to Play mode takes time.

->Just to be clear, I didn't mean that "Unity Editor dead time", I was referring to (after doing something like changing screen ratios), the NGUI elements will "crawl" across the screen until they settle in their new location. That being said I have tried using the different update anchor modes, and they all seem to be behaving the same way (Am I using them incorrectly?). I also tried "ImmediatelyCreateDrawCalls" which didn't seem to make any difference (although, again, its probably me misusing the method).

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Question on Anchor Setups vs. Screen Ratios Scaling Issue
« Reply #7 on: February 11, 2015, 09:29:50 PM »
Sounds like it's an issue with how you had them set up. Try the Example 0 that comes with NGUI. It features a lot of anchors, and they all update immediately.

blitzer

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 52
    • View Profile
Re: Question on Anchor Setups vs. Screen Ratios Scaling Issue
« Reply #8 on: February 13, 2015, 05:22:04 AM »
"Sounds like it's an issue with how you had them set up."
-> Seems to be, as you say, your example happens instantly.