Hello Guest

Author Topic: Handling GUI positioning between different resolutions  (Read 4336 times)

arvz

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 21
    • View Profile
Handling GUI positioning between different resolutions
« on: May 24, 2014, 11:16:25 am »
Hey,

I'm making a game for tablet/phones which means handling all sorts of different resolutions. In the game, players get 3 lives which are indicated by 3 symbols in the top left corner.

I want these life symbols to always be a set amount of distance from the top and set amount of distance from the left.

Is there a nice way to do this that will work for arbitrary resolutions? I've tried a couple of different methods including a separate camera for GUI elements only, and using camera overrides, it won't work for all resolutions. Also looked into using tk2dlayout but can't really see how it would help me.

I'd appreciate it if you could point me in the right direction

Thanks

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Handling GUI positioning between different resolutions
« Reply #1 on: May 24, 2014, 10:05:24 pm »
You can use the tk2dCameraAnchor to anchor things to the camera. If you just need it to be at specific locations, that will be the easiest option.

arvz

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Handling GUI positioning between different resolutions
« Reply #2 on: May 25, 2014, 05:55:46 am »
Thanks, just playing around with tk2dCameraAnchor currently. I have a GameObject parent that parents all 3 of the symbols, and put the tk2dCameraAnchor component on that object, however its Z-axis keeps getting completely messed up, at first it stays at the exact same Z position as the camera I point it to, but when I start the game the Z position gets smaller and smaller and smaller very fast.

Am I doing something wrong?

edit: Got it to work, but just as a side note: I realised when I add a tk2dCameraAnchor manually as a script component on an existing GameObject, the 'Offset' and 'To Native Bounds' option do not appear.
These options appear if I go to GameObject > Create Other > TK2D > Camera Anchor.  What is going on there?
« Last Edit: May 25, 2014, 06:17:27 am by arvz »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Handling GUI positioning between different resolutions
« Reply #3 on: May 25, 2014, 05:08:14 pm »
The camera behaves differently when attached to a tk2dCamera (the anchor camera field). If you add the component you'll need to make sure it is wired up properly.