SFML Set Alpha Color

Started by
4 comments, last by fastcall22 14 years, 4 months ago
Hi, i have a simple question. How do i set an invisible color in SFML? I load an image and want the color magneta to be invisible.
Advertisement
A quick Google search pulled up the documentation for sf::Image. CreateMaskFromColor looks promising. If not that, you can use an image manipulation program to convert image into a format that supports an alpha channel (such as .png); then convert the magenta color into 0 alpha.
If i would have understood what google told me i wouldn't post here. I already tried with doing this before posting:

Color ColorKey(255 ,0 ,255 ,255);
for (i = 0; i<=5; i++)
Image::CreateMaskFromColor(ColorKey, 0);

Maybe someone can show me what is wrong?.

"C:\Program\CodeBlocks\Projects\Test SFML\main.cpp|98|error: expected `;' before '::' token|"

Edit: When i add a "." instead of "::" i get the program to run:

//Set invisible color
Color ColorKey(255, 0, 255);
for (int i = 0; i<=4; i++){
Image.CreateMaskFromColor(ColorKey, 0);
}

, but the magenta color is still visible.

[Edited by - zippo88 on December 3, 2009 4:48:41 PM]
CreateMaskFromColor is not a static method of the sf::Image class. Therefore, you need to invoke the method on an actual object of the sf::Image class. You do this using . (the dot operator), not :: (the scope resolution operator). That is why changing :: to . in the code you posted works (for compilation purposes).

As far as the magenta color still being visible, I would double check that the RGB values for the color in your image really are 255, 0, 255 as your color key appears to be correct. If you double checked and the RGB values are indeed correct, I recommend posting the code where you declare the sf::Image array (which you have named Image) and the code where you actually draw the image.

Out of curiosity, do you have the following line in your code?
using namespace sf;
ahh that was my problem, although i am sure i changed the color to be magenta several times, but i was having some trouble with it since i'm not used to paint.net
Quote:Original post by _fastcall
you can use an image manipulation program to convert image into a format that supports an alpha channel (such as .png); then convert the magenta color into 0 alpha.


This topic is closed to new replies.

Advertisement