SFML community forums

Help => Graphics => Topic started by: JeZ-l-Lee on February 02, 2009, 09:46:46 pm

Title: How do I set transparent color of a sprite image ? [Solved]
Post by: JeZ-l-Lee on February 02, 2009, 09:46:46 pm
Hi,

I am new to S.F.M.L.

I made a small demo that creates a window and displays a sprite image.
How do I set the transparent color of a sprite ?
I am loading a JPG image file into the Sprite.

Please look at this screenshot:
(http://silentheroproductions.com/images/SFML_Demo_02-02-2009.gif)
Any help would be appreciated!

JeZ+Lee
SLNTHERO@aol.com
Silent Hero Productions(R)
Video Game Design Studio
http://www.SilentHeroProductions.com
Title: How do I set transparent color of a sprite image ? [Solved]
Post by: Mr. X on February 02, 2009, 10:16:54 pm
The class sf::Image contains a method called "CreateMaskFromColor".
Title: How do I set transparent color of a sprite image ? [Solved]
Post by: JeZ-l-Lee on February 02, 2009, 10:48:41 pm
Hi, I tried CreateMaskFromColor, but it is not working for me...
Please help!

Code: [Select]

// Load a sprite to display
sf::Image Image;

if (!Image.LoadFromFile("cute_image.jpg"))
return EXIT_FAILURE;

//-----------------------------------------------------------------
// Transparent color of JPG image file "Image" (green)
Image.CreateMaskFromColor(sf::Color(0, 255, 0, 0), 0);
// NOT WORKING ?????
//-----------------------------------------------------------------

sf::Sprite Sprite(Image);
Title: How do I set transparent color of a sprite image ? [Solved]
Post by: Core Xii on February 03, 2009, 01:30:10 am
Please note that JPEG is a lossy compression. There may indeed not be a single (0, 255, 0) pixel in that entire image. Use PNG instead. Also, the alpha component is zero... as far as I know JPG doesn't support alpha, so such an invisible color doesn't exist. It should probably be (0, 255, 0, 255)
Title: How do I set transparent color of a sprite image ? [Solved]
Post by: Daazku on February 03, 2009, 02:17:07 am
It is simple than that....

It's not: sf::Color(0, 255, 0, 0)

It is sf::Color(0, 255, 0, 255) or sf::Color(0, 255, 0) XD.
Title: How do I set transparent color of a sprite image ? [Solved]
Post by: JeZ-l-Lee on February 03, 2009, 03:49:36 am
Quote from: "Core Xii"
Please note that JPEG is a lossy compression. There may indeed not be a single (0, 255, 0) pixel in that entire image. Use PNG instead. Also, the alpha component is zero... as far as I know JPG doesn't support alpha, so such an invisible color doesn't exist. It should probably be (0, 255, 0, 255)


GOT IT WORKING, thanks!

This is my previous work using SDL(R)...
TetriCrisis 100%[TM] Version 5.9 Remix
For P.C. Windows(R) computer systems
http://www.silentheroproductions.com/TetriCrisis100PercenT.htm

(http://www.silentheroproductions.com/images/PC_Windows_TetriCrisis_100Percent_Title.gif)(http://www.silentheroproductions.com/images/PC_Windows_TetriCrisis_100Percent_InGame.gif)

Making something alittle more graphically advanced now!


JeZ+Lee
SLNTHERO@aol.com
Silent Hero Productions(R)
Video Game Design Studio
www.SilentHeroProductions.com[/url]
Title: How do I set transparent color of a sprite image ? [Solved]
Post by: Nexus on February 03, 2009, 01:40:37 pm
Looks nice ;)

You can present your projects in the projects subforum if you like. :)