0 votes

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.

in Engine by (80 points)

1 Answer

0 votes
Best answer

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.

by (5,274 points)
selected by

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.

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()

That's it. Thanks for you help

Glad I could help. X)

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.