Glitches in the flood fill function (array manipulation)

0 favourites
  • 4 posts
From the Asset Store
An educational game for Fill in the Blanks. An easy to use template for developers to build larger games
  • Hello.

    I added a flood fill function to my level editor.

    I found it here on the forums.

    construct.net/en/forum/construct-2/how-do-i-18/best-flood-fill-tilemap-141678

    I tried to adapt it to my editor. (it functions a little different)

    I managed to go a bit, ironing out a lot of bugs/glitches/getting stuck.

    But I am having a bit of glitches.

    If you draw small boundaries or figures and try to flood fill them (try several times!) it will sometimes be stubborn and NOT floodfill it, until you found a sweet spot and it manages to fill.

    Sometimes it will flood fill but in WRONG boundary area!

    I have to be honest, I don't play well with that kind of array manipulation. I prefer fixed array, setting values, ha ha!

    But it might be a problem elsewhere. I am confused why the original code only needed X coordinate and not Y (for the inital push)

    Capx file is here:

    funnybunny.se/files/bugwithff.capx

    And just to take a glance of the editor in action here's the uploaded version.

    funnybunny.se/files/project

    Again, I have tried to clean the code as much as I could. Let me know if I forgot third party plugin.

    Thank you and I hope you can help me.

    Also if you feel helpful, maybe also give advice to work in that i won't touch the boundary tiles (1tile border)

  • Hmm, The flood fill does seem finicky in your capx. I had a gander at the your code and the original capx you referenced but I can't pick out what's amiss. Admittedly it's a lot to digest.

    Actually, it looks like it's made to give up if it takes too long and sends a message to the browser console.

    I had a go at making a flood fill that doesn't give up. It ended up being very similar to the one you used. Looks like you're using not adding positions to the array if that tile is already filled, and I think you're doing bounding checking so you're not adding positions off the edge of the tilemap. But the main difference is I'm using the array as a stack instead of a queue which seems to be much faster. I tried switching it around and it was much slower to the point of hanging the game (guess that's why the one you used would give up).

    dropbox.com/s/3eolcab1it3evn4/tilemap_floodfill.capx

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thank you!

    I have added that "quitter" when I got fed up with trying to shut down browsers from task manager for 50th time like.

    Your example looks neat and looks like it works properly. I will try to use that toward my needs.

    Thank you so much again, as always.

    (and I am very much considering going over to a properly tilemap for this... I couldn't use it for game engine iself, but for level editor it will work. Lots of rewriting ahead, but it might be for the better!)

  • Late reply, but I wanted to tell that I used your example (with my own modifications) and it is working beautifully.

    Thanks again!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)