0 votes

Why are the texturebuttons I place into the scene are way off center to the bottom right from the mouse position that is given to them using set_position(). Their pivot points when resizing them also seem to be at their top left which is seen when their size changes on mouse hover.
When i was using sprites instead of texturebuttons, this issue wasn't prevalent.

Godot, off center texture buttons image

Any suggestions would be much appreciated!

asked Jul 21 in Engine by KnightNine (12 points)
retagged Jul 21 by KnightNine

1 Answer

0 votes

Have a look at the Control's rect properties. "Grow Direction" determines in which direction(s) the object grows when resizing - you probably want "Both". You can also set the "Pivot Offset" to the center of the Control rather than the default of (0, 0) (top-left corner).

answered Jul 21 by kidscancode (10,690 points)
#hopefully this fixes the offset issues
    rect_pivot_offset.x = .5
    rect_pivot_offset.y = .5

put this under _ready(), It didn't change anything unfortunately (also tried a bunch of random values and no difference.).

i also tried (with and without the pivot_offsets)

grow_horizontal = Control.GROW_DIRECTION_BOTH
grow_vertical = Control.GROW_DIRECTION_BOTH

under _ready() and the icons are placed to the far top right and no longer open up with my script which moves the icons. (the icons still grow in the same direction on hover btw)
:/ i could try to recreate a more basic example that focuses on this issue to demonstrate it but yeah. I'm starting to think this is a problem with how these buttons were implemented.

(i drew where my mouse is relative to the icons (bottom left))
mouse distance

I might just have to create a sprite and child the texture button to it for this to work properly.

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 How to use this Q&A? before posting your first questions.