SFML community forums
Help => Graphics => Topic started by: Jeckie on July 19, 2013, 02:17:13 pm
-
I want to put all my drawings in separated file.
Can I do that?
How to do that?
I want all my logic and events in main.cpp.
But drawing in one class named eg Drawing, but I want that class to be in separated file.
-
Maybe by learning C++ in the first place?
SFML requires that you have a good understanding of C++. ;)
Here's a good list with good C++ books (http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). :)
-
I have a good understanding of c++.
Just I have always been using class in main.cpp not in separated file.And my question is how to draw everything in there.
-
Without seeing what your doing with your classes it's hard to say how you should handle Drawing code in another file. Normally you would have objects in different files (For example, my Entity class is Entity.h and Entity.cpp and my Entity class handles Updating and Drawing all of the entities).
Maybe provide an example of how you are currently handling your classes? It might give us a better idea to help with.
-
I have a good understanding of c++.
Just I have always been using class in main.cpp not in separated file.And my question is how to draw everything in there.
You had never the need to use multiple files with C++ and don't understand how to separate declarations and definitions, than I know, that your knowledge is lacking on some important features of C++. It's not bad or anything, but it's also not helpful not wanting to read it up in a C++ book that actually explains it. ;)
It's rather simple: Declarations belong into the header file (in C++ preferably with the ending .hpp), while the definitions belong into the source file (.cpp). Every file that wants to use the class/functions needs to include the header file, even the source file that holds the definitions. To prevent multiple inclusions and thus multiple declarations of a class/function one should always add include guards to the header file. The way to do this, that is supported by the C++ standard, is to use #ifndef #define #endif pre-processor commands.
Any good C++ book would cover that. ;)
-
Ok, I'll learn some more c++, but I can't buy any of those books...
-
Maybe you can borrow them from a library?
Otherwise, Thinking in C++ is available as a free e-book, you could have a look at that ;)