Making an advanced lighting system

23

Index

Contributors

Stats

11,341 visits, 26,215 views

Tools

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 3 Jun, 2019. Last updated 24 Jun, 2019

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.

  • 3 Comments

  • Order by
Want to leave a comment? Login or Register an account!
  • This great! Thanks!

  • trying to follow your tuto, great so far but I'm confuse on the page 5:

    OBJECT POOLING and PLACE THE SHADOW screencap don'tseem to show the same nested script.

    On the first one you see the event showcaster>>> pick instance with UID=uid with direct action linked to it and other events following (not sub event) and in the 2nd screenshot you see that the condition showcaster>>> pick instance with UID=uid has some other sub event.. which one is correct?