sfml, when loading images/textures ignore background color!?

Started by
2 comments, last by Serapth 11 years, 6 months ago
Hello.
What i am trying to do is draw "Hero.png" 50x50 image to screen.
Problem is that i don't know how to ignore one color, so it does not draw a square of pink(color i use for background on "Hero.png" around my character. Therefore make the (255,0,255) color transparent on my sprite.

I cant find a function to do this in sfml.

in SDL the function is something like

//Set all pixels of color R 0, G 0xFF, B 0xFF to be transparent
//SDL_SetColorKey( optimizedImage, SDL_SRCCOLORKEY, colorkey );

//int SDL_SetColorKey(SDL_Surface *surface, Uint32 flag, Uint32 key); This is definition

SDL_SetColorKey(MyImage,
SDL_SRCCOLORKEY,
SDL_MapRGB(Screen->format, 255, 0, 255);

Advertisement
Why not open up your favorite photo editing program (paint.net is free and will do this), go to the magic wand tool (or use an eraser if you can't get paint.net) and select the pink, delete it. Unless your using MS Paint, it should be transparent when you save it. Why you'd use pink I don't know. If you don't have a magic wand here's how:

Use an eraser and delete all the pink. In SFML, you really can't do this without writing your own special and pointless line of code. However, I highly reccomend paint.net, because it makes doing this extremely easy.
EDIT:
The magic wand is a photo editing tool, google it.

I'm a game programmer and computer science ninja !

Here's my 2D RPG-Ish Platformer Programmed in Python + Pygame, with a Custom Level Editor and Rendering System!

Here's my Custom IDE / Debugger Programmed in Pure Python and Designed from the Ground Up for Programming Education!

Want to ask about Python, Flask, wxPython, Pygame, C++, HTML5, CSS3, Javascript, jQuery, C++, Vimscript, SFML 1.6 / 2.0, or anything else? Recruiting for a game development team and need a passionate programmer? Just want to talk about programming? Email me here:

hobohm.business@gmail.com

or Personal-Message me on here !


Why not open up your favorite photo editing program (paint.net is free and will do this), go to the magic wand tool (or use an eraser if you can't get paint.net) and select the pink, delete it. Unless your using MS Paint, it should be transparent when you save it. Why you'd use pink I don't know. If you don't have a magic wand here's how:

Use an eraser and delete all the pink. In SFML, you really can't do this without writing your own special and pointless line of code. However, I highly reccomend paint.net, because it makes doing this extremely easy.
EDIT:
The magic wand is a photo editing tool, google it.


Well if that is the case ok then. And thank you!
Already edit all my images. Did it with gimp...
Again thanks you very much on fast reply.
If you already have images keyed to a certain color, you can set that color to be transparent using createMaskFromColor()

http://www.sfml-dev.org/documentation/2.0/classsf_1_1Image.php#a22f13f8c242a6b38eb73cc176b37ae34

This topic is closed to new replies.

Advertisement