I don't know what all that code does. :o
I'll just give a simple example.
There are two methods to have transparent sprites.
1: Use an image editor that supports exporting transparency. I use transparent png's.
2: (Hardly very reasonable but usable) Use sf::Image and two for loops to remove the specified color. Then load that image into the texture. I find this useful for removing a color that image editors can't completely remove correctly.
How to use sf::image for that:
sf::Image image;
image.loadFromFile("image.bmp");
for(int x=0;x<image.getSize().x;x++)
{
for(int y=0;y<image.getSize().y;y++)
{
if(image.getPixel(x,y)==sf::Color::Yellow)
{
image.setPixel(x,y,sf::Color::Transparent);
}
}
}
sf::Texture texture;
texture.loadFromImage(image);
Sprite sprite;
sprite.setTexture(texture);
If you have a single color for transparency, you can actually use SFML's built-in createMaskFromColor function (https://www.sfml-dev.org/documentation/2.6.1/classsf_1_1Image.php#a22f13f8c242a6b38eb73cc176b37ae34) on sf::Image.
sf::Image image;
if (!image.loadFromFile("image.bmp"))
{
return -1;
}
image.createMaskFromColor(sf::Color(255, 132, 66));
Yes, you'd have to do that for every image that has a colored background.
Alternatively, what Me-Myself-And-I suggested and what I'd do as well, is to use an image program to export a true transparent background stored in a PNG.