Code, demos and ideas.

Fake 2d Lighting with javascript

November 16, 2011

Just started messing with realtime 2d raycasting for lighting today, used a pretty good code example from Heres my version in JS, and a fiddle to play with. If you look at the code youll notice I added a portion to keep track of the closest block per ray so you can light up only that block and not the others. However doing this got me to thinking, this method can be used to make a vision cone for AI. Ive seen this raycasting method used before I just never implemented it myself.. besides my *really* slow implementation for lighting on my canvas terrian.


I might mess with this some more, got a few ideas for a small game or two, but who knows if Ill actually get around to it before finding something else that’s shiny. Feel free to do whatever with the code. Theres a lot of room for optimization.

Figured I might as well post this thing I was messing around with. Same concept but much slower .


Written by Jason Brown Father, Veteran, lover of everything tech.