Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Fog of War


Andy1988
 Share

Recommended Posts

Hi everyone.

I am trying to build a top-down game and I would like to implement Fog of War in my game. I'm using Tiled for creating my maps. Any one have any idea what would be the best approach be to creating that kind of system? I've attached an example picture. In my mind I see something like that.

fog.jpg

Link to comment
Share on other sites

This will happen outside of tiled (I think, its dynamic whereas Tiled is static I think so it can't be supported), you need to work out a few things

* How much of the world has been visited?

* How much of the world is visible?

They're both fairly trivial, the top one is simplest just with each tile/location having a flag (visited), set it to true whenever it has been seen (not actually visited, maybe rename the variable!), the bottom one is marginally trickier, iterate over each unit (actually, you only need to update units that have moved) and calculate their visible range. In the example this is not a visibility check, its merely a distance check, the trees do not obscure visibility (maybe they do in your AI code?). Store all the visible and not visible locations in an array.

During the render phase you use your visibility map to draw an additional layer of darkness (or not) on top of everything else.

Note that when the world and/or number of units gets large this can get a little expensive, particularly if you do implement an entity-obscured visibility check, but normally your AI would choke the cpu before the fog stuff causes any issues.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...