Author Topic: Scale, but keep aspect ratio  (Read 10429 times)

kork

  • Guest
Scale, but keep aspect ratio
« on: April 24, 2012, 02:39:08 AM »
Hi,

in our game we have a background image that we want to use as a backdrop for the main menu. The native size is 1280x1024 (5:4).  I'd like this image to fill the height of the screen, but keep its aspect ratio (with the camera's background color pillarboxing the image).  I built the following UI Tree:

* UI Root
** Camera
*** Anchor (Center)
**** Panel
***** UISprite (Pixel Perfect)

I tried attaching a UIAnchor to the UISprite and ticking the  "Stretch to fill" checkbox. This streched the image across the screen, but did not preserve the aspect ratio. So how would I achieve this in NGUI?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Scale, but keep aspect ratio
« Reply #1 on: April 24, 2012, 02:43:20 AM »
Stretch to Fill option is long gone. Update to the latest version of NGUI and use the UIStretch script. It has an option to stretch based on height only.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Scale, but keep aspect ratio
« Reply #2 on: April 24, 2012, 02:43:46 AM »
Oh right, you have the free version... Free version isn't supported, it comes as-is. :)

kork

  • Guest
Re: Scale, but keep aspect ratio
« Reply #3 on: April 24, 2012, 02:44:50 AM »
Hmm I see there are significant differences between the free version and the full version. So i guess using the free version for evaluation purposes is probably not a good idea.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Scale, but keep aspect ratio
« Reply #4 on: April 24, 2012, 02:48:13 AM »
Free version was released over 2 months ago. I've kept updating NGUI since then -- quite a lot actually. All the changes are backwards compatible -- ie: UIs you make in the free version will still work in the latest version... but I obviously can't do the opposite and support an old version that has had many, many improvements and bug fixes.

kork

  • Guest
Re: Scale, but keep aspect ratio
« Reply #5 on: April 24, 2012, 02:54:07 AM »
Yap, perfectly understandable. Thanks for the quick replies. I just buy the full version now, and see how far it gets me :)

kork

  • Guest
Re: Scale, but keep aspect ratio
« Reply #6 on: April 24, 2012, 03:09:22 AM »
Got it working with the full version. Just for the sake of completeness, I've attached a screenshot on how to do it, in case someone else stumbles upon it. The important part is to put the aspect ratio into the "relative size" fields, otherwise the thing will get stretched.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Scale, but keep aspect ratio
« Reply #7 on: April 24, 2012, 03:10:38 AM »
Yup :)

kork

  • Guest
Re: Scale, but keep aspect ratio
« Reply #8 on: April 24, 2012, 03:23:47 AM »
Great work btw. Doing this was a nightmare with iGUI/EZGui and just a few clicks with NGUI :) I already like it.