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

Author Topic: Inherit drawable?  (Read 2847 times)

0 Members and 1 Guest are viewing this topic.

xarxer

  • Newbie
  • *
  • Posts: 35
    • View Profile
Inherit drawable?
« on: February 23, 2010, 06:52:59 pm »
Hi all..
I created a thread a while ago concerning almost the same thing.

The thing is I just cannot let this go, look at this piece of code:
http://codepad.org/LPxddsRq

As seen, object inherits from sf::Drawable and CSquare inherits from object.
To make CSquare drawable via App.Draw(mysquare);, the function void Render(sf::RenderTarget& Target) const   { Target.Draw(square); } is needed in CSquare.

But CSquare also has the functions SetPosition(), SetRotation(), SetScale() and so on inherited from sf::Drawable, but these functions won't actually do anything since they don't affect the sf::Sprite square in CSquare.

Is there any way to solve this nicely or is the ONLY way to use a reference to a sf::RenderWindow and make a function CSquare::Draw();?

Thanks in advance!  :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Inherit drawable?
« Reply #1 on: February 23, 2010, 07:41:17 pm »
Quote
But CSquare also has the functions SetPosition(), SetRotation(), SetScale() and so on inherited from sf::Drawable, but these functions won't actually do anything since they don't affect the sf::Sprite square in CSquare.

They do!
Nested calls to Draw accumulate their transformations. In SFML 2, they also modulate their global colors.
Laurent Gomila - SFML developer

xarxer

  • Newbie
  • *
  • Posts: 35
    • View Profile
Inherit drawable?
« Reply #2 on: February 23, 2010, 08:14:48 pm »
oh.. I noticed this now  :shock:

so if I have void Render(sf::RenderTarget& Target) const { Target.Draw(square); } in my class, that very piece of code makes the class it is in to respond to SetPosition etc. and apply this to the sprite used in the Render function (CSquare::square in this case)?

Is this mentioned in the tutorials?  :roll:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Inherit drawable?
« Reply #3 on: February 23, 2010, 08:43:54 pm »
Quote
so if I have void Render(sf::RenderTarget& Target) const { Target.Draw(square); } in my class, that very piece of code makes the class it is in to respond to SetPosition etc. and apply this to the sprite used in the Render function (CSquare::square in this case)?

Yes sir. And the square can have its own transformations as well, that will be combined to its parents' ones.

Quote
Is this mentioned in the tutorials?

No, inheriting from sf::Drawable was initially not meant to be done outside SFML, so there is no mention of it in the tutorials. But I think I will document it better in SFML 2.
Laurent Gomila - SFML developer

xarxer

  • Newbie
  • *
  • Posts: 35
    • View Profile
Inherit drawable?
« Reply #4 on: February 23, 2010, 09:12:47 pm »
Cool!  :D

Keep up the good work   :D