0 votes

I am making checkers in godot (you can view it here) for structure I am using areas for the pieces and a Tlemap for the board.

Project Structure
The checkers are in groups (WCheck for white checkers, BCheck for black checkers) and the tilemap is in its own group. All of these nodes are children of the main node. I was thinking I could add a script to the tilemap which I could call via group to place the current layout of the board in a singleton so I can easily access it with a bot.

The Problem
Is it possible to get an array of areas overlapping a tilemap, and if so what would the syntax be to do this?

Godot version 3.3
in Engine by (27 points)

1 Answer

0 votes
Best answer

I have found a workaround

my structure is

root
|-board (tilemap)
|-W
||-all of the white checkers
|-B
||-all of the black checkers

I am using this code to check the positions of each checker against the board:

func get_board():
    b_peices_remaining = $B.get_child_count()
    w_peices_remaining = $W.get_child_count()

    var b_children = $B.get_children()
    for b_child in b_children:
        var position = b_child.get_position()
        var coord: Vector2 = $Board.world_to_map(position)

        if(b_child.is_in_group("Standard")):
            current_board[coord] = 2
        elif(b_child.is_in_group("King")):
            current_board[coord] = 4
        else:
            print("there is a weird checker at: ", coord)

    var w_children = $W.get_children()
    for w_child in w_children:
        var position = w_child.get_position()
        var coord: Vector2 = $Board.world_to_map(position)

        if(w_child.is_in_group("Standard")):
            current_board[coord] = 1
        elif(w_child.is_in_group("King")):
            current_board[coord] = 3
        else:
            print("there is a weird checker at: ", coord)
by (27 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.