This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+1 vote

I need to use a tween animation for change text label current scale.

But, when scaling text label, it is modified from the top-left. I wish to scale it from the center, as shown in the following example:

enter image description here

Is it possible?

Thanks in advance

in Engine by (1,488 points)

The only option may be to displace the text while scaling.

EDIT: I've just tried something: if you can, put the text on the center of a Node2D or a Control and scale that node instead.

Yes, with a control node as parent it works.

But this is not convenient, why not Godot support like "Sprite".

3 Answers

+1 vote
Best answer

If is to use tweens only and no extra nodes, can be done tweening rect/scale and rect/pos in the same tween.

Dirty example:

tween.interpolate_property(text, "rect/scale", text.get_scale(), text.get_scale()*4, 2, Tween.TRANS_LINEAR, Tween.EASE_IN)
tween.interpolate_property(text, "rect/pos", text.get_pos(), text.get_pos()-text.get_size()*1.5, 2, Tween.TRANS_LINEAR, Tween.EASE_IN)
by (7,954 points)
selected by
0 votes

This comes up quite a bit, I sort of wonder why they never extended pivots to other types of nodes.

In addition to faking a pivot with a empty parent node, you can offset it in code by keeping the original position and dimensions.

set_pos(original_position - original_size * scale / 2)
by (5,286 points)

This works well in a static situation, but during a tween animation is more complex to do

I didn't notice any problems when I applied tweening to it:

extends Label

func ease_out_bounce(t,b,c,d):
    t /= d
    if (t < 1/2.75): 
        return c*(7.5625*t*t) + b
    elif (t < 2/2.75):
        t -= 1.5/2.75
        return c*(7.5625*t*t + .75) + b;
    elif (t < 2.5/2.75):
        t -= 2.25/2.75
        return c*(7.5625*t*t + .9375) + b;
        t -= 2.625/2.75
        return c*(7.5625*t*t + .984375) + b;

onready var original_size = get_size()
onready var original_pos = get_global_pos()

func _ready(): set_process(true)

var t = 0
var d = 1.5

func _process(delta):
    t += delta
    if(t > d):
        t = d

    var tween_amount = ease_out_bounce(t,1,3,d)
    var scale = Vector2(tween_amount, tween_amount)

    set_global_pos(original_pos - original_size * scale / 2)
0 votes

Hi, I have asked a question like this.
here is the url

by (86 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 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.