Godot Version
4.2
Question
I am working on a small game. The game has objects troop and city. In the troop, I use MOUSE_LEFT to trigger a popup menu. The popup menu is the mouse position.
The most relevant code:
func _unhandled_input(event: InputEvent) -> void:
if event is InputEventMouseButton:
if event.button_index == MOUSE_BUTTON_LEFT:
var target = get_global_mouse_position()
if event.pressed:
if selection_node.selected:
#print("set target %s" %[target])
set_target_position(target)
popup_menu.set_position(target)
popup_menu.popup()
print("debug: popup menu %s"%[target])
else:
pass
There are two cases
case 1: mouse position is on a tilemap
case 2: mouse position is inside an object (city).
It works well in case 1. However, the the PopupMenu does not appear in case 2. The debug message shows the popup_menu.popup()
is called but I can not see the menu.
I have some guess here:
1: The PopupMenu is behind the city? I tried to click the mouse in the edge of the city, I can not see part of PopupMenu.
2: The city is selectable. So, the MOUSE_CLICK used by the city but not pass to the troop? Because the debug message shows the popup_menu.popup()
is called. So the mouse event is passed to the troop.
Thanks.