#Trying to understand anchors

3 messages · Page 1 of 1 (latest)

wise cobalt
#

I've been managing to do what I originally wanted to do - but I think it's the wrong way. I've used a simple script on my hbox

`extends HBoxContainer

func _ready() -> void:
resized.connect(_on_resized)
define_anchors()

func _on_resized():
define_anchors()

func define_anchors():
offset_left = size.x / 2
offset_top = size.y / 2`

Which give the following result

#

It feels really off for some reasons:

  • It means you cannot "preview" your UI while your scene hasn't started, and every elements place themselves at start
  • Positioning elements with script isn't really what I've been taught in my web developer career, I would never write javascript that moves element at screen resize, even tho websites are fully responsive
#

And I still don't understand the position of my hbox in my first 3 screens. Maybe it makes no sense to define anchor at the same point without offset ?