# SFML Set Alpha Color

This topic is 3000 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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.

##### Share on other sites
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.

##### Share on other sites
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++)

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++){
}

, but the magenta color is still visible.

[Edited by - zippo88 on December 3, 2009 4:48:41 PM]

##### Share on other sites
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;`

##### Share on other sites
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

##### Share on other sites
Quote:
 Original post by _fastcallyou 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.