Size And Position, Godot 4
Asked Answered
T

2

0

I'm confused. What is the problem?
func new():
var up_layer = ColorRect.new()
up_layer.size = Vector2(size.x,size.y / 5)
up_layer.color = Color.RED
add_child(up_layer)

var website_button = Button.new()
up_layer.add_child(website_button)
website_button.text = "Website"
website_button.size = Vector2(up_layer.size.x / 3 / 3, up_layer.size.y / 3 )
website_button.position = Vector2(distance * 2, up_layer.size.y / 4)

print("website_button size = " + str(website_button.size))
print("website_button position = " + str(website_button.position))


var key_find_button = Button.new()
key_find_button.text = "Key Point"
key_find_button.size = Vector2(up_layer.size.x / 3 / 3, up_layer.size.y / 3)
key_find_button.position = Vector2(website_button.size.x + website_button.position.x + distance * 2, up_layer.size.y / 4)

up_layer.add_child(key_find_button)
print("key_find_button size = " + str(key_find_button.size))
print("key_find_button position = " + str(key_find_button.position))

The results are
website_button size = (102.2222, 43.2)
website_button position = (4, 32.4)
key_find_button size = (102.2222, 43.2)
key_find_button position = (110.2222, 32.4)

Trishtrisha answered 26/1 at 8:13 Comment(0)
Q
0

Trishtrisha What is the problem?

Indeed, what is the problem? What did you expect and what is wrong? I don't see the issue.

Quan answered 26/1 at 10:56 Comment(0)
T
0

The problem lies in the inconsistency between the printed position of the website button and key button and their actual positions on the screen. However, after adding the third button, they suddenly aligned.

Trishtrisha answered 7/2 at 9:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.