4
\$\begingroup\$

I'm trying to place a button on the bottom right corner of the screen, so I tried to put all the Anchor parameters in the inspector to the value "End" but the position still needs to be specified relative to the top-left corner. If I try changing the margins in the inspector it kind of works but then I have to change all four margins taking into account the size.

enter image description here enter image description here enter image description here

\$\endgroup\$
  • \$\begingroup\$ The position vector is always related to the top left corner of it's parent node, at least for control nodes as i know. The margins are the way to set the "position" relative to the pivot.. However, are you trying to set position programmatically? If not, simply select your control and then go to Layout > Bottom Right. If you want to change only the anchors after you've found a nice position for you control go to Layout > Anchors Only > Bottom right \$\endgroup\$ – LookForAngular Nov 11 '18 at 23:29
0
\$\begingroup\$

Having a Node2D with a Button in it you need this code.

extends Node2D


func _ready():
    var v:Vector2 = get_viewport().size
    $Button.rect_position = v - $Button.rect_size

This does not look clean as the button is squeezed into the bottom right not looking great. It's better to put it in ie a MarginContainer and then move that bottom right. It's Custom constants margins can be set manually.

extends Node2D


func _ready():
    var v:Vector2 = get_viewport().size
    var m:MarginContainer = $MarginContainer

    m.rect_position = v - m.rect_size

Hope this was useful :-)

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.