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, 2019 in Engine by KnightNine (36 points)
retagged Jul 21, 2019 by KnightNine

2 Answers

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, 2019 by kidscancode (13,074 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.

0 votes

update for reference:

The issue was that Godot doesn't give you control of the pivot offset (and probably other controls) through the code of nodes I created and set the values for dynamically from the scene itself. I had to make a separate scene to create instances of these buttons from; where all these settings are already applied to an existing button.

Guess that Godot isn't built for certain more complex nodes like textureButtons to be created dynamically. If Godot had thrown an error instead of allowing me to create these nodes dynamically in the first place, i would've figured that wasn't the way I was meant to do this sooner.

answered Aug 22, 2019 by KnightNine (36 points)
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.