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

Author Topic: Derive from sf::Drawable?  (Read 1485 times)

0 Members and 3 Guests are viewing this topic.

programmerGuy

  • Newbie
  • *
  • Posts: 3
    • View Profile
Derive from sf::Drawable?
« on: August 07, 2013, 10:29:53 pm »
The question of whether you should derive a class that draws something from sf::Drawable or give it a separate draw function has already been asked before.

This:
window.draw(menu)

or:
menu.draw(window)

However, I haven't seen this discussion for SFML 2.0 and higher. In SFML 1.6 the sf::Drawable class had things like:
- set/get position
- set/get rotation
- set/get scale
- set/get color
- set/get blend mode

And if it made since to have these in your class then you would derive from sf::Drawable, but now(in 2.0+) the drawable class just has a single draw function.

So should you always just derive from sf::Drawable if your class draws something? Or am I missing something else?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Derive from sf::Drawable?
« Reply #1 on: August 07, 2013, 10:45:08 pm »
Since there's only the draw function in SFML 2's sf::Drawable, the only difference is the syntax, as you already noticed.
Quote
This:
window.draw(menu)

or:
menu.draw(window)

So there's no strong point in favor or against deriving from sf::Drawable, it's just a matter of personal taste. It's not going to have a noticeable impact on your design either.

And all the transformation stuff that was also in sf::Drawable in SFML 1.6, is now in sf::Transformable.
Laurent Gomila - SFML developer

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Derive from sf::Drawable?
« Reply #2 on: August 07, 2013, 10:48:54 pm »
Laurent. Would you consider allowing anything that has draw(sf::RenderTarget&,sf::RenderStates) method to draw itself without inheriting sf::Drawable? Although with your coding standard it'd add another file to sf::RenderTarget. :-\
Back to C++ gamedev with SFML in May 2023

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Derive from sf::Drawable?
« Reply #3 on: August 07, 2013, 10:56:11 pm »
Quote
Laurent. Would you consider allowing anything that has draw(sf::RenderTarget&,sf::RenderStates) method to draw itself without inheriting sf::Drawable?
For what?
Laurent Gomila - SFML developer

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Derive from sf::Drawable?
« Reply #4 on: August 07, 2013, 11:00:19 pm »
No added size, virtual call and const.  Okay, it makes no sense and it can be done with global function. Sorry.
Back to C++ gamedev with SFML in May 2023

programmerGuy

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Derive from sf::Drawable?
« Reply #5 on: August 07, 2013, 11:43:08 pm »
Thanks for the answer! Cleared up the confusion.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Derive from sf::Drawable?
« Reply #6 on: August 08, 2013, 08:50:06 pm »
Most of the other member functions you mentioned are now available in the base class sf::Transformable.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

 

anything