Author Topic: Problems with UI positioning  (Read 7912 times)

Disastercake

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 87
  • www.disastercake.com
    • View Profile
    • Disastercake
Problems with UI positioning
« on: May 24, 2012, 02:45:56 PM »
I'm brand new to NGUI and Unity, and am attempting to make a main menu mock up and am having issues with the GUI buttons not scaling with the rest of my game properly.

I am using 2DToolkit to place a sprite of Soul Saga's logo in the middle of the screen, and would like NGUI to make the buttons underneath it.  However, when doing this, if the camera size or resolution changes, the NGUI buttons do not scale the same as the logo.  How would I fix this?

Attached are examples of how the menu looks under different view port settings (and not changing anything else with positioning code.)

Thanks!
Creator of Soul Saga.
http://www.disastercake.com

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Problems with UI positioning
« Reply #1 on: May 24, 2012, 02:48:28 PM »
UIRoot - set 'automatic' to be off, and choose your target resolution. The buttons will then scale proportionally with the screen's height, thus staying in one place. A pixel-perfect solution would instead be to position them using a relative offset instead (UIAnchor, play with the relative setting).

Also you can use UITexture to draw that background. You don't need the 2D Toolkit.

Disastercake

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 87
  • www.disastercake.com
    • View Profile
    • Disastercake
Re: Problems with UI positioning
« Reply #2 on: May 24, 2012, 04:00:06 PM »
When I change the automatic to off, it technically does what I need it to.

However, 2D Toolkit keeps the graphics crisp at the higher resolution, while the NGUI buttons get very pixelated and fuzzy.

How would I fix this issue?  Would this be by using the offset? 

I've attached an example.
« Last Edit: May 24, 2012, 04:03:25 PM by Disastercake »
Creator of Soul Saga.
http://www.disastercake.com

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Problems with UI positioning
« Reply #3 on: May 24, 2012, 04:01:31 PM »
You need to start with a higher-res font. That font has a fixed size, and is meant to remain at that size to look perfect. Scaling it up blurs it.

Same goes for the UI. Stretching anything means it won't look pixel-perfect anymore. it's just less noticeable with your background image.

Disastercake

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 87
  • www.disastercake.com
    • View Profile
    • Disastercake
Re: Problems with UI positioning
« Reply #4 on: May 24, 2012, 04:03:31 PM »
Do I have to script the offset to change depending on the resolution the player has chosen?
Creator of Soul Saga.
http://www.disastercake.com

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Problems with UI positioning
« Reply #5 on: May 24, 2012, 09:30:56 PM »
You can just set a relative position offset on the UIAnchor.