Godot Version
4.2
Question
I had this working before refactoring it to it’s own function when it was just in process() but when I attempt to use clear_area from this parent node:
func _process(_delta):
handle_panel(UnitSelectionPanel, "unit_selection_panel_updated", "rts_drag_select")
handle_panel(UnitPlacementPanel, "unit_placement_panel_updated", "rts_drag_position")
func handle_panel(panel: Control, signal_name: String, action_pressed: String) -> bool:
if Input.is_action_just_pressed(action_pressed):
panel_start_position = get_global_mouse_position()
is_dragging = true
if Input.is_action_just_released(action_pressed):
is_dragging = false
emit_signal(signal_name, panel_start_position, panel_end_position, panel_area)
panel.clear_area()
print("emitting signal")
return true
if is_dragging:
panel_end_position = get_global_mouse_position()
panel.draw_area(panel_start_position, panel_end_position)
var new_area = panel.get_area()
if new_area != panel_area and new_area.size.x > 0 and new_area.size.y > 0:
panel_area = new_area
return false
We get to the clear_area function directly on the panel node:
func clear_area():
self.size = Vector2(0, 0)
self.position= Vector2(0, 0)
print("clearing")
However it is still visible on the screen. I know this doesn’t technically clear it but the panel should not be seen since it is a 0 size and at the origin. I had this working when the parent node was running a child_node_name.size = 00 and position so when calling in process from the parent node but I would prefer this specific function to be in the child’s script. Don’t know where I am going wrong.
I also just now noticed the event seems to be firing when I just left mouse click despite my input map setting rts_drag_select to only work when shift + left mouse click is used.