2D Toolkit Forum
2D Toolkit => Support => Topic started by: tenpn on July 18, 2014, 08:10:38 pm
-
I'm trying to make some production-quality UI with tk2d and struggling a bit.
I like the anchoring of the layout containers very much, but I'm struggling to do simple stuff like centering and aligning element.
For instance, I have a large panel, with a background sliced sprite. Inside that panel is a button, with a UI item at the top level. With the UI item, the button's anchor is in the top right:
https://www.dropbox.com/s/c78x2in3pfbck8d/Screenshot%202014-07-18%2020.08.55.png
I want this button to be central to the containing panel. Because of where the anchor is, I can't just child the button to the panel and set the X value to 0. I have to just do it by hand.
I'm not expecting Keynote-levels of alignment snapping, but is there some way for me to line this up reliably? Am I missing something?
Cheers.
-
We've never needed aligning things like that regularly, so we never made a shortcut for it. I think we've made something like that once, but since we always have a controller script sitting on the base, we simply positioned it in the center using that...
If you want an automated way to do this, you can place invisible/empty uiItems on either side, set to expand to fill, i.e. 2 proportional ones, and one fixed size thing in the middle. Its not ideal but it does work.
-
Can you go into more details on your first paragraph? I'm not quite following. What does your usual object hierarchy look like? How does that help you center objects?
-
We usually have a controller behaviour to control a message box / dialog box or whatever it is we're building. All the controls are a child of this gameobject, and we simple code some stuff in the behaviour to position the problematic children.