Author Topic: Problem using anchors (not the legacy component)  (Read 7207 times)

1337GameDev

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 13
    • View Profile
Problem using anchors (not the legacy component)
« on: July 24, 2015, 05:33:41 PM »
I have a project and want to anchor some gui elements to the screen.

I have a simple hierarchy:
-MinimapPanel 
     -Panel-minimap
         -Sprites and NGUI elements
     -Panel-largemap
         -Sprites and NGUI elements

I want "Panel-minimap" to be anchored to the top left of the screen (with the target set to "MinimapPanel").
I set the anchor of "Panel-minimap" to Unified (after setting the clipping to "No Clip but constrain") and have the following anchor settings:
Left: Right
Right: Right
Top: Top
Bottom: Top

And tested it to see that it doesn't update it's position if the window size changes (I set it up to Execute on update).

Why doesn't it seem to anchor and move?

I have attached some screenshots of my scene and hierarchy.

The last 3 attachments are of "MinimapPanel" and a problem I have, where setting any clipping causes the purple "bounding box" to disappear and a very negative number with a yellow line to appear.

What does this mean?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Problem using anchors (not the legacy component)
« Reply #1 on: July 27, 2015, 08:04:54 PM »
I'm confused... you say you want the minimap to be anchored to top-left of the screen, then proceed to anchor it to top-right? Also why even have this panel at all if you are not clipping anything? Lastly it's generally a good idea to anchor widgets, not panels. A panel can be a child of an invisible widget (ALT+SHIFT+W), it will work better this way.

P.S. You forgot the attachments.

1337GameDev

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 13
    • View Profile
Re: Problem using anchors (not the legacy component)
« Reply #2 on: July 27, 2015, 09:02:56 PM »
 :-\   I remember uploading them. This forum seems to remove them all the time for me. Very frustrating.

And I want my minimap in the top right. Was a typo. My bad.

And I should create an invisible widget that is the size of my parent panel?
I haven't used the invisible widget workaround before, so how would that all work for scaling and anchoring? Wouldn't THAT widget need to be anchored? And what if I want to "organize" my widgets to seperate seperate menus, and still have them anchored?


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Problem using anchors (not the legacy component)
« Reply #3 on: July 27, 2015, 09:08:30 PM »
The widget doesn't need to be the size of your parent. It's just there to handle being anchored to top-right. This way the panel underneath it doesn't need to be anchored (only positioned beforehand), which makes it work better. You can use a parent game object with a UIAnchor on it instead of using a UIWidget if you like, but it's the same thing.

1337GameDev

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 13
    • View Profile
Re: Problem using anchors (not the legacy component)
« Reply #4 on: July 30, 2015, 10:54:36 AM »
Alright, I will attempt that. Thanks for the advice on this issue, I greatly appreciate it!  :D

I'll try and stay away from legacy components to avoid future problems and possible deprecations in the future.

1337GameDev

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 13
    • View Profile
Re: Problem using anchors (not the legacy component)
« Reply #5 on: July 31, 2015, 12:04:33 AM »
I tried it, and it seems to only move when the screen has changed in dimensions equal to the width of the minimap.

EG: The minimap is x pixels wide. The minimap doesn't move if I resize the window, except when it is a multiple of x pixels, and then the minimap snaps to the edge of the screen. This also doesn't stay correctly positioned, as when I hit play, the other elements don't line up if it's not a multiple of x pixels wide.

Here's my setup.
In the hierarchy picture, "Panel" is my single UI panel for clipping reasons. Then, I have the invisible widget (name as TopRight) as a child of that, anchored to the top right corner of "Panel", with my other widgets as children of the invisible widget, position at the corner of the screen.

Then, if I resize my window it doesn't move until it is x (the width of the minimap sprite) pixels smaller, the minimap snaps to the corner where it's supposed to be anchored.

How can I make it constantly move with the corner and stay anchored? :/
I also noticed that when positioning, I couldn't drag it nicely where I wanted, and it would "snap" around as if to a grid, and not free floating. I had to enter decimals to position the minimap widgets.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Problem using anchors (not the legacy component)
« Reply #6 on: July 31, 2015, 10:05:27 PM »
Make sure your anchor is set to update OnUpdate, and that the panel isn't marked as static. Static panels don't track widget position changes.