Jump to content
  • Advertisement
Sign in to follow this  
nekoflux

how do I create a fog of war?

This topic is 4528 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

any suggestions for how to implement fog of war? I'm working on a java 2d based rts. you can see it here: http://www.himatomo.com/games/rts/ not really sure how to go about implementing fog of war, would appreciate any help!! thanks, --Mike

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by nekoflux
any suggestions for how to implement fog of war? I'm working on a java 2d based rts. you can see it here:
http://www.himatomo.com/games/rts/

not really sure how to go about implementing fog of war, would appreciate any help!!

thanks,

--Mike


One option: Each tile or zone has an 'explored' timestamp. Initialize to zero. When you visit an area, set the time stamp to Now(). When rendering, a time stamp of 0 means "don't display". A time stamp < Now()-x means display the old remembered stuff, a time step >= Now()-x means to just display it as normal.

The implementation details are up to you.

Looking at your applet, I'm not sure exactly what will be covered by the Fog of War. Hopefully that's stuff being developed. [smile]

Share this post


Link to post
Share on other sites
thanks for the feedback.

i dont have a notion of tiles in the rts. it's all vector based. so theres no concept of tiles really to expire.


Quote:
Looking at your applet, I'm not sure exactly what will be covered by the Fog of War.


I'm not sure if this is a subtle stab at the game's progress or what ;) I'm not an artist, I never claimed it would be beautiful to look at. I'm a developer. I don't have an artist yet, so my concern is to make the underlying engine featureful and robust, and skin on top of it later when I find talented artists.


any other suggestions considering that the game is not tile based?

--Mike

Share this post


Link to post
Share on other sites
Quote:
Original post by nekoflux
Quote:
Looking at your applet, I'm not sure exactly what will be covered by the Fog of War.

I'm not sure if this is a subtle stab at the game's progress or what ;)

No, not intentionally.


Somehow you're going to have to mark areas as recently viewed, historically viewed, and never viewed. Exactly how you do it is up to you.

Option 2: Perhaps you might find a 'viewed pixels' bitmap overlay would be more appropriate. Mark as on/off what has been seen and what is unseen. That could be a black overlay where unseen and the historical view in the 'seen' portions. Then draw the area directly around the few pieces with the full detail.

Option 3: Or you might have the game board as a large 2D bitmap. The displayed background image be black by default, then when a piece moves around it draws the background on that map (the fog-of-war view). After drawing that background, you could draw only what each piece directly sees.

Share this post


Link to post
Share on other sites
1> Work out what is "visible" to your units.
2> Only draw the "visible" things.
3> In areas that are not "visible", draw what was last "visible", and "grey it out" some so the player knows it isn't currently visible.

You can embellish this with two (or more) layers:
1> "static" features which tend not to change.
2> "dynamic" features that tend to change.

"Static" features (like terrain) could grey out "less" than than "dynamic" features do. Or you could simply remove "dyanmic" features.

(Starcraft, for example, greys out buildings and terrain, but erases units, outside of your LOS).

Share this post


Link to post
Share on other sites
hmmm, well i understand what a fog of war is, and i understand that several games have implemented it such that there are multiple layers that get composited into s single image. I should have been more clear.

The problem that I am facing is how to do the sight determination efficiently. The easy way is simply to draw the visible areas that each unit has each turn and comb ine them into a composite image, but that seems horribly inefficient. I am trying to figure out an algorithm that is more efficient. (for example, consider a large group of units that are close together. They will share a view that is almost identical and it will be a waste computing each one individually. Hope that clears up my source of trouble...thoughts?

--Mike

Share this post


Link to post
Share on other sites
Tricky.

For a given unit, you want to be able to quickly determine if there is any point in calculating which pixels it can see.

If you have a quad tree (or a hex tree?) of the area with each node marked as "partial" "full" and "no" sight, you might be able to quickly determine if there are any areas in manhattan/hex view distance that are partial or full, and short circuit the drawing of the field-of-view mask.

Another idea is to have a "coarse cell" grid that keeps track of cells with full coverage, partial coverage and no coverage, and who can see into partial coverage cells. This might reduce the number of bits you would have to flip.

Yet another idea would be to encode the "FOV" map as a RLE of some kind, taking advantage of the fact that FOV areas are contiguous and single-bit. For fast searching of what areas are visible, break the map into cells and RLE each cell.

But really, all I can think of is optimizations of "draw a circle around each unit". As optimizations, the first stage is to implement the naive algorithm and see if it is fast enough. ;)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!