How do I create directional light?

Hi guys,

Does anyone know of a simple way of creating a directional light, like a flashlight? I am able to use the normal lighting method however I want my character to change it light source. So for example, they hold a wooden shaft that is on fire and I can get this to light up the areas nicely. However, I want the player to be able to use a flashlight, but I can get the light to function how it would when using a flashlight. Is it possible?

Many Thanks.

2.5 methods that I know of.

With lighting system:

  1. Add all objects to a “Dark” object group.
  2. Set the scene background to black.
  3. Create a light object and give it a light texture in the shape you want. (Remember that rotation acts as if due east/right is the “0” point. So make sure your texture faces that way)
  4. Attach the light object to the position of the player you want the flashlight to move with.
  5. Install the sprite masking extension.
  6. Add an event with the mask action, to mask all “Dark” objects with the light object.

This method will have all objects be hidden unless they’re in contact with the light projected by the light texture. Things blocked by light obstacles will be left in darkness.

Manual lighting A - for low resolution games:

  1. Create a large black sprite with a transparent center in the shape you want. This must be larger than your game resolution (roughly by 3x), so it won’t work if your game is above ~640x640 resolution, as then it’d require a sprite over 2000x2000.
  2. Place it on a layer above your main game layers (but below the UI).
  3. Ensure the cameras on this layer are moved with the other layers.
  4. Set up events to position the center of this object onto whatever point on your player you want it to attach to.
  5. The black sprite will hide everything that isn’t in the transparent spot in the center. The larger-than-window sprite size is so your player character can go all the way to each corner of the screen and still be hiding the objects.

Manual method B:
This is basically the inverse of the above, using the sprite masking system.

  1. Make an sprite object the shape of the flashlight beam you want.
  2. Add all objects to be hidden to a “Dark” group.
  3. Set the scene background to black in color.
  4. Attach the light object to the position of the player you want the flashlight to move with.
  5. Install the sprite masking extension.
  6. Add an event with the mask action, to mask all “Dark” objects with the light object.

This method will show objects behind walls if the flashlight beam is over them.

2 Likes