Jump to content
  • Advertisement
Sign in to follow this  
zippo88

SFML Set Alpha Color

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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]

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
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.


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!