I found out how I can draw a circle using the draw_circle() method within the _draw() function.
Now I like to reference the circle node (or object) to change it's diameter or color or to delete it again.
How can I reference it?
E.g. I would expect to use it like this:

circle_node = draw_circle ( position, radius, color )
circle_node.queue_free()

But circle_node is null, obviously because draw_circle()'s return value is void.
How does it work then?

  • cybereality Great, thank you!

    My solution is now to make a class DrawCircle.
    Then I can make a new circle by instantiating a new object of the circle class.
    And if I don't need the circle any more, I queue_free() the circle class object.

    class_name DrawCircle
    extends Node2D
    
    
    # Declare member variables here.
    var node
    var center
    var radius
    var color
    
    # Workaround to make get_class() and is_class() also work for custom classes.
    # This overrides the get_class() and is_class() methods and returns your
    # custom class name correctly.
    func get_class():
    		return "DrawCircle"
    
    func is_class(value):
    		if value == "DrawCircle":
    				return true
    		else:
    				return false
    
    func _init( _node, _center:Vector2, _radius, _color ):
    	node = _node			# parent node under which the child node is created
    	center = _center
    	radius = _radius
    	color = _color
    	node.add_child(self)
    	return self
    
    # Called when the node enters the scene tree for the first time.
    func _ready():
    	pass
    
    func _draw():
    	draw_circle(center, radius, color)

The drawing happens every frame (when draw is called). You can either remove that function call (draw_circle) or you can remove the whole node when you are done with it.

    5 days later

    cybereality Great, thank you!

    My solution is now to make a class DrawCircle.
    Then I can make a new circle by instantiating a new object of the circle class.
    And if I don't need the circle any more, I queue_free() the circle class object.

    class_name DrawCircle
    extends Node2D
    
    
    # Declare member variables here.
    var node
    var center
    var radius
    var color
    
    # Workaround to make get_class() and is_class() also work for custom classes.
    # This overrides the get_class() and is_class() methods and returns your
    # custom class name correctly.
    func get_class():
    		return "DrawCircle"
    
    func is_class(value):
    		if value == "DrawCircle":
    				return true
    		else:
    				return false
    
    func _init( _node, _center:Vector2, _radius, _color ):
    	node = _node			# parent node under which the child node is created
    	center = _center
    	radius = _radius
    	color = _color
    	node.add_child(self)
    	return self
    
    # Called when the node enters the scene tree for the first time.
    func _ready():
    	pass
    
    func _draw():
    	draw_circle(center, radius, color)