Material Box

Material Box

WEB Design & Material Images

Godot - Getting the Position and Size of a Button

Godot

This code example shows how to get the position and size of a circular Button node using GDScript.


To get the position of a Button node, you can either reference the `position` property or use `get_position()`.

# Create a Button node
var button = Button.new()
add_child(button)
button.set_text("Button")
button.set_size(Vector2(200, 200))

# Get the position
var pos = button.get_position()
# var pos = button.position

print(pos)
# (0, 0)

To get the size of a Button node, you can either reference the `size` property or use `get_size()`.

# Create a Button node
var button = Button.new()
add_child(button)
button.set_text("Button")
button.set_size(Vector2(200, 200))

# Get the size
var size = button.get_size()
# var size = button.size

print(size)
# (200, 200)

Godot

TitleGodot - Getting the Position and Size of a Button

CategoryGodot

Created

Update

AuthorYousuke.U