I have created a 2D Tile Based game. The game has a single path that the sprite can move on. I want to create to make the entire screen black except for where the sprite is.

The sprite has commands such as left where he keeps looking left, right where he keeps looking right and move forward where he moves in the direction he is looking. I want to make it such that when he looks left then the tile on the left of the sprites, fog should be removed and so on for all the sides.

How can I do this?


2 Answers 2


As always, you have several ways of doing it:

In any case, add a bool Visible to each tile, and set it to true when it has been discovered. This property decides whether your tile is visible or not. How you save that property entirely depends on your code, only you can answer that.

a) Set the background to black (GraphicsDevice.Clear(Color.Black);) at the beginning of each draw step, and simply don't draw an undiscovered tile.

b) All overloads of SpriteBatch.Draw have a parameter Color, which tints the texture to a certain color, without changing the actual texture in any way. If Visible == false, then you use Color.Black in the Draw method, otherwise you use Color.White.

c) If at some point you want a nicer texture than plain black, you can simply start out with all tiles being the fog tile, and then replace the texture at a visible tile with the one it is supposed to be.

  • \$\begingroup\$ Is there a tutorial that i can have a look at? I have tried this one link but it does not work on xna 4.0 and it isn't for a tile-map. \$\endgroup\$
    – Sigh-AniDe
    Commented Jun 2, 2012 at 15:58
  • \$\begingroup\$ @Sigh-AniDe The tutorial you linked to does something else than what you asked for. You asked for a fog of war that only illuminates a tile adjacent to the player (and maybe the tiles you already visited, you didn't specify that), not in a circular area around the player. If you are asking for a circular area of light, you need to change your question. \$\endgroup\$
    – Hackworth
    Commented Jun 2, 2012 at 17:16
  • \$\begingroup\$ You are right but i used the circular fog of war so i could get a basic understanding of how the fog of war works, but it didnt help at all. \$\endgroup\$
    – Sigh-AniDe
    Commented Jun 2, 2012 at 17:50
  • \$\begingroup\$ @Sigh-AniDe Look, I'm writing my answers based on your questions. I am spending my time to help where I can. I cannot read your mind, so in the future, please ask only what you really want, not something that may or may not help you. I don't know about others, but I hate wasting my time. \$\endgroup\$
    – Hackworth
    Commented Jun 2, 2012 at 18:04
  • \$\begingroup\$ about the circular fog of war, i am just telling you what ive tried to do regarding fog of war. Didnt mean to give you an impression that your answer was a waste of time. I am currently doing more research on how to go about doing it using your methods as i do not understand how to implement it. This is all new to me, its the first game i am developing. \$\endgroup\$
    – Sigh-AniDe
    Commented Jun 2, 2012 at 19:04

To do what you want you need to use combine the char line of sight with the visibility of the tile.

Line of sight

You will use some algorithm to determine which tiles are visible or not at a given time.
There are several algorithms for that, research one suitable for your game type.

Each tile will have three states:

Visibility states

  1. Unknow. This is a tile never saw. You will usually keep it black or otherwise mark it as unknow.
  2. In sight. This tile is in your sight, you can see what type is the tile and its contents. The first time you see it, you flag it as Know.
  3. Know but out of sight. This tile was saw before. You know that type it is but not the contents. You may mark it with some obscuring fog and may or may not show the last know content.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .