1
Graphics / My texture holder gets deleted although still in scope
« on: June 13, 2019, 04:37:30 pm »
So I'm new to SFML. I read a lot of post, but I really don't get it.
I wrote an texture holder:
And I tried to load a sprite with it in different ways....
For example:
I always get the white box being drawn. And I really dont get why the texture_holder is getting deleted.
BTW type is an enum.
I hope somebody can help me solve my issue!
I wrote an texture holder:
Quote
class tile_texture_holder {
private:
sf::Texture tx;
public:
tile_texture_holder(type a) {
switch (a) {
case type::desert:
tx.loadFromFile("C:/Users/Andreas/source/repos/conquer/Media/desert.png");
break;
case type::grass:
tx.loadFromFile("C:/Users/Andreas/source/repos/conquer/Media/grass.png");
break;
case type::mountain:
tx.loadFromFile("C:/Users/Andreas/source/repos/conquer/Media/mountain.png");
break;
case type::water:
tx.loadFromFile("C:/Users/Andreas/source/repos/conquer/Media/water.png");
break;
}
}
sf::Texture ret_texture() {
return tx;
}
~tile_texture_holder() {
std::cout << "///////////////////////HOLDER DELETED!!!/////////////////////" << std::endl;
}
};
And I tried to load a sprite with it in different ways....
For example:
Quote
tile_texture_holder t(type::desert);(in the same function, where I draw the sprite)
sf::Sprite s;
s.setTexture(t.ret_texture());
I always get the white box being drawn. And I really dont get why the texture_holder is getting deleted.
BTW type is an enum.
I hope somebody can help me solve my issue!