I want to select objects on the map, to be able to group them, but I do not want to select them 1 by 1, but when I press the left mouse button I can drag to where I want to select so I can know which objects are selected and add them to a group that I choose. And that the selection area has some effect to highlight.
doing click and drag can be done by any node that’s a Node by _input event function.
to draw it, the rectangle from point of click to until mouse is released, can be creating a child node of panel or TextureRect with beginning size of 0,0 and spawn at clicked position when created and off start clicked. for it to follow mouse position, will need to calculate the first mouse clicked position (or global_position) and the current mouse position subtracted and feed it into the size of this new child panel/textureRect in _process(delta) function. this works if it’s only making rectangle.
There will be problems such as if it drags from top right to bottom left, i think will need to know the direction of the node and flip accordingly. Also above mentioned way is only drawing a rectangle and doesnt blacken the outside area
func _process(delta: float) → void:
if Input.is_action_just_pressed(“justmouse”):
start_mouse=get_global_mouse_position()
select=true
if Input.is_action_just_released(“justmouse”) and select:
select=false
selecting()
func _input(event: InputEvent) → void:
if event is InputEventMouseMotion:
end_mouse=event.position
queue_redraw()
func _draw() → void:
if select==true:
var rect=Rect2(start_mouse,end_mouse-start_mouse)
draw_rect(rect,Color(0,0,1,0.2))
func selecting():
var rect=Rect2(start_mouse,end_mouse-start_mouse).abs()
for x in get_tree().get_nodes_in_group(“x”):
if rect.has_point(x.global_position):
x.modulate=Color.RED
print(x.name)