Author Topic: NGUI not scaling to different mobile resolutions  (Read 8939 times)

CazicThule

  • Guest
NGUI not scaling to different mobile resolutions
« on: February 25, 2013, 03:01:51 PM »
I've set up some sprites and sliders which appear in the correct position when running in the editor, but when I run on my device they do not scale down to fit the screen. I thought NGUI handled this automatically? Is there something I need to specify?

It seems to position them correctly on the Y axis, but does not scale for the X axis. I'm running in portrait mode on the device.

I've tried various UIRoot settings, I'm currently using FixedSize/640/320/1536.
« Last Edit: February 25, 2013, 03:17:58 PM by CazicThule »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: NGUI not scaling to different mobile resolutions
« Reply #1 on: February 25, 2013, 06:15:21 PM »
Fixed Size UIRoot means the UI will always remain the same size proportional to the height -- which sounds like what you want. Pixel Perfect means the UI will remain the same size in pixels. Meaning a 300x200 window is going to be huge on a 320x240 screen, and tiny on a 1920x1200 screen.

If you need things to be attached to side of the screen, use anchors. There is a wealth of information on how to use them, including the very first example in NGUI + video tutorial specifically for that purpose.

BjoernMXM

  • Guest
Re: NGUI not scaling to different mobile resolutions
« Reply #2 on: November 08, 2013, 04:38:56 AM »
Unfortunatly, this does not answer the question for me.

I do use FixedSize, but if I load the app on my android tablet, it does not scale down the elements to fit the screen. I got a simple sprite for example at the bottom right(with an UIAnchor) with company logo and some lines of text. In Portrait Mode, the sprite does not scale down, to fit the screen. Some parts of the sprite went off screen, when switching to portrait mode.

Does anyone know why it does not scale automatically to fit the screen size?

Thanks!

kind regard,

bjoern

EDIT: Maybe i should add, that die POSITION of all sprites are correct(according to the anchor setup), the problem is the scaling of the sprites!
« Last Edit: November 08, 2013, 04:51:49 AM by BjoernMXM »

JeongHo Eom

  • Guest
Re: NGUI not scaling to different mobile resolutions
« Reply #3 on: November 08, 2013, 06:33:22 AM »
If you use the 2D camera.
You can consider this snippet.

      if (UICamera.mainCamera && Screen.height > 0){
         var orgRatio = 1280f / 720f;
         var ratio = (float)Screen.width / (float)Screen.height;
         if (ratio > 0)
         {
            UICamera.mainCamera.backgroundColor = Color.black;
            UICamera.mainCamera.orthographicSize = orgRatio / ratio;
         }
      }

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: NGUI not scaling to different mobile resolutions
« Reply #4 on: November 09, 2013, 10:28:37 AM »
Scaling is based on the height, so if your aspect changes (like if you switch from landscape to portrait) it won't fit anymore. You'll have to set up two different manual heights for each, that you can switch between.