Tween scaling for a text label

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By jospic
:warning: Old Version Published before Godot 3 was released.

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

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.

eons | 2016-11-22 12:30

Yes, with a control node as parent it works.

jospic | 2016-11-22 17:38

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

Kevin | 2016-11-23 02:17

:bust_in_silhouette: Reply From: avencherus

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)

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

jospic | 2016-11-23 08:56

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)

avencherus | 2016-11-23 10:44

:bust_in_silhouette: Reply From: Kevin

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

:bust_in_silhouette: Reply From: eons

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)