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

Author Topic: How do I set transparent color of a sprite image ? [Solved]  (Read 16118 times)

0 Members and 1 Guest are viewing this topic.

JeZ-l-Lee

  • Jr. Member
  • **
  • Posts: 80
    • ICQ Messenger - 223180991
    • MSN Messenger - JeZLee@Live.com
    • AOL Instant Messenger - SLNTHERO@aol.com
    • View Profile
    • http://www.SilentHeroProductions.com
    • Email
How do I set transparent color of a sprite image ? [Solved]
« 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:

Any help would be appreciated!

JeZ+Lee
SLNTHERO@aol.com
Silent Hero Productions(R)
Video Game Design Studio
http://www.SilentHeroProductions.com
JeZ+Lee
Silent Hero Productions(R)
Video Game Design Studio

http://www.SilentHeroProductions.com

Mr. X

  • Jr. Member
  • **
  • Posts: 80
    • View Profile
How do I set transparent color of a sprite image ? [Solved]
« Reply #1 on: February 02, 2009, 10:16:54 pm »
The class sf::Image contains a method called "CreateMaskFromColor".

JeZ-l-Lee

  • Jr. Member
  • **
  • Posts: 80
    • ICQ Messenger - 223180991
    • MSN Messenger - JeZLee@Live.com
    • AOL Instant Messenger - SLNTHERO@aol.com
    • View Profile
    • http://www.SilentHeroProductions.com
    • Email
How do I set transparent color of a sprite image ? [Solved]
« Reply #2 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);
JeZ+Lee
Silent Hero Productions(R)
Video Game Design Studio

http://www.SilentHeroProductions.com

Core Xii

  • Jr. Member
  • **
  • Posts: 54
    • MSN Messenger - corexii@gmail.com
    • AOL Instant Messenger - Core+Xii
    • View Profile
How do I set transparent color of a sprite image ? [Solved]
« Reply #3 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)

Daazku

  • Hero Member
  • *****
  • Posts: 896
    • View Profile
How do I set transparent color of a sprite image ? [Solved]
« Reply #4 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.
Pensez à mettre le tag [Résolu] une fois la réponse à votre question trouvée.
Remember to add the tag [Solved] when you got an answer to your question.

JeZ-l-Lee

  • Jr. Member
  • **
  • Posts: 80
    • ICQ Messenger - 223180991
    • MSN Messenger - JeZLee@Live.com
    • AOL Instant Messenger - SLNTHERO@aol.com
    • View Profile
    • http://www.SilentHeroProductions.com
    • Email
How do I set transparent color of a sprite image ? [Solved]
« Reply #5 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



Making something alittle more graphically advanced now!


JeZ+Lee
SLNTHERO@aol.com
Silent Hero Productions(R)
Video Game Design Studio
www.SilentHeroProductions.com[/url]
JeZ+Lee
Silent Hero Productions(R)
Video Game Design Studio

http://www.SilentHeroProductions.com

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6288
  • Thor Developer
    • View Profile
    • Bromeon
How do I set transparent color of a sprite image ? [Solved]
« Reply #6 on: February 03, 2009, 01:40:37 pm »
Looks nice ;)

You can present your projects in the projects subforum if you like. :)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: