Using _draw to draw a grid with rounded edges

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By verbaloid

I have a grid of cell size 576x1024
How can I draw a white rectangle of that size with rounded edges in each cell using _draw function? Using StyleBox?
Grid

1 Like
:bust_in_silhouette: Reply From: njamster
extends Node2D

const RADIUS = 45
const POSITION = Vector2(0, 0)
const SIZE = Vector2(576, 1024)

func _draw():
	var style_box = StyleBoxFlat.new()
	style_box.set_corner_radius_all(RADIUS)
	draw_style_box(style_box, Rect2(POSITION, SIZE))

This will work for all base-nodes that inherit from CanvasItem - not just Node2D.

Thank you!! This helped me greatly!

verbaloid | 2020-05-16 10:58

Saved my day! Thanks!

vfpe | 2022-01-29 17:02

1 Like