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

Author Topic: I don't understand about drawing in SFML Game Development book  (Read 2762 times)

0 Members and 2 Guests are viewing this topic.

aratnon

  • Newbie
  • *
  • Posts: 24
    • View Profile
It tells me to make a SceneNode class which inherits from sf::Drawable and sf::Transformable so I can draw by pass it as a paremter for the RenderWindow.draw() function

what I don't understand is for example, I have a SceneNode as a top of the SceneGraph then I call RenderWindow.draw(SceneNode). The result is every child node of SceneNode also draws too.
How it could be possible?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Re: I don't understand about drawing in SFML Game Development book
« Reply #1 on: August 27, 2013, 06:38:35 pm »
Well turn to page 60 of the book, it's explained there. :)

It simply draws all the children in a loop. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

aratnon

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: I don't understand about drawing in SFML Game Development book
« Reply #2 on: August 27, 2013, 08:13:25 pm »
I have a epub version so, I dont know what is the page 60 actually in the book  ???
but I guess.

This is the draw function of The SceneNode class
void SceneNode::draw(sf::RenderTarget &target, sf::RenderStates states) const
{
        states.transform *= getTransform();
        drawCurrent(target, states);

        for each (const SceneNode::SceneNodePtr  &child in _children)
        {
                child->draw(target, states);
        }

}

In The World class I call this function to render the parent node
_renderWindow->draw(_sceneGraph);

after I call it. Does the _sceneGraph call
void SceneNode::draw(sf::RenderTarget &target, sf::RenderStates states)
by itself?


Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: I don't understand about drawing in SFML Game Development book
« Reply #3 on: August 28, 2013, 02:50:58 pm »
Does the _sceneGraph call
void SceneNode::draw(sf::RenderTarget &target, sf::RenderStates states)
by itself?
Exactly, that's the recursive function call here:
child->draw(target, states);


By the way:
for each (const SceneNode::SceneNodePtr  &child in _children)
This syntax is a non-portable extension, not standard C++. You should use
for (const SceneNodePtr& child : children)
if your compiler supports range-based for, or our standard-conforming workaround
FOREACH(const SceneNodePtr& child, children)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

 

anything