How do the custom drawing (using _draw()) positioning works?

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

So I have a simple script on sprite that draws a circle at the position of the sprite.

extends Sprite
func _draw():
    	draw_circle(position,2,Color.red)

Initially the object is at (0,0) and it works fine.
enter image description here
But I re ran the project by changing the position to (30,30). Now the sprite and the circle are not in the same position.
enter image description here
And as I change the position at more distant from the origin, the more the difference between circle and sprite increases.
I am not understanding how the custom drawing positioning works?

:bust_in_silhouette: Reply From: Zylann

Everything you draw inside _draw() is drawn relative to the node. So if you use position in your call, you’ll end up drawing it at position + position, which is why you see it offset.

To draw your circle on top of the sprite, use draw_circle(Vector2(0,0), 2, Color.red).

Got it, thanks

_nabajit | 2020-05-04 01:40