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

Author Topic: Drawing in class  (Read 2416 times)

0 Members and 1 Guest are viewing this topic.

Jeckie

  • Newbie
  • *
  • Posts: 22
    • View Profile
    • Email
Drawing in class
« 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.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Drawing in class
« Reply #1 on: July 19, 2013, 03:42:25 pm »
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. :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Jeckie

  • Newbie
  • *
  • Posts: 22
    • View Profile
    • Email
Re: Drawing in class
« Reply #2 on: July 19, 2013, 07:32:03 pm »
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.

Gobbles

  • Full Member
  • ***
  • Posts: 132
    • View Profile
    • Email
Re: Drawing in class
« Reply #3 on: July 19, 2013, 07:57:05 pm »
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.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Drawing in class
« Reply #4 on: July 19, 2013, 08:31:46 pm »
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. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Jeckie

  • Newbie
  • *
  • Posts: 22
    • View Profile
    • Email
Re: Drawing in class
« Reply #5 on: July 20, 2013, 09:51:56 pm »
Ok, I'll learn some more c++, but I can't buy any of those books...

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Drawing in class
« Reply #6 on: July 21, 2013, 12:36:06 pm »
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 ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: