Godot Version
Godot Engine v4.2.2.stable.official.15073afe3
Question
I am trying to draw a grid on screen.
As best I can work out, I am drawing the lines, but nothing is shown on screen so I am clearly missing something. The coords seem sensible to me, but even if they werent I’d expect to see some lines on screen!
Code and result below. Any help would be appreciated!
## world.gd
func _draw() -> void:
print("hit draw")
if _show_grid:
_draw_grid()
func _draw_grid() -> void:
print("draw_grid called")
var start: Vector2i = Vector2i.ZERO
var end: Vector2i = Vector2i.ZERO
var colour: Color = Color.PINK
for x in range(0, grid_size.x + 1):
start = Vector2i(x * _grid_scale, 0)
end = Vector2i(x * _grid_scale, grid_size.y * _grid_scale)
print("Draw horizontal (", start, end, ")")
draw_line(start, end, colour, 2)
for y in range(0, grid_size.y + 1):
start = Vector2i(0, y * _grid_scale)
end = Vector2i(grid_size.x * _grid_scale, y * _grid_scale)
print("Draw vertical (", start, end, ")")
draw_line(start, end, colour, 2)
Console output:
Toggle show grid. Now: true
hit draw
draw_grid called
Draw horizontal ((0, 0)(0, 24))
Draw horizontal ((4, 0)(4, 24))
Draw horizontal ((8, 0)(8, 24))
Draw horizontal ((12, 0)(12, 24))
Draw horizontal ((16, 0)(16, 24))
Draw horizontal ((20, 0)(20, 24))
Draw horizontal ((24, 0)(24, 24))
Draw horizontal ((28, 0)(28, 24))
Draw vertical ((0, 0)(28, 0))
Draw vertical ((0, 4)(28, 4))
Draw vertical ((0, 8)(28, 8))
Draw vertical ((0, 12)(28, 12))
Draw vertical ((0, 16)(28, 16))
Draw vertical ((0, 20)(28, 20))
Draw vertical ((0, 24)(28, 24))
Result:
Scene tree: