SFML community forums

Help => Graphics => Topic started by: CreaM on May 23, 2014, 09:48:32 am

Title: one texture problem
Post by: CreaM on May 23, 2014, 09:48:32 am
Hello, im trying to draw dozens of sprites of the same texture - but i dont know how (when im using classes and objects) load texture just once and use it for all my sprites...
I tried static texture but compilator doesnt like it:
1>project2.obj : error LNK2001: unresolved external symbol "private: static class sf::Texture solder::imageSource" (?imageSource@solder@@0VTexture@sf@@A)
1>C:\Users\.\documents\visual studio 2010\Projects\project2\Release\project2.exe : fatal error LNK1120: 1 unresolved externals

here is  my code:
class car{
public:
        void set_up(){
                if(!source.loadFromFile("Untitled.png"));
        }
        car(){
                sprite.setTexture(source);
        }
        ~car(){}

private:
        static sf::Texture source;
        sf::Sprite sprite;
}
 
thans for help.
Title: Re: one texture problem
Post by: Laurent on May 23, 2014, 10:02:06 am
Google "c++ static member".

Do you realize we can't teach you C++ on this forum? At some point you'll have to learn how to find things by yourself. Books, tutorials, Google, ... they are all your friends. You'll progress much better than by coming here everyday to ask a basic C++ question.
Title: Re: one texture problem
Post by: CreaM on May 24, 2014, 12:19:02 pm
ok, I find out that static member HAVE TO be defined. When I use classic c++ variables it's clear, but how can i define sf::Texture outside the main(){}?(by definition of texture i mean something like .loadFromFile("")
Thanks for replies.
Title: Re: one texture problem
Post by: Nexus on May 24, 2014, 12:40:41 pm
A function call is not a definition, and one does usually not just define objects "outside main", but rather in classes with an appropriate area of responsibility.

Seriously, read a C++ book. Your terminology is so wrong that I have no idea what you're actually asking, let alone how to fill the knowledge gaps in a few sentences.
Title: Re: one texture problem
Post by: Laurent on May 24, 2014, 11:08:48 pm
car.hpp

class car
{
    static sf::Texture source;
};

car.cpp

sf::Texture car::source;

Doesn't teach you anything, but at least you've got the solution and you'll stop asking... for now.