Author Topic: Square sprite which scales with resolution  (Read 2634 times)

mslinklater

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Square sprite which scales with resolution
« on: March 02, 2014, 06:20:33 PM »
Hi - I'm pretty new to NGUI so forgive me if this is a no-brainer.

What I want to do is have a sprite which grows as the screen resolution changes, but which maintains it's own aspect ratio even if the aspect ratio of the screen changes.

I've played with the anchor settings and can't seem to find the correct way of achieving this. I either have a sprite which maintains it's own aspect ratio but doesn't resize with the screen, or a sprite which grows with the screen while having it's own aspect ratio modified.

To put this in to context I want a square icon which is 5% of screen width in both width and height. This sprite needs to be anchored to the top-left of the screen.

Is this possible with NGUI ? And how do I set up the anchors (or whatever) to make it work.

Thanks for any help/pointers you can give.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Square sprite which scales with resolution
« Reply #1 on: March 02, 2014, 09:44:11 PM »
If you wanted a fixed size sprite:

Unified Anchor
0. Ideally change sprite's pivot to top-left.
1. Left to Target's Left.
2. Right to Target's Left.
3. Bottom to Target's Top.
4. Top to Target's Top.

If you wanted a sprite that remains at 5% of the screen's height and remains a square:

Advanced Anchor
0. Ideally change sprite's pivot to top-left.
1. Left to Target's Left
2. Right should not be anchored (leave blank).
3. Bottom to Custom, 0.95 for the relative value (first box), 0 for the absolute (2nd box).
4. Top to Target's Top.
5. Aspect Ratio of 1, BasedOnHeight.

mslinklater

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: Square sprite which scales with resolution
« Reply #2 on: March 03, 2014, 04:49:48 AM »
Thank you so much - that works great. The bit I was missing was constraining the aspect ratio.

 :D