Author Topic: Relative Anchors - Positionning Problems  (Read 4014 times)

RDeluxe

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 18
    • View Profile
Relative Anchors - Positionning Problems
« on: May 30, 2014, 06:02:41 AM »
Hi ! I'm posting this here, I guess it's the best place to ask.

I have some troubles getting how relatives anchor are working. It seems that there is a UI problem when using "Advanced" anchors. After setting a relative anchor, it will become a "normal" one with a arbitrary value as soon as I test the game. It seems to work though, but I don't really get why the UI does not show the relative field again.

Another problem that I have is that relative anchor behavior is strange. I set the left anchor of a button at 71% (0.71) of the UIRoot, and the bottom anchor of the same button at 15% (0.15).

Here is what I got with a 16/9 resolution : http://i.imgur.com/OhrSEY3.jpg
Here is what I got with a 4/3 resolution : http://i.imgur.com/zR35vpd.jpg

I don't quite understand why ...

I find it quite difficult to manage the scale of my buttons (resizing them depending on the screen height, i'm using a UIStrech for this) + having relative anchors.
All this was done by code in Javascript (using Gameclosure), positionning was based on the screen size and a fixed value (representing the original position, with the maximum resolution). All I want here is my button to change its size and position. I guess I'll have to use custom scripts to handle that correctly.


Another question : is it not possible to anchor the center of an object to the center of another one ? I'm asking this because my buttons are composed of 2 layers, the "cover" and the background. I want to background to be slightly smaller (92% of the cover), and for this i'm using a UIStrech script. But as I need to anchor the background to the cover, my anchors value are changing all the time and gaps appear. Would be simpler if I could just anchor their centers.
« Last Edit: May 30, 2014, 11:32:23 AM by RDeluxe »

RDeluxe

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 18
    • View Profile
Re: Anchors - Streching
« Reply #1 on: May 30, 2014, 07:27:00 AM »
Well, first thing first : I think I'm stupid.

Using a FixedSize UIRoot allows me to avoid all my UIStrech call, and to set the sizes I want in my "original template", with a nice an smooth resize.

Second thing : this should NOT be in the last tutorial of the serie. Multiplatform developpers will be gratefull :D

I still have some positionning problems, but I guess I will be able to fix them with the same method.

I still would like to use relative (% size of parents) values for the anchors though.

Edit : Well, the problem is that the anchor values do not scale like the rest (size values for example). Plus, the relative anchor size is definitely doing weird things. I will try to explain my problem in a clearer way.

Here is what I want :
- Cutting the background depending of the resolution and resize it correctly. I managed this using a UI2DSprite with UIStrech script attached which force the picture to respect its original ratio :
 

- Now I would like to position my two buttons like this :


The problem is that the anchor size between my 2 buttons seems fixed : I'm not sure it is resizing considering the UIRoot FixedSize property. It seems to be resizing correctly ! Yeah!
And the relative anchors are not working so well (or I don't use them correctly), as you can see here:



I was trying to use a 0.73 relative anchor on my left button. But using "0" did not move my button. Is it just an UI problem, or something that I don't quite get correctly ?


tl:dr : Seems that my anchor value between my 2 buttons is working correctly (the distance seems to scale nicely). But the problem with my "fixed" anchor on the left button (to fix its x position) is that when the ratio is changing (4/3 >> 16/9) it does not work correctly. I have to use a percentage here.
« Last Edit: May 30, 2014, 11:49:58 AM by RDeluxe »

RDeluxe

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 18
    • View Profile
Re: Relative Anchors - Positionning Problems
« Reply #2 on: May 30, 2014, 12:07:32 PM »
Eureka.

I had to set both the Left and Right anchor to specific values :



Left : 1 and Right : 0 <<<< Middle of the screen
Left : 1 and Right : 0.44 <<< 0.72 of the screen, 72% !

I watched all the tutorials and read the documentations, this behavior is not quite obvious and deserves (in my opinion) a better description !


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Relative Anchors - Positionning Problems
« Reply #3 on: May 30, 2014, 03:39:15 PM »
"Target's Left" and "Target's Right" are both Horizontal values. "Left" simply means '0', and "Right" means '1'. Center is '0.5'. They are all written out for convenience, making it easier to understand what's going on. When you turn on "Custom" anchoring, you can specify the relative value yourself, and it's not limited to 0, 0.5, or 1.0. You can set it to any value you like. For example 0.75 means 25% from the right side.

Never use UIStretch when using the new anchoring system. UIStretch is a legacy component.

yo_milo

  • Newbie
  • *
  • Thank You
  • -Given: 10
  • -Receive: 2
  • Posts: 36
    • View Profile
Re: Relative Anchors - Positionning Problems
« Reply #4 on: March 08, 2015, 07:24:46 PM »
I agree with RDeluxe... The naming is not obvious... Maybe changing "Custom" to "Relative" will do the trick... because I was going crazy (and about to use a UIStretch script), until I found this thread....