1
\$\begingroup\$

I'm developing a 2D stealth game but I cannot figure out how to create something like a torch (flashlight) that the enemies hold and look around with.Any help? Also, if relevant, I'm using MonoGame.

\$\endgroup\$
3
  • 2
    \$\begingroup\$ Can you post a picture of what you want it to look like? Are you looking for information on how to illuminate objects around the torch? Or do you want information on how to draw the fire coming out of the torch? (Also, do you mean "torch" in the British sense - like a flashlight - or American sense - like a stick on fire?) \$\endgroup\$ Jan 9 '18 at 6:40
  • \$\begingroup\$ Quick google search (I guess what you are asking for is just a simple lighting, everything is explained well enough for a beginner): 2D lighting \$\endgroup\$
    – Nick
    Jan 9 '18 at 6:57
  • \$\begingroup\$ I've never used it myself but maybe this awesome lighting library would be of interest: github.com/discosultan/penumbra \$\endgroup\$ Jan 9 '18 at 23:48
1
\$\begingroup\$

If I have understood your question correctly, what you want to have is e.g. a "dark map", where you can have a circular area whoch is brighter from the torch.

Now, since I don't really know Monogame, you could fill your screen with a half transparent, dark color over your normal map. Then, you probably could draw a sprite over it with a gradient from the aforementioned color to a fully transparent color. You'd have to use subtractive blending to clear the area from the dark color.

I mean something like that:

Blending effect

This was created using an image editor, I took the image, filled it with a 65% yellow-brownish color, then made a selection around the torch source, deleted it and added a gradient from fully transparent to the previous color. For your game you could also create this image in a pixel editor and then just draw it - either clearing the area below, or using subtractive blending if thats possible in monogame.

For example in JavaFX, you can clear a rectangle of a drawing canvas with the method clearRect(), for reference.

Cheers

\$\endgroup\$
1
  • \$\begingroup\$ This is, of course, a very basic way of getting that effect. It won't stop at obstacles etc. For more complicated effects (not only circular, but e.g. ray casted, you would need a bit more math and proper shaders. Have a look at Stealth Bastard (official webpage is down) for example. \$\endgroup\$
    – Ignatiamus
    Jan 9 '18 at 15:51

Not the answer you're looking for? Browse other questions tagged or ask your own question.