Draw with functions from parent node

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

I have a parent-Node2D with an image; on witch I draw and use setpixel etc.
It has a childe-Node2D, witch is almost the same as it parent.
Now, how can the child use the functions of the parent, so they draw in the child instead?

:bust_in_silhouette: Reply From: avencherus

By connecting to it’s draw signal, so the functions can be called at the right time.

extends Node2D # Parent node

func _ready():
	$child.connect("draw", self, "draw_on_child")
func draw_on_child():
	$child.draw_circle(Vector2(), 30.0, Color.green)

First: Thank you.
Second: Nope I don’t get it.
I’m guessing ‘draw_on_child’ tells the ‘draw_circle-function in the child-node’ to work?
I thought all draw-functions had to be in _draw()?
Well… I fiddled a bit, and now the child can draw circles on the parent. (most parents wouldn’t like that! HA!) But I want the child to tell the parent to draw on the child.
I was perhaps not clear enough in my question?
Let’s say I have a bunch of functions in some node (parent or otherwise). As a kind of library of useful stuff.
I can use them from other nodes via get_node(someplace). But (in my case(so far)) I can only get them to change data. Not draw stuff in the node that calls them.
I’m still baffled, so probably avencherus’s answer is correct.

edit: why is my text oblique? Strange thing are going on…

edit too: I’m sure avencherus’s answer is accurate but my question was questionable?.

Black Monkey | 2020-07-29 14:57

:bust_in_silhouette: Reply From: Black Monkey

adding a little example:
in the parent;

func point(img:Image, start:Vector2 , color:Color):
img.set_pixel(start.x , start.y , color)

in the child:

func _ready() -> void:
image = Image.new()
image.create(imageSize.x, imageSize.y, false, imageFormat) 
imageTexture = ImageTexture.new()
imageTexture.create(imageSize.x,imageSize.y, imageFormat, 0)    
$parent.point(image,Vector2(10,10) , Color(1,1,0),22)

doesn’t work…
If I call to a similar function in the child self: it works.
edit: pasted in a bit more code