Hello!
Soo, my skills are down to storing dynamic Font objects in a linked list and letting it shoot sprites. That is nice.
Now I wanted to store Textures in a std::map. I used a std::String as key and an unique pointer to a sf::Texture as the value.
std::map<std::string, std::unique_ptr<sf::Texture>> textures;
textures["poop"] = loadTexture("res/kugel.png");
sf::Sprite obj;
std::map<std::string, std::unique_ptr<sf::Texture>>::iterator it = textures.find("poop");
obj.setTexture(*(it->second));;
Results not in the Texture but in a big white plane.
Or, more specific, if I put view.zoom(1.01) in the update loop, you begin to see a white line.
Why a white line and not the texture???
Am I using the map wrong? Am i too dumb for object oriented programming?
Because:
I also tried (first, actually) to make my own player class which inherits from sf::Sprite.
class poop : public sf::Sprite {
public:
poop(std::map<std::string, std::unique_ptr<sf::Texture>> textures){ //
score = 0;
lives = 3;
std::map<std::string, std::unique_ptr<sf::Texture>>::iterator it = textures.find("poop");
setTexture(*(it->second));;
std::cout << getTexture()->isSmooth();
}
Funfact:
THIS DOES NOT WORK
I dont even see a white screen this time. I just see black nothingness.
Its almost as I didnt even set a texture. Still, I get '0' for the isSmooth() - that does mean I set the texture, or does it?
I pass the map via move as it is supposed to be since you cant copy UNIQUE pointers (learned it the hard way)
poop mPlayer(std::move(textures));I really have no clue why the first thing does not work and furthermore why the own-class-thing does not work I mean I give the adress of the beginning of the wanted value (sorted to key "poop" which is a texture) to the sprite object WHY does that not work?
And where is the difference if I am now doing it in my own class that inherits from sprite? It is indeed inherited as public so that shouldnt be the problem either?
Please I think all my question are quite dumb I have no idea what im doing so maybe if you show me how it is done right maybe I know how it is right too in the future maybe I could learn from it.
Im thanking you very much for reading this
~Cron
---
Edit1:
If I exclude the map and try to set the Texture via loadTexture directly, I still only get a white image, but this time it has the rectangular size of the original image and is centered nicely in the middle of the screen (where it should be)
sf::Sprite obj;
obj.setTexture(*loadTexture("res/kugel.png"));;
std::unique_ptr<sf::Texture> loadTexture(std::string filename) {
std::unique_ptr<sf::Texture> texture(new sf::Texture());
if (!texture->loadFromFile(filename))
throw std::runtime_error("ResourceHolder::load - Failed to load " + filename);
return texture;
};
I am doing something terribly wrong aint I
Edit2
I modifed it to THIS:
obj.setTexture(*loadTexture("res/kugel.png"));;
sf::Image f = (obj.getTexture()->copyToImage()) ;
std::cout << f.getPixel(1,2).toInteger();
it resulted in my PC to stop working for 2 Minutes after finally throwing a seg fault.
(i doubt you need this inform. but im runnin Ubuntu 18.04 and SFML Vers. is (idk downloaded it somwhere last month)
So Map is prob. fine, but why isnt loadTexture???