Thursday, November 15, 2018

2d - How can I create gradiented Fog of War?


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?



Answer



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.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...