I have a game I am working on where there are tiles in rows and columns. Players can swap the tiles by dragging them around with the mouse and I want to check what order they are in after each move.
I've tried a couple of iterations of what I thought would work by using an Area2D node that moves to each tile position and adds the tiles to lists after releasing the mouse button. Instead, the Area2D moves, but only adds the first tile it was on to the list (or in the case of using a signal, doesn't even add anything after the first input).
I've tried using bodyentered and getoverlapping_bodies. I've also tried switching between _input and _process. Here is the relevant code trying to get just the top row:
for column in columns:
$PosChecker.position.x = firstColumnX + columnSpacingX*column
$PosChecker/CollisionShape2D.position.x = firstColumnX + columnSpacingX*column
rowList += $PosChecker.get_overlapping_bodies()
for name in rowList:
$PosChecker.position.x = firstColumnX
$PosChecker.position.y = firstRowY
I'm assuming this has something to do with sequencing and/or collisions all processing at once (as in the case of getoverlappingbodies). But I've spent way too much time banging my head against the walling trying to figure this out and I obviously have no idea what I am doing.
Am I missing something or going about it wrong? Is there an elegant solution to this or should I maybe place Area2Ds at each tile position?