Example:

Some methods for 2D Field of Vision suggest scattering out a bunch of raycasts, shotgun style, to see when they’ll collide with walls like so:

evernote1Non-artist’s representation

 

Depending on the amount of resources you can afford to invest, you can make a very nice effect that way. I found that this wasn’t working for me in GameMaker. To keep a decent framerate, I was having to use a very low number of rays, and lowering the precision to unacceptable levels (12 rays only checking for collisions every 8 pixels is far from ideal).

After some research, I came to the conclusion that I could do something else to get the desired effect. Every Update I have the game perform the following algorithm. I start by having all the wall chunks that are on screen (or nearly on screen), check themselves into a global list (or remove themselves if they are not in range):

evernote2Also non-artist’s representation

Once I had all these wall chunks, I would store their corners in a list, to test if they were visible to the player.

Since I have a start point and an end point, I can just do a line collision test from each corner of those wall chunks (I actually ended up doing two parallel line collisions, because there were some clipping errors now and then):

evernote3Still not an artist

From here I sorted the points that I kept, so their angles were in clockwise order (so I could use them to cut out a triangle fan primitive later). Basically made another list of angle-to-player, and then sorted the x-y pairs by their angle in ascending order.

Here are my winning end points:

evernote4-1Can’t even draw a God-damn rectangle

 

To cover the concealed parts of the map, I first fill a screen-sized Surface with black:

evernote4-2No comment

 

Then I cut away a Triangle Fan primitive, using the player as the origin (this is why the points needed to be sorted by ascending angle earlier):

evernote4-3Look, no ruler

 

Finally, I would stamp out a rectangle where the wall chunks actually were, so the player could see what was impeding their vision (hey, we already have a list of walls for that!).

This method works well because I don’t have a lot of large open spaces in my game, you could try adding points along the edges of the screen to your list of points to make it more effective in large open areas.

Well, I hope you found my awful drawings somewhat helpful in explaining this process. I ultimately decided to go with a Fog of War effect because as much as I wanted to surprise the player it felt kind of claustrophobic to use a Field of Vision effect to do so.