How to click on TileMap and send it to close Control

Godot Version

4.2.1

Question

After pressing the button, the BoardMenu will come up. In the BoardMenu there is a TileMap. I want after pressing the TileMap to close the BoardMenu page. How to


In GUI

extends Control

@onready var rook_cho = $MarginContainer/VBoxContainer/Rook_cho as Button
@onready var board_menu = $Board_Menu as BoardMenu

# Called when the node enters the scene tree for the first time.


func _ready():
	set_process(false)
	handle_connecting_signals()


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	pass

func _on_Rookcho_pressed() ->void:
	board_menu.visible = true
	
func _on_exit_tile_map() ->void:
	board_menu.visible = false

func handle_connecting_signals() ->void:
	rook_cho.button_down.connect(_on_Rookcho_pressed)

In Board_Menu

class_name BoardMenu
extends Control

@onready var tile_map = $MarginContainer/GridContainer/Node2D/TileMap
signal exit_tile_map

var is_handling_tile_map = false

func _ready():
	exit_tile_map.connect(_on_tile_map)

func _input(event: InputEvent) -> void:
	if event.is_action_pressed("mouse_left") and not is_handling_tile_map:
		is_handling_tile_map = true
		_on_tile_map()

func _on_tile_map() -> void:
	pass

Rapidly skimming the code, when you connect the signal of the pressed button, that will only turn it visible because the method linked makes it “visible = true.” You can try to invert its state instead like:

func _on_Rookcho_pressed() -> void:
    board_menu.visible = !board_menu.visible
1 Like