gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > help: "Fog of War" technique

#16125 - snorman - Mon Feb 09, 2004 3:40 am

Hi,
I'm fairly new to GBA development so I thought I'd ask these question here:

1. What is the best way to achieve a fog-of-war type effect? I'm currently writing a turn-based strategy game where each unit has a certain field of vision (the game currently runs in tile mode 0). Anything not in that field of vision should be greyed out. I want this to be a transparency effect and not a "blanking out" effect, so that you can still see the terrain...it's just darker.

2. Simirarly, when I select a unit, I'd like to overlay some type of display effect which indicates the unit's movement range...I'm assuming this could be acheived similarly to (1).

Any help or ideas would be appreciated!
Sean.

#16126 - poslundc - Mon Feb 09, 2004 5:08 am

snorman wrote:
1. What is the best way to achieve a fog-of-war type effect? I'm currently writing a turn-based strategy game where each unit has a certain field of vision (the game currently runs in tile mode 0). Anything not in that field of vision should be greyed out. I want this to be a transparency effect and not a "blanking out" effect, so that you can still see the terrain...it's just darker.


If the field of vision is a simple, convex polygon (ie. a circle, ellipse, hexagon or similar simple shape) then it would probably be most practical to use a window and dynamically change the window's settings each scanline during HBlank. There are various tutorials on how to do this, or you can search the forums, but be warned that this is an intermediate-level technique on the GBA and may prove difficult if you're just starting out. This technique has the advantage that you can easily change the radius of the effect to animate it or give different amounts to different units.

If the field of vision is a more complicated shape but relatively small and unchanging, you might want to represent it with a sprite and use a sprite window.

If, on the other hand, the visible area is dynamic (such as in games like War Craft) you'd be better off using a text background to represent what areas can be seen and what areas are obscured.

Once you've determined your method, use the alpha-effects register to darken the relevant backgrounds, sprites, etc. by 50% and then apply the effect to outside the window (if using the first two methods) or if using the third method then set it to alpha blend 50% and then blend the text background on top with everything else.

Quote:
2. Simirarly, when I select a unit, I'd like to overlay some type of display effect which indicates the unit's movement range...I'm assuming this could be acheived similarly to (1).


Again, this depends on how you want it to appear on the screen. Do you want arrow-shaped sprites, or do you want another "fog of movement"? The thing to keep in mind is that you can only use one set of alpha effects at a time, so if you want it semi-transparent you will either have to do something compatible with your previous effect (which is very tricky if you're doing the window method) or use another technique like toggling a sprite/background on and off every other frame to generate a sort of flickering transparency.

Good luck,

Dan.

#16130 - snorman - Mon Feb 09, 2004 1:20 pm

Thanks for the quick reply! I will definately look into these techniques...

One quick question first: Is is possible to use alpha-blending on individual tiles in tile-mode (I don't know much about alpha blending yet...)? For example, I was thinking I could use two backgrounds...one for my map, and another which just consists of black tiles. Then, I would set the black-tiled background to a higher priority and enable alpha-blending on all tiles in it except for those within the field of vision?

Quote:
If, on the other hand, the visible area is dynamic (such as in games like War Craft) you'd be better off using a text background to represent what areas can be seen and what areas are obscured.


Yes, something along these lines is what I had in mind...would this be done similarly to the idea I suggested above?

Thanks!
Sean.

#16132 - FluBBa - Mon Feb 09, 2004 2:46 pm

I suspect that you want to change the "color" of individual tiles, right?
So that is exactly what you should do, if you make your background of 16 color tiles you can just change the palette each tile have, if you have 8 different palettes for the background you can have 8 copies with different luma or color.
Or you can use 2 BGs, one which you fill with black (or grey) where you should mark the map and use transparency.
_________________
I probably suck, my not is a programmer.

#16133 - poslundc - Mon Feb 09, 2004 3:27 pm

Or you can just swap different tiles in and out of the tilemap. If an 8x8 square becomes visible, swap in an empty tile where there was a totally black tile. You can give tiles different shapes in order to create a transition from the light to dark, eg. you can have a tile that has the upper-right half dark and the bottom-left half empty to create a diagonal line between light and dark.

Dan.