SFML community forums

Help => Graphics => Topic started by: blueeyedlion on June 22, 2011, 10:34:07 pm

Title: Is there a way to change one colour in a sprite?
Post by: blueeyedlion on June 22, 2011, 10:34:07 pm
If I have a sprite that is blue and green, is there any way to change all the blue pixels to red?
Title: Is there a way to change one colour in a sprite?
Post by: Lo-X on June 22, 2011, 11:06:09 pm
Maybe with GetPixel

Doc : http://www.sfml-dev.org/documentation/2.0/classsf_1_1Sprite.php#afc959f1195fef7402e01fe5d5f611bdf (SFML 2)
Title: Is there a way to change one colour in a sprite?
Post by: thePyro_13 on June 23, 2011, 04:37:28 pm
You can use setcolor() to change the sprites hue.

Otherwise you'll need to edit the image itself. sprite::getpixel is read only, so it won't be much hel if you want to actually change the colour.

Using image:: getpixel/setpixel

or by copying the result of GetPixelsPtr ()

altering it and then reapplying it to the image with loadfrompixels()

Keep in mind that editing image like this is pretty slow, so you don't want to be doing this every frame. In most cases, simply having two different images should suffice.
Title: Is there a way to change one colour in a sprite?
Post by: Groogy on June 23, 2011, 04:41:22 pm
It's planned to be implemented for SFML2
https://github.com/SFML/SFML/issues/1
Should let you change color on specific parts of a sprite with some imagination without changing the image.
Title: Is there a way to change one colour in a sprite?
Post by: Laurent on June 23, 2011, 05:00:27 pm
Quote from: "Groogy"
It's planned to be implemented for SFML2
https://github.com/SFML/SFML/issues/1
Should let you change color on specific parts of a sprite with some imagination without changing the image.

Rendering masks will be used to clip rendering to a certain rectangular region of the render target, I don't see how it could be used to replace a color in a sprite :?:
Title: Is there a way to change one colour in a sprite?
Post by: Groogy on June 23, 2011, 07:18:14 pm
Quote from: "Laurent"
Quote from: "Groogy"
It's planned to be implemented for SFML2
https://github.com/SFML/SFML/issues/1
Should let you change color on specific parts of a sprite with some imagination without changing the image.

Rendering masks will be used to clip rendering to a certain rectangular region of the render target, I don't see how it could be used to replace a color in a sprite :?:


Well I said by being creative, you clip away from the source sprite the part you want to recolour, then you clip away everything else in the "colour" sprite and draw it on top with a different hue set. :)

Or wait, just noticed you said rectangular, it was definitely not what I imagined what mask would be. I was thinking like how it works in Photoshop.
Title: Is there a way to change one colour in a sprite?
Post by: danman on June 23, 2011, 07:24:22 pm
groogy : for the photoshop case it's better to use a per-pixel mask (a image that mask another one, somebody has already implement that on the forum, but i forgot who).