Author Topic: Stretched header question  (Read 1878 times)

Enki

  • Guest
Stretched header question
« on: June 18, 2013, 09:11:02 AM »
I have a full screen header ui consisting of 3 parts which are stretched to form one bar across the entire screen.

Root
  Camera
    Panel
      GameObject (empty holder)
        Left Bar (sprite, anchor, stretch)
        Etc.
Stretch is set to occupy ~30% of screen. Anchor is left, center, right for each part. Final bar looks good.
What I can't seem to figure out, is how to place labels on each part, which will remain proportionate with their respective bar chunk. I've tried all the obvious answers and they only seem to result in goofy output.
What's the proper way?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Stretched header question
« Reply #1 on: June 18, 2013, 12:14:38 PM »
Instead of anchoring to left and right, change the anchor point to be 0.1667 and (1 - 1.667), respectively (assuming the size is actually 33%, not 30%? If it's 30% then it should be 15% and 85%, respectively).

Your anchor should also be on an empty game object, not on the sprite. The stretch script can remain on the sprite.

Set up like this, you can then add a label to your game object, and it too will be centered within your 30% cell.

Enki

  • Guest
Re: Stretched header question
« Reply #2 on: June 18, 2013, 06:44:02 PM »
Beautiful, thank you. They aren't all equal, that's why I said ~30%. Easy math though, now that I understand  :)