Flood fill algorithm to select a country in a map with libgdx

See for working example and code here

Note: this solution is made for libgdx, using Pixmap

Building a 2d strategy game could be useful to draw a world map, divide countries using a specific color and then let user select a country, then highlight it. But how to made this selection without store any information about countries geometry ?

Solution: use flood fill algorithm!


Solution is made with on the following steps:

  1. get player click point as (x,y)
  2. from (x,y) use flood fill algorithm to fill a specific area, delimited by border color
  3. draw a border around the resulting image, not used areas are transparent
  4. display image with border to the player

For the complete code, take a look here