SFML community forums

Help => Graphics => Topic started by: The Terminator on July 24, 2012, 07:26:44 pm

Title: Won't let me do this
Post by: The Terminator on July 24, 2012, 07:26:44 pm
For my texture manager I'm trying load a .png file and it keeps giving me an error.

void Engine::loadTextures() {
        if (textureManager->loadTexture("tileset.png")) {
            rw->draw(textureManager->getTexture("tileset.png"));
        }
}

When I'm trying to draw to the renderwindow (rw) it gives me this error: "No matching member function for call to 'draw'

Heres my .h file of my TextureManager class:

namespace Engine {
    class TextureManager {
    private:
        std::map<std::string, sf::Texture> textureList;
       
    public:
        TextureManager();
        ~TextureManager();
       
        bool loadTexture(std::string fileName);
        sf::Texture getTexture(std::string fileName);
       
    };
   
    static TextureManager* textureManager;
}

And .cpp file:

Engine::TextureManager::TextureManager() {
   
}

Engine::TextureManager::~TextureManager() {
   
}

bool Engine::TextureManager::loadTexture(std::string fileName) {
    sf::Texture tempTexture;
   
    if (!tempTexture.loadFromFile(resourcePath() + fileName))
        return false;
       
    textureList[fileName] = tempTexture;
    return true;
}

sf::Texture Engine::TextureManager::getTexture(std::string fileName) {
    return textureList[fileName];
}

Anybody know what the problem is?
Title: Re: Won't let me do this
Post by: Acrobat on July 24, 2012, 07:48:16 pm
try
rw->draw( sf::Sprite(textureManager->getTexture("tileset.png")) );
Title: Re: Won't let me do this
Post by: The Terminator on July 24, 2012, 10:17:10 pm
It works! I can't believe I forgot about loading to a sprite.. lol....
Title: Re: Won't let me do this
Post by: Acrobat on July 25, 2012, 10:17:51 am
btw
sf::Texture Engine::TextureManager::getTexture(std::string fileName) {
    return textureList[fileName];
}
don't copy the texture
Title: Re: Won't let me do this
Post by: eXpl0it3r on July 25, 2012, 10:34:36 am
btw
sf::Texture Engine::TextureManager::getTexture(std::string fileName) {
    return textureList[fileName];
}
don't copy the texture
You could have also told him how to do it correctly (That's what helping is all about). ::)

You should return a reference, like sf::Texture& Engine::...