Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Won't let me do this  (Read 1666 times)

0 Members and 1 Guest are viewing this topic.

The Terminator

  • Full Member
  • ***
  • Posts: 224
  • Windows and Mac C++ Developer
    • View Profile
Won't let me do this
« 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?
Current Projects:
Technoport

Acrobat

  • Full Member
  • ***
  • Posts: 153
    • View Profile
Re: Won't let me do this
« Reply #1 on: July 24, 2012, 07:48:16 pm »
try
rw->draw( sf::Sprite(textureManager->getTexture("tileset.png")) );

The Terminator

  • Full Member
  • ***
  • Posts: 224
  • Windows and Mac C++ Developer
    • View Profile
Re: Won't let me do this
« Reply #2 on: July 24, 2012, 10:17:10 pm »
It works! I can't believe I forgot about loading to a sprite.. lol....
Current Projects:
Technoport

Acrobat

  • Full Member
  • ***
  • Posts: 153
    • View Profile
Re: Won't let me do this
« Reply #3 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

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10820
    • View Profile
    • development blog
    • Email
Re: Won't let me do this
« Reply #4 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::...
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/