On every tick 🔁
Now we're going to see what we need to do on every tick to update the light
First, we obviously need to clear the canvas and paste the light and shadowlight again
Picking
We need to loop through every shadowCaster instance and pick the lights that the given instance is standing next to. I use that to setup a bunch of local variables that I'll use later.
Tint effect
I add a tint effect to the shadowcaster instances as an additional visual cue.
After pasting the shadows I apply the tint, and in case the instance is not inside any light's range, set its tint back to the default tint.
Object pooling
Now I need to pick the shadow instance I'll use. If the object exists in the pool, pick it, else create one, initialise it and use it.
Note that I make use of the create by name feature to be able to create the right sprite instance from the family. If I were to create the family object directly, it would create a random object from the family, which is not the behavior we want.
Place the shadow
Once we have the right shadow instance, we need to place it and resize it.
Choosing the right animation frame
This part will need to be changed to work with your own animation system.
In my animation system, animations are named StateDirection (ie RunUp, IdleLeft, etc). I use that to check if the instance is using that naming convention or not. If it's not, no need to change the animation frame and animation.
If it is, pick the right animation depending on the direction the instance is looking towards, and depending on the angle between it and the light.
Pasting the shadow
No blur
That part is pretty easy. Just paste the shadow.
Blur effect
As explained, we only need to loop through each angle offset and paste the shadow with a lower opacity the larger the angle offset.