Cover everything in darkness, except for player and certain objects

I want to make it so that when a scene begins, everything is shrouded by darkness. However, there is a small light surrounding the player and the torches so that the player can see something along the way. How do I do that?

Example would be the night mode in Ghost House and Underwater themes in Super Mario Maker 2. The stage is completely dark in this mode, but the player and some other objects like the Starman, fire, fireballs, Boos, and light blocks are either unaffected by the darkness or surrounded by small light.

Strangely best example i ever found to achieve this is fog of war

And here is what you are asking for
https://games.gdevelop-app.com/game-777efed6-0d90-4660-bbd7-318d31db0183/index.html

To achieve that you need only VisionField
You can/should delete ScoutedArea from scene
image

I also changed Fill opacity of VisionField

But turns out in events sheet there is action that changes opacity so you need to set it to 255 (making above step useless so you either change it here or change in above step and delete this action)

And lastly VisionField have MarchingSquaresBehavior (extension you need to install and add as behavior)

If you wanna go even further add tween behavior to VisionField
Make more or less this

And result will be “breathing” effect on size of light area
2023-06-28_10_39_SJjN95Keek_GDevelop

4 Likes

Amazing! Thanks for the help!

Hey guys. I just wanted to update that I’ve found another way to solve the problem by using the dynamic light feature in GDevelop.

When you create a light object, the engine automatically creates another layer called the Lighting layer, which is where all of the light functions work. To make everything dark, you have to go to the Lighting properties in the Lighting layer and set the ambient color to black (0; 0; 0). Afterwards, you can do anything you want. For example, I made it so that when the stage begins, the player character has a little bit of light surrounding them so that the player always knows where their character is.

The other lights in the image above are the brown lights that indicate where the torches are so that the player doesn’t have to search blindly to where they are, and the blue ambient light above.

example2

This image shows the player getting ready to light one of the torches.

When the torch is lit, it reveals everything around them, including the platforms that weren’t there before, and a purple floating enemy that will kill the player if they touch it.

And here are the codes I used for when the light is summoned or unsummoned:

When the player is able to control the light:

When the light hits a torch:

And when the enemies and platforms are now active (they become inactive if the player lights another torch):

1 Like