Hello Guest

Author Topic: Fitting button to screen height  (Read 4354 times)

beardkey

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 10
    • View Profile
Fitting button to screen height
« on: August 21, 2013, 09:43:45 pm »
A few quick questions (hopefully) somewhat involving Demo Scene 11 - Camera and Alignment.

1) With the background image, how is it being scaled without scaling the border of the image? I can't seem to figure out what's doing that, or where I can read up on it.

2) Let's say I need two buttons, one on top of the other, maybe with a background or without, which ever is easier. I'd like them to take up the left 10% of the screen at any resolution, stretching from top to bottom. Using camera anchors I can get them to sit in the top left of the screen but I can't seem to find the best way to stretch them without it messing up the text as well (which I would like to remain readable). Any ideas?

Thanks!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Fitting button to screen height
« Reply #1 on: August 21, 2013, 10:24:20 pm »
1. What background are you talking about here? The magenta box or the gradient?

2. Not so easy in the current version of 2D Toolkit, but 2D Toolkit 2.2 adds layout (http://unikronsoftware.com/2dtoolkit/doc/2.20/ui/basic_layout.html), which allows you to resize items nicely. The rules set up on the layout object will be used to resize / reposition sprites and textmeshes.
There is also a layout container sizer http://unikronsoftware.com/2dtoolkit/doc/2.20/ui/advanced_layout.html which will let you specify percentages for controls, etc.

Leaving you with one problem specifically - how to position the layout item to fit the screen. And this is pretty straightforward if you use the tk2dCamera, you simply set bounds on the layout item to
Vector3(tk2dCamera.Instance.ScreenExtents.xMin, tk2dCamera.Instance.ScreenExtents.yMin, 0),
Vector3(tk2dCamera.Instance.ScreenExtents.xMax, tk2dCamera.Instance.ScreenExtents.yMax, 0)

beardkey

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Fitting button to screen height
« Reply #2 on: August 21, 2013, 10:29:04 pm »
Ah! Sorry. I meant the magenta box with the instructions in it.

Edit: Doh, it looks like it's because it's a Sliced Sprite. I totally missed that it wasn't just a normal sprite. Sweet, onward and upward. I'll give your suggestions a try, thanks!
« Last Edit: August 22, 2013, 03:26:05 am by beardkey »