Hi there! I'm starting to tinker around with new projects, and I'm interested in making a puzzle game where creating closed-off spaces on a tilemap is part of the gameplay - as such, I'm experimenting with flood fill methods, but I can't seem to get one that works efficiently and instantly.
Here's my quick and dirty example - left click places walls, right click erases them, and middle click wipes the board and checks for enclosed spaces. (adjacent corners don't count as enclosed for my purposes!)
And here's the .capx file:
As you can see, it works, and you can watch it work, but it's definitely way too slow. I'm sure there must be some ideal, optimal way of doing this - I'm hoping for something efficient enough that I can check it every time a piece is placed on the board without bogging things down. Any help would be appreciated!
-- EDIT: UPDATE --
I did a bit more tinkering and I think I found a solution! I'd still appreciate having my work double-checked though:
And the .capx:
This time around, instead of creating a sprite that multiplies itself, it adds the tiles to change represented by coordinate strings in an array - the array serves as a queue of tiles to check, and behaves much like the flood fill object did, but this time it runs in a 'while' loop and thus happens instantly. It seems to work well! Is this the best way to go, or are there even more efficient solutions? I noticed if I add any animated elements, it does hitch slightly upon flood-filling, so any even more optimized solutions would be appreciated.