Simple Tile Interaction for an Idiot

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Joe’sFemaleParent

I’m trying to figure out how to allow the player to interact with certain tiles, preferably with single tiles, unless the other options are a lot easier or something. Unfortunately, I can’t find any tutorials that aren’t part of some big series whereas they explain literally nothing and do half the project off cam, and I don’t exactly want to restart my game from scratch. Pretty much the only thing I need to know is the function I’d have to use to detect an interaction with the left mouse button (on a specific tile), and I can do the rest by myself. Please elaborate as much as possible, because I’m dumb.

:bust_in_silhouette: Reply From: MattMakingAGame

From one idiot to another… Not sure if this will work, but I feel it might.

Need to create a scene with Area2d Node with a CollisionShape2D. (You can set it up as a cell if all cells are the same - otherwise change the size of the collision shape when you instance the area(editable children must be selected if you right click on the instance))

Under Tile_ Map attach a script and do

const ClickArea = preload(“res://ClickArea”)

for tile in get_ used_ cells_ by_ id(index_here):
var click_ area = ClickArea.instance()
click_ area.position = tile
add_ child(click_ area)

You would then need to add the click event in the ClickArea script. AND MAKE SURE THE “PICKABLE” selection is ticked
You could also create a tile set of clickable tiles, in which case you could return all tiles used with get_ used_ cells() which would not need an index

Hoping that helps