What we need
On one hand, we need a set of objects inside a container for the light, and we need to setup a family for the shadows.
Light🔦
Objects
We need four objects inside a container
- LightSource Sprite
- The sprite that is going to be used as the base for the light, and will contain every instance variable
- ShadowLight
- Used to cast shadows from scenery objects
- Shadow DrawingCanvas
- This is the canvas that will be used to render the light and the shadows
- LightCircle Sprite
- The sprite that contains the animation for the light circle.
This is the sprite I used for the light circle:
Note that you can add multiple frames to the animation, or even multiple animations, and you can add a Sine behavior to add some wavy movement.
Instance variables
Here is the list of every instance variable I used for the light source.
- radius
- The light radius in pixels
- colorR
- Color red property from 0 to 255
- colorG
- Color green property from 0 to 255
- colorB
- Color blue property from 0 to 255
- minSizeMult and maxSizeMult
- The shadow's height varies depending on the distance from the center, these values control the minimum and maximum size multipliers for the shadow
- Sharpness
- The light's sharpness, 0 produces very blurry shadows, 100 produces sharp shadows
- BlurMinAngle and BlurMaxAngle
- The shadow blur's angle depends on the distance from the center, these values control the minimum and maximum angle of the blur
- strength
- The light's opacity from 0 to 100
- Shivering
- Whether to activate the light circle's sine behavior, and add a little bit of shivering
- ShiverPeriod
- The sine behavior's period
- ShiverMagnitude
- The sine behavior's magnitude
Shadow Caster Family
The family needs a ShadowCaster behavior and a few instance variables. Whether the shadow caster behavior is enabled will define whether the family will cast a ShadowLight shadow or a normal shadow.
Here are the needed instance vars
- isShadow
- Wether the current instance is a shadow instance or not.
- masterUID
- The parent Shadow Caster object of that shadow.
- destroy
- Destroying objects in C3 happens at the end of the frame, this variable is used to tag shadows that need to be destroyed so they don't get picked during that frame.
- initOpacity
- Used to store opacity before rendering the blur effect and restoring it after.