14
\$\begingroup\$

I'm creating a top down 2D RTS game for educational purposes. Currently, I'm really just copying Starcraft's design/ideas. I've decided I should probably implement Fog Of War too.

My expectations:

  • Areas currently explored (units are there) should be lit up.
  • Areas previsouly explored (units were there) should be darker but show what things were there when your unit was there.
  • Areas not explored (areas your units have never been to) should be completely black.
  • There should be a gradient change from each type (e.g. explored to previously explored) See picture below.

gradients between visibility regions

Just the rough details: How would I do this?

\$\endgroup\$

1 Answer 1

11
\$\begingroup\$

You should add more information about how you are implementing the game, but here are a few sugestions:

  • Keep a bitmap of the whole map, each time a new area is explored just flip the corresponding bits as they become visible. You can do the same for the revealed area.
  • Enemy units are drawn only if they are in the revealed area. You'll need to keep a 'last seen' state for buildings in the FOW area.
  • You don't need to update visibility every frame - depending on your maximum unit speed, 5 or 10fps should be quite enough.
  • Assuming you are using square tiles, you'll just need 4 masks to get the results you need: one for a 'solid' (blacked out) tile, one 'elbow' and one 'corner' gradient, and one 'straight edge' gradient. You can get all others from these using rotations and different transparencies.

Hope that helps.

\$\endgroup\$
1
  • \$\begingroup\$ Also, use a spacial index to store your game objects, so that you can quickly query which objects are visible to the player. \$\endgroup\$
    – Kai
    Feb 15, 2012 at 14:33

You must log in to answer this question.

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