I'm interested in knowing the techniques on how 2D games hide tiles that are behind walls.

This is a really old MMO that is probably the easiest example to show what I'm asking.

enter image description here

Here you can see all the tiles apart from inside the two buildings

enter image description here

But enter the building and let the door close, and you can see only what's inside.

enter image description here

Stand beside or IN the doorway, and you can see inside and out.

What techniques should I look into to achieve an effect like this?

EDIT: A video of a similar game that shows the effect also, skip through parts and you'll get the idea: https://www.youtube.com/watch?v=ujwQ0-gNQ64

  • \$\begingroup\$ If you're looking for a more detailed answer, you should describe better what you're trying to achieve (maybe you're looking for more precise line of sight algorithms?). Otherwise you should consider marking the answer as accepted. \$\endgroup\$
    – Liuka
    Jan 15, 2020 at 14:26

1 Answer 1


The simplest implementation is for your Tile class to have two members: visible and opaque. Optionally, but a very useful third member is solid.

  • visible: Is the tile currently visible by line of sight to the player?
  • opaque: Does this tile block visibility of the tiles behind it?
  • solid: Does this tile block movement?

If a tile is not visible it should not be drawn. A tile can block movement even if it isn't visible.

Doors flip their opaque and solid members as their state changes.

  • Open: opaque = false; solid = false;.
  • Closed: opaque = true; solid = true;.

By running your line of sight algorithm in every direction you can easily determine what tiles the player can see and therefore which tiles should be drawn.

If you want a floodfill look-and-feel you can use light propagation techniques a la Minecraft to tell if an area is enclosed or outdoors or needs to be visible and if the player is currently within such an area. If they are, only draw the tiles visible to the player.

  • \$\begingroup\$ Thanks for your answer and insights! The game in question is using some kind of flood fill on-the-fly technique to hide all tiles onscreen that are behind a wall. I've attached a video to show the effect in motion, notice at 0:38 when he comes around the building, part of the outside tiles that are hidden suddenly open up. \$\endgroup\$
    – Manshoe
    Jan 6, 2020 at 18:22

You must log in to answer this question.

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