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

Author Topic: one texture problem  (Read 1651 times)

0 Members and 1 Guest are viewing this topic.

CreaM

  • Newbie
  • *
  • Posts: 36
    • View Profile
one texture problem
« 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: one texture problem
« Reply #1 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.
Laurent Gomila - SFML developer

CreaM

  • Newbie
  • *
  • Posts: 36
    • View Profile
Re: one texture problem
« Reply #2 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.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: one texture problem
« Reply #3 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.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: one texture problem
« Reply #4 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.
Laurent Gomila - SFML developer