Okay thank you, i now use a texture manager to keep load textures !
someone else is looking for the solution :
TexturesManage.hclass TextureManager
{
private:
/* Array of textures used */
std::map<std::string, sf::Texture> textures;
public:
void loadTexture(const std::string& name, const std::string& filename);
sf::Texture& getRef(const std::string& texture);
TextureManager(){}
};
TexturesMnager.cpp#include <SFML/Graphics.hpp>
#include <map>
#include <string>
#include "TexturesManager.h"
void TextureManager::loadTexture(const std::string& name, const std::string& filename) {
sf::Texture tex;
tex.loadFromFile(filename);
this->textures[name] = tex;
return;
}
sf::Texture& TextureManager::getRef(const std::string& texture) {
return this->textures.at(texture);
}
Game.h#include "Header.h"
#include "TexturesManager.h"
using namespace sf;
using namespace std;
class Game {
private:
void loadTexture();
Sprite* createSprite(string textureName);
public:
RenderWindow window;
TextureManager texmgr;
class Game(VideoMode VideoMode, string& title);
void _run();
};
Game.cppvoid Game::loadTexture() {
texmgr.loadTexture("blabla", "Sprites/blabla.png");
}
Sprite* Game::createSprite(string textureName) {
sf::Sprite* sprite = new Sprite;
sprite->setTexture(this->texmgr.getRef(textureName));
return sprite;
}
and to use functions :
void Game::_run() {
this->loadTexture();
Sprite randomName = this->createSprite("blabla");
}