← Yop2D

How to add lights, shadows and a day and night cycle?

Beginner guide · no code

Français · English · Español · Deutsch · Italiano · Português · Русский · 中文 · 日本語

With a few nodes, a game goes from flat to atmospheric: a dark night, a lantern that follows your hero, soft shadows and a sun that sets by itself. Nothing to write: you only choose values. The lights are drawn on the screen (they do not go around walls), which keeps the game fast on every phone.

You need:

Step 1: darken the game

  1. Open the Blueprint and add “Darkness and light mood” after “On Start”.
  2. Choose the darkness: 0 is full day, 100 is pitch black. For a night where you still see the scene, try 85.
  3. Choose the color of the night: a dark blue looks natural, black makes it scarier.
👉 The darkness and the color change smoothly. Use a length of 30 seconds to turn a day into a night, like a sunset.

Step 2: light a torch

  1. Add “Light source (torch, lantern…)” and choose the object that carries the light: a torch, a window, a lantern.
  2. Set the radius (the distance from the center, in pixels), the lighting (100 is normal, up to 300 for a stronger light) and the colored glow.
  3. Choose the flicker: candle for a soft flame, torch for a strong one, flickers for a failing lamp.
  4. The light follows its object. To make a lantern that follows your hero, put a small invisible object on the hero (a child object) and light that object.
👉 With Switching on = Only when it is dark, the light turns on by itself when the night falls and turns off during the day. Use “Turn off the object's light” to turn a light off with a node.

Step 3: add a shadow

  1. Select a character in the scene and open the Inspector, part Appearance.
  2. Tick Shadow under the object: set its strength and its width.
  3. The shadow follows the object everywhere. The node “Shadow under the object” does the same, if you prefer to switch it on during the game.

Step 4: let the day pass

  1. Add “Day and night cycle” at the start of the game.
  2. Choose the length of a full day: 30 to 120 seconds feel alive. Then the starting moment (full day, evening, deep night or dawn) and whether it repeats forever.
  3. Put your lights on Only when it is dark: they turn on at nightfall, all by themselves.
👉 Length 0 stops the cycle where it is. A game on pause freezes the cycle too. To jump to a moment, use “Day and night cycle” again with another starting moment: the example "Day and night village" does it with 5 buttons.

To go further

If it does not work