Godot Version
v4.2.1.stable.official
Question
I have a following helper node made for handling clicks:
class_name ClickHelperScene
extends Area2D
signal clicked_left_mouse_button
signal clicked_right_mouse_button
signal mouse_hover_start
signal mouse_hover_end
func _ready() -> void:
mouse_entered.connect(func():
mouse_hover_start.emit()
#get_viewport().set_input_as_handled()
)
mouse_exited.connect(func():
mouse_hover_end.emit()
#get_viewport().set_input_as_handled()
)
func _input_event(viewport: Viewport, event: InputEvent, _shape_idx: int) -> void:
var is_event_mouse_click: bool = \
event is InputEventMouseButton and event.is_pressed()
if is_event_mouse_click and event.button_index == MOUSE_BUTTON_LEFT:
clicked_left_mouse_button.emit()
viewport.set_input_as_handled()
elif is_event_mouse_click and event.button_index == MOUSE_BUTTON_MASK_RIGHT:
clicked_right_mouse_button.emit()
viewport.set_input_as_handled()
And this works fine… Well, mostly. Thing is, I’m making a card game, and the cards use this to react to mouse events but sometimes cards overlap over one another, like this:
Clicks work fine since I handle them via viewport.set_input_as_handled()
, but same doesn’t go for mouse hover. Is there a way for me to handle an mouse hover event so it doesn’t propagate to Area2D
s below it, similar to clicks (there is probably a manual way of detecting some sort of InputEventMouseMotion
but that seems hacky to me)? As you can see in the code above, I tried handling input manually on area’s mouse_entered
and mouse_exited
signals, but doesn’t do anything as far as I can see.
Any advice on handling this neatly would be awesome.