I tried resizing the scale of my Label node but then it changed positions

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By javrocks

I have a label in the centre of my texture and since the scale of my texture changes the scale of the label needs to change to, but when i tried this the label did resize but it also moved out of the centre and to the left

extends KinematicBody2D

func _ready():
    randomize()

    var random_value = rand_range(0.4,0.8)
   $Texture.scale.x = random_value
   $Texture.scale.y = random_value
   $Label.rect_scale.x = $Label.rect_scale.x * random_value
   $Label.rect_scale.y = $Label.rect_scale.y * random_value
:bust_in_silhouette: Reply From: skysphr

Instead of directly manipulating the rect_scale of the label, use anchors and margins. If you make your Label a child of a TextureRect, select the Label, switch align and valign to center, then on the tool bar go to Layout > Center. This should keep the label centred automatically.

I added label as a child of a Texture Rect did those things but Its still off. Allign and Vallign is centre ad everything

javrocks | 2022-02-18 20:27

Something must have gone wrong in the process. Here’s an example project.

skysphr | 2022-02-21 07:44

Yeh in the toolbar i hit centre left the first time but then i changed it to Layout>centre and now it’s wrk
Thx

javrocks | 2022-02-22 04:08