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

Author Topic: Is there a way to change one colour in a sprite?  (Read 6105 times)

0 Members and 1 Guest are viewing this topic.

blueeyedlion

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
Is there a way to change one colour in a sprite?
« 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?


thePyro_13

  • Full Member
  • ***
  • Posts: 156
    • View Profile
Is there a way to change one colour in a sprite?
« Reply #2 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.

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Is there a way to change one colour in a sprite?
« Reply #3 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.
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Is there a way to change one colour in a sprite?
« Reply #4 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 :?:
Laurent Gomila - SFML developer

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Is there a way to change one colour in a sprite?
« Reply #5 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.
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

danman

  • Hero Member
  • *****
  • Posts: 1121
    • View Profile
    • Email
Is there a way to change one colour in a sprite?
« Reply #6 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).
Pointilleur professionnel