0 votes

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 ?

in Engine by (86 points)

1 Answer

+3 votes
Best answer

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)
by (5,232 points)
selected by

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

You're quite welcome. ^_^

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 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 webmaster@godotengine.org with your username.