How to scale button when pressed

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

I want to scale from 1 to 1.2 when press a button, but the scale pivot is left-top, I want center. so any one can help me ?

:bust_in_silhouette: Reply From: avencherus

Option 1 is to use an empty control node, or position 2D as a parent. Use it as a faux pivot point by moving the (child) button until the center point of that empty parent node is the center of the button. From there, just scale the control/position2D parent node. It’s transforms will carry over.

Option 2, use math in script to offset the position after scaling. Here is an example with scaling by 50%, contained inside the button itself.

extends Button

func _on_Button_pressed():
	var scale = Vector2(.5, .5)
	var button_size = self.get_size()
	var button_pos = self.get_global_pos()
	self.set_global_pos(button_pos + button_size * scale / 2)

It works,hhhh.
Because I need to scale with animation, the option 1 is what I wanted.
Thank you my brother !

Kevin | 2016-11-20 05:49

You’re quite welcome. :slight_smile:

avencherus | 2016-11-20 16:53