How to add a node2d to a position coming from a HUD node position

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

Hello,

I cannot to figure out the following:

I’m trying to add a node2d to a position which comes from an HUD node i created.
What i’m trying to achieve is to spawn sprites in a certain predefined area on the screen (no matter where the camera moves).

What i did so far:

I created a CanvasLayer and in there a node(collisionshape2D) which i can read the position and size from and stays static in the screen.

Any help would be much appreciated!

:bust_in_silhouette: Reply From: Christoffer

You can send the position using signals or make the hud a singleton (autoload).

:bust_in_silhouette: Reply From: Bartosz

Use set_global_position and get_global_position and set directly position of the spawn object.

# inside node in hud that is on desire spawn position 
func spawn():
    # add youre code creating new instance
    # ...
    instance.set_global_position(get_global_position())

This did the trick! Thank you very much!

backdash | 2018-03-20 10:15