2D Toolkit Forum
2D Toolkit => Support => Topic started by: AurayStudios 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:
(http://i1370.photobucket.com/albums/ag276/AurayStudios/Untitled_zps1864d0dc.png)
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.
-
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.