
GameMaker Cookbook
By :

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.
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).
Open obj_spotLight
and add a Create event.
Drop a code block in the Actions box and enter the following code:
lightStrength = 1;
Add...
Change the font size
Change margin width
Change background colour