Hello Guest

Author Topic: Anchoring to a percentage of the screen  (Read 3497 times)

AurayStudios

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 6
    • View Profile
    • Auray Studios
Anchoring to a percentage of the screen
« on: May 24, 2014, 10:47:16 am »
Hi,

I've been trying to anchor UI items to a percentage of the screen rather than a fixed offset from the anchor, and cannot figure out if there is an easy way to do this in tk2d. I explain what I'm trying to accomplish with an image:



The 4 buttons are anchored "Middle Center", and I'm positioning them through code at the percentage proportions in the image. What I'm wondering is: is there a way to accomplish this using the anchoring system?

The 2 corner buttons are easy to place using "Lower Right" and "Lower Left" anchors. What I'm having trouble with are the 2 middle buttons, that should be at 1/3 of the offset of the corner buttons. I calculate this 1/3 offset through code and place them, but it's not a good solution, as I cannot check the layout for other resolutions by changing the preview resolution, only by hitting play in Unity for every resolution.
« Last Edit: May 24, 2014, 10:53:43 am by WarmFeetStudios »
Auray Studios: We create fun, engaging experiences that help groups grow together through social interaction.

Check out our latest work at www.auraystudios.com

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Anchoring to a percentage of the screen
« Reply #1 on: May 24, 2014, 10:16:07 pm »
Use a tk2dUILayout to lay out your items in there.
Have 2 tk2dUI camera anchors positioned at the top left and bottom right. Write a script, and get the world positions of these 2 objects and call layout.SetBounds(minAnchorPosition, maxAnchorPosition).

That should scale a lot better.