Things not being where they say they are, going mad

Godot Version

4.2.1

Question

I am drawing procedurally generated tiles with the draw_rect() function, but the tiles are not drawing where they say they are. even printing the position before drawing, like this:

rect = Rect2(position, tile_size)
print(position)
draw_rect(rect, col)

it still prints (0, 0) as the position, but they render way off at something like (1000, 200). everything in the scene is at the position (0, 0), so there should be no reason for this to happen. here is the complete tile rendering code (WARNING: BAD CODE):

extends Control

var map_size = Vector2(20, 10)
var tile_size = Vector2(2, 2)
var rect = 0
var col = Color.SADDLE_BROWN

@onready var world_gen = $“…/WorldGen”

Called when the node enters the scene tree for the first time.

func _process(delta):
queue_redraw()

func _draw():
position = Vector2(0, 0)
for x in range(0, world_gen.width):
position.y = 0
position.x = x*tile_size.x
for y in range(0, world_gen.tile_map):
rect = Rect2(position, tile_size)
print(position)
draw_rect(rect, col)
position.y -= tile_size.y

please help, I am going insane.

The _draw() function transform is local to the node’s transform. So if your node is set to position 1000,200 then draw_rect(Rect2(0, 0, 16, 16), Color.BLUE) will draw a blue rectangle of 16x16 at position 1000,200

as mentioned in the post, the local position of every single node in the game is at 0, 0. I think I will report this as a bug, because I have no clue why this is happening and nobody else seems to either :frowning:

position is the local position of the node relative to its parent, global_position is the global position of the node relative to the canvas. If your node is a child of another node that’s is in 1000,200 then the node position is 0,0 but the global_position is 1000,200

Make sure that all the nodes positions are set correctly.

as mentioned, every single node in the game is at position 0, 0, even the parent nodes. I will report it as a bug