Looking for help with an idea involving _draw()

Godot Version

v4.1.1.stable.official [bd6af8e0e]

Question

I’m trying to create a map game and have been successful in importing an image of my map, then converting it to a polygon tied to a single node using the _draw() func.

What I need help with is dividing this map into pieces. While I’d love to spend 20 hours individually dividing the map into thousands of smaller polygons, I know there must be a faster way to do it through godot, I just don’t know how.

I couldn’t find any example of anybody else doing this type of thing online, so I’m hoping someone on this forum has some knowledge on the subject?

Specifically: Does anyone have ideas on how I can divide my map made of polygons into more smaller polygons?

Example:
One big polygon as the main landmass, then many smaller polygons dividing it up.

The easiest way I can think of is using _draw() to draw a bunch of polylines between points to make the borders of each new polygon division, but how to get the coordinates for each line? I have no idea. Any help or ideas would be very helpful, thank you.

The problem here is edge detection and there are a number of algorithms you can find to solve it. It is probably still going to be a painful experience if you haven’t already practised with these algos.
Alternatively this may be something that one of those new fangled AI systems could do for you.
And lastly (and probably least pleasant)…
If it is only this map and no more then you could brute force it by painting the walls of a cell a known color (say yellow) then writing some code to find the yellow pixels and storing those coordinates.
Then repeat that for each of what looks like 200 cells.

1 Like