Author Topic: Resizing while keeping aspect ratio  (Read 2104 times)

Ana

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 28
    • View Profile
Resizing while keeping aspect ratio
« on: April 26, 2014, 05:48:21 PM »
I have a background image that I want to resize to fill the screen while keeping its aspect ratio. The image needs to be centered on the screen, but here is where it gets tricky:
I want the image to always fill the screen completely, screen should have no parts that are not covered by the image.
If I use aspect ratio constrain by width or height while anchoring to sides, I can only achieve it filling the screen in certain resolutions.
I draw a quick picture of how it is supposed to behave, it is in the attachment.

How would I do this in NGUI?

EDIT:
I created two versions of the background, one is restrained by width the other is by height. Then I check the aspect ratio of the screen and activate one of them that would be appropriate for that aspect ratio. That solves the problem.
Does NGUI have an included way to solve this or should I stick to my solution?
« Last Edit: April 26, 2014, 06:41:22 PM by Ana »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Resizing while keeping aspect ratio
« Reply #1 on: April 27, 2014, 11:26:59 PM »
You seem to be overcomplicating the task. Write a script that will simply scale the image based on either the width or the height.