5
\$\begingroup\$

I have a map of adjacent irregularly-shaped territories. It happens to be a county map, but that's not important. In the game, the player only sees a few to start, and as he progresses to new territories, the ones adjacent to it are revealed. It's a territory-scale fog-of-war.

I'm using Unity3D, and my inclination is to make a set of planes, each of which has an image of a single territory on it, and then arrange them manually like a jigsaw puzzle. It then is fairly easy to respond to a click on each region and also to mark the planes as visible or invisible, or even do clever things like fade or zoom on individual regions.

This sounds like an arduous task, and if we need to change the visual design of the territories, we'd have to cut up the main map all over again into each of the individual pieces.

Does anyone have a more elegant solution to this problem?

\$\endgroup\$

2 Answers 2

3
\$\begingroup\$

Maybe you could use a second texture, hidden from the player, with a color mask where every color corresponds to a certain region? Then you could do a lookup againts the coordinates of a user click on your main map against that colormaskmap.

Also you could have a graph storing which counties are adjacent to which and decide which ones should be visible that way. Nodes could of course also store other info as center of region which you might want to zoom to etc.

I don't know if this is how others do it though, just an idea on the top of my head.

\$\endgroup\$
4
  • \$\begingroup\$ If all I needed to do was detect clicks, I'd probably use a color mask. It's the showing and hiding of regions that I'm puzzling over. I suppose I could use a color mask as a way to cluster pixels within a region, and when I need to show a region, change just the alpha of the corresponding pixels in the map image. That is, if I'm clicking on the 'red' masked territory, then for each red pixel in the mask, change the alpha of the pixel at the corresponding coordinate. I'll have to consider that. \$\endgroup\$ Aug 13, 2012 at 11:32
  • \$\begingroup\$ Yeah I was thinking along those lines. I think your question is very interesting so let us know what you come up with! \$\endgroup\$ Aug 13, 2012 at 12:41
  • \$\begingroup\$ This is essentially what we ended up doing. One layer is the map the player sees. There's another reference layer with the same topology but with color coding. A third visible layer provides the fog of war: look up the corresponding colors in the reference layer and change the alpha values in the fog layer to reveal only the portion we see. I wrote a bit about it on my blog: paulgestwicki.blogspot.com/2013/01/… \$\endgroup\$ Jan 2, 2013 at 16:28
  • \$\begingroup\$ Interesting read! \$\endgroup\$ Jan 11, 2013 at 8:44
0
\$\begingroup\$

I think your basic approach is correct — as you noted, there are several really useful things that you can do with a bitmask for your countries, and especially for things like picking there really aren't substantially better ways. But it sounds like you're looking at the construction of these masks backwards; rather than building individual masks and carefully fitting them together jigsaw-style, I would go the other way: start with a bitmap of the map as a whole, either a single black-and-white layer where the black pixels represent boundaries or a full-color image that has a specialized 'boundary color' for doing the same thing. It should be easy to tweak your pipeline to make sure you can generate an image like this; it's almost a necessary piece of building the full-scale worldmap, and should be at worst be an easy by-product of the art generation process.

I'd suggest building a small tool that can take this 'map layer' and create the bitmasks you're talking about: do a linear search through the bitmap for a non-boundary pixel, then floodfill from that point with respect to the boundary pixels, marking off each pixel that you fill in a second bitmap. Once you're done, that second bitmap will be the mask for one territory; you can clip it to its minimum size (keeping track of where it came from in your original image), fill its pixels in your original image so they aren't considered again, and then do another scan to look for non-boundary (and non-filled) pixels. Continuing like this will eventually give you all of your territories, along with their positions in the original map, and from there everything should work like you were outlining.

Note that the key to this process is really the tool — having a mechanical process that can work from a relatively easy-to-produce asset (in this case, the overall map) and give you the assets you really need.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .