Prevent moving _draw rect when changing position of node

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

I am drawing a rectangle around a fixed region using the draw_rect method. Problem is that when I move the node with the draw function the rectangle also moves.
If I hide and reshow the node, the rectangle snaps back to the fixed region.

I’m aware that the _draw function draws with respect to local coordinates so that is probably the issue here. But how do I update the drawn rectangle anytime the position is updated?

Is it possible to use a setter for transform.origin maybe? I can call queue_redraw() in the setter.

Reference Video

I’m curious what your requirements are. Why would the node’s position need to change if what it renders stays in the same place? Maybe understanding what you’re trying to do could lead to a potentially different solution.

Tom Mertz | 2023-06-02 00:29

:bust_in_silhouette: Reply From: jgodfrey

You can call draw_set_transform() before drawing anything (in the _draw() function) to set a specific transform for all drawing.

Docs here:

This does change the transform from the default node origin to a custom one but my problem still remains. If I move the node, the drawn rectangle moves along with it, like shown in the linked reference video

spawd | 2023-06-01 18:13

Hmmm… Maybe change the position argument for draw_set_transform() to be dynamically calculated as the difference between the original location and the node’s current location?

jgodfrey | 2023-06-01 18:21

Or, could you move the _draw() code to a node that’s stationary?

jgodfrey | 2023-06-01 18:22