SFML community forums

Help => Graphics => Topic started by: Nice Guy on November 19, 2012, 01:31:57 pm

Title: Make a sprite darker
Post by: Nice Guy on November 19, 2012, 01:31:57 pm
Hello. I'm making a tile-based 2D game using SFML2. At the moment I'm working on a light system similar to the one found in Diablo, in which the (tiled) area gets darker the further it is from the player. Is there a way to reduce the light of a sprite? I tried to find information about this but didn't succeed. Something to do with shaders maybe?

I also have another question: how could I make a sprite black n white?

Thank you  :)
Title: Re: Make a sprite darker
Post by: Laurent on November 19, 2012, 01:36:42 pm
Quote
Is there a way to reduce the light of a sprite?
Set its color to gray.
sf::Uint8 light = ...; // 255 = initial brightness, 0 = black
sprite.setColor(sf::Color(light, light, light));

Quote
I also have another question: how could I make a sprite black n white?
There's no built-in function for that, you must apply a black-and-white algorithm manually to all the pixels of the texture. Or do it in a fragment shader, if you want to apply this effect at runtime.
Title: Re: Make a sprite darker
Post by: Nice Guy on November 19, 2012, 01:40:00 pm
Perfect! Thank you so much!  :D
Title: Re: Make a sprite darker
Post by: masskiller on November 19, 2012, 09:19:10 pm
Check the HSL color standard in the wiki, it's a code sample I wrote that has a very complete explanation on how to do crazy things with colors.

Here's the link: https://github.com/SFML/SFML/wiki/Source%3A-HSL-Color (https://github.com/SFML/SFML/wiki/Source%3A-HSL-Color)