Terraria like 2D block based lighting,Terraria like block based lighting

I am currently working on a 2D survival game sandbox similar to terraria and I was wondering how I should go about implementing lighting. I have a lighting system in the game right now but it looks bad, it’s very glitchy, and it’s really bad for performance. (Drops my fps to 30.) I was wondering how I would implement a better lighting system.,How would I go about adding lighting to my 2D terraria like sandbox game. I have a lighting system right now, but it doesn’t look very good and it’s very glitchy and it’s bad for performance. I was wondering how I would make a better system for lighting?

I don’t know what lighting system you’re using or what your experience with coding is like, but I think Terraria and other similar games use flood-fill lighting. Instead of looking at every single block on screen and evaluating how much light is hitting it by checking each light source, you go through each light source one by one, find which block it is on, and propagate the light out to each adjacent block, and recursively for each of those blocks until there is no more light. This way the light will curve around edges and add light value to blocks that have already been lit by a different light source.