Getting the world space of an object that is a child of a VBoxContainer

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By funlamb
:warning: Old Version Published before Godot 3 was released.

enter image description here

As you can see I’m making a menu. I have the 4 buttons in a VBoxContainer so they all have a position inside that container. I’m trying to get the black bar to be under the button that is selected. Right now the 1 Player button is selected and the bar’s y position is too low. This is happening because the 1 Player buttons position is relative to the VBoxContainer. The bar uses that y position the get to the right spot but it wrong.

How do I go about finding the screen space position of the button?

Also, if there is a better way to do this I’m all ears.

:bust_in_silhouette: Reply From: avencherus

This will give you the top left coordinate of that control in global (screen) coordinates.

Other alternative designs might include nesting hidden elements behind the buttons, and using hide and show.

Yet another is that Controls are CanvasItems, so you can invoke update() and write your own _draw() method. Things can be locally draw within whatever container or panel that may wrap up the button itself, and it should appear underneath since it would be the parent node.

How do I get the center of the node? I’ve tried getting the size of the button and adding half that to the position but that didn’t work.

funlamb | 2017-03-18 21:59

Should work that way unless you have some scaling on your button. The size is pre-scaling.

That’s about all I can suggest though.

get_global_transform().get_origin() + get_size()/2 * get_scale()

avencherus | 2017-03-18 22:04

That’s it. Thanks for you help

funlamb | 2017-03-18 23:53

Glad I could help. X)

avencherus | 2017-03-19 17:53