Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer 1

up vote 11 down vote accepted

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.

share|improve this answer
    
Also, use a spacial index to store your game objects, so that you can quickly query which objects are visible to the player. –  Kai Feb 15 '12 at 14:33
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.