#Set the size and position of sibling ColorRect

1 messages · Page 1 of 1 (latest)

elder whale
#

func _ready() -> void: color_rect.size = collision_shape_2d.shape.get_rect().size color_rect.global_position = collision_shape_2d.shape.get_rect()
I want to make a color_rect have the same size and position as the sibling collision2D, how can I do that?

dark birch
#

This should work.
Unless the ColorRect is inside another Control node or is using anchors.

Altho Control nodes are not meant for stuff other than UI elements. Trying to position them in specific parts of the world tends to be fucky.

elder whale
#

what node am I supposed to use if nothing works for setting an area shader?

dark birch
#

Any of the Node2D variants.
Polygon2D, Sprite2D, TileMap, Light2D, etc.

You just need something that draws to 2D and has a controllable size. The shader does the rest.