Godot Version
Godot Engine v4.3.stable.official
Question
I’m trying to draw some rectangles stacked together but Godot is giving me some weird behaviors.
I have two gd scripts.
parent.gd
extends Node2D
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
position = Vector2(10, 10)
for i in range(4):
add_child(Child.new(Vector2(0, i * 40)))
child.gd
class_name Child extends Node2D
func _init(p_position) -> void:
position = p_position
func _draw() -> void:
draw_rect(Rect2(position, Vector2(40, 40)), Color.BEIGE, false)
My scene is just one Parent node that has the parent.gd script attached
What I expect to have:
What I got after running the code:
I also noticed that if I set the position of the 2nd child manually in the remote mode, it stacks it right below the first rectangle.
but then if I click the visible checkbox off and on again. the rectangle goes to the correct location (0, 0)
, same location as the first rect.
I’m new to Godot, but I am an experienced programmer (not with game dev). I had no idea what was going on here and how I could draw my rectangles correctly. In the end, I might have thousands of rectangles so they need to be instantiated with the script.