Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Make a sprite darker  (Read 3920 times)

0 Members and 1 Guest are viewing this topic.

Nice Guy

  • Newbie
  • *
  • Posts: 2
    • View Profile
Make a sprite darker
« 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  :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Make a sprite darker
« Reply #1 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.
Laurent Gomila - SFML developer

Nice Guy

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Make a sprite darker
« Reply #2 on: November 19, 2012, 01:40:00 pm »
Perfect! Thank you so much!  :D

masskiller

  • Sr. Member
  • ****
  • Posts: 284
  • Pointers to Functions rock!
    • MSN Messenger - kyogre_jb@hotmail.com
    • View Profile
    • Email
Re: Make a sprite darker
« Reply #3 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
Programmer, Artist, Composer and Storyline/Script Writer of "Origin of Magic". If all goes well this could turn into a commercial project!

Finally back into the programming world!

 

anything