![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Godont |
I have read several threads which say that it isn’t possible for children of container nodes to be scaled because the parent controls that property, and yet this simple demo project seems to do it (unless I’m missing something).
Is this just a bug and it isn’t supposed to be able to do that? If so, how can one achieve, for example, a tween of a Label
’s rect_scale
from one scale to another if it sits inside, say, a VBoxContainer
? I have a hard time believing that such a basic GUI operation is impossible in Godot.
So I overloaded the set_scale()
and draw()
functions of the Cancel
label and found that when you call_deferred("focus_cursor",current_choice)
:
end
(1, 1) draw, vis in tree: True
set rect (1.6, 1.6) vis in tree: True
(1.6, 1.6) draw, vis in tree: True
but when you focus_cursor(current_choice)
:
set rect (1.6, 1.6) vis in tree: True
end
(1, 1) draw, vis in tree: True
Even when you call_deffered("_draw")
on the Cancel
label just draws it twice at (1,1)
scale. Strange.
timothybrentwood | 2021-05-05 22:11
I remember replying to someone that they could use the scale to animate a VBoxContainer
children appearing. So you should be fine using the rect_scale
property. One thing for sure is that you can’t control the size of the children, because it’s controlled with the parent container.
MrEliptik | 2021-05-05 22:12
From Using Containers — Godot Engine (3.3) documentation in English :
“When a Container-derived node is used, all children Control nodes give up their own positioning ability. This means the Container will control their positioning and any attempt to manually alter these nodes will be either ignored or invalidated the next time their parent is resized.”
func _input(event):
if event.is_action_released("mb_left"):
$CenterContainer/FileSelectBox/CenterContainer/ConfirmBox/ChoicesBox.rect_size += Vector2.ONE
So when you scale the Cancel
label using focus_cursor()
then click to resize the parent the scale set in focus_cursor()
goes away. Which follows the above logic.
From Control — Godot Engine (3.3) documentation in English :
Vector2 rect_scale [default: Vector2( 1, 1 )]
The node’s scale, relative to its rect_size. Change this property to scale the node around its rect_pivot_offset. The Control’s hint_tooltip will also scale according to this value.
Note: This property is mainly intended to be used for animation purposes. Text inside the Control will look pixelated or blurry when the Control is scaled. To support multiple resolutions in your project, use an appropriate viewport stretch mode as described in the documentation instead of scaling Controls individually.
Note: If the Control node is a child of a Container node, the scale will be reset to Vector2(1, 1) when the scene is instanced. To set the Control’s scale when it’s instanced, wait for one frame using yield(get_tree(), “idle_frame”) then set its rect_scale property.
when the scene is instanced stands out to me. Obviously it’s instanced when the game starts but it’s exhibiting the same behavior when it’s being made visible as well
timothybrentwood | 2021-05-05 23:17
Thanks for the very detailed research and response here. I really appreciate it.
If I’m understanding properly (not sure I am), it seems that I cannot change the size of a Control
child of a container node, but I can change the scale. However, if ever the container node is resized that scaling will be reset to Vector2.ONE
. This leaves us with the mystery of why this scale is also reset after the parent’s visibility is changed, with two connected mysteries:
- This only occurs the first time that the confirmation container node is made visible, and not when it is subsequently made visible again
- This does not occur for the file select container node even though it is initially not visible and is later made visible
Is this the right takeaway? If so, how does one go about tweening a Label
’s rect_scale if it is a child of a container node? Is it just impossible?
Godont | 2021-05-06 15:21