Author Topic: Tilemap dynamic lighting (fog of war) help  (Read 2264 times)

0 Members and 1 Guest are viewing this topic.

Offline LemonDrop

  • LV2 Member (Next: 40)
  • **
  • Posts: 26
  • Rating: +4/-0
    • View Profile
    • tin.gy
Tilemap dynamic lighting (fog of war) help
« on: November 15, 2013, 10:55:08 pm »
So I was trying to think of a system to do a sort of fog of war system based on tiles that can be seen by the player (not relatively complex), but was having a hard time doing so. The first idea I had involved having a sort of nested for loop x/y system which would check all the sprites in a diamond shaped area (in a certain order of course) and if it hit a solid tile, abort that row. Sadly mid-coding it I realized it would only work on one axis so I decided the only other way would be to do actual raycasting checks to see if anything is in the way of each "light beam" to a tile (in a diamond area pattern again). I planned it to go something like:

  • Index all (solid) tile coordinates (tile x*8, tile y*8) in a 7x7 area to some temp location. (Square because calculating a diamond is more costly)
  • For each tile in the view diamond loop, use the start and end point of the "line" made from the player to the tile to check if any of the x/y coordinates in the previous step are within 8 pixels of it. (Math behind it: http://stackoverflow.com/a/14554286/2085551)
  • Finally display the ones as they pass the test

As fast as axe is at math however I feel like this many calculations may slow down my frame times too much, so I was wondering if there's some crazy optimized calculator method of "dynamic lighting" or whatever for tile-based games.