Lighting objects with a spot light
In the previous recipe, we were able to illuminate an entire room with a perfectly even light with the push of a button. In this case, that button was the spacebar and not an actual light switch, but you get the idea, right? Now, what if you don't want to light up the entire room at once? What if you want to shine a light on a smaller area, leaving the rest of the room in cold, scary darkness? Well, you're in luck! Let's take a look at how to create a mouse-controlled spotlight to investigate a dark scene.
Getting ready
We're going to continue from the scene that we created previously, so if you haven't finished it, now would be a good time. You'll also need a spot light sprite (spr_spotLight
), which should be nothing more than a white circle and a spot light object (obj_spotLight
, but do not assign the sprite to it).
How to do it
Open
obj_spotLight
and add a Create event.Drop a code block in the Actions box and enter the following code:
lightStrength = 1;
Add...