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

Author Topic: SFML Game Development project  (Read 1602 times)

0 Members and 1 Guest are viewing this topic.

EGYPTIAN CODER

  • Newbie
  • *
  • Posts: 32
    • View Profile
    • Email
SFML Game Development project
« on: November 26, 2016, 12:48:37 pm »
hello every one
I am now in chapter three in SFML Game Development
class SceneNode : public sf::Transformable, public sf::Drawable,
private sf::NonCopyable
{
public:
typedef std::unique_ptr<SceneNode> Ptr;
public:
SceneNode();
void attachChild(Ptr child);
Ptr detachChild(const SceneNode& node);
private:
virtual void draw(sf::RenderTarget& target,
sf::RenderStates states) const;
virtual void drawCurrent(sf::RenderTarget& target,
sf::RenderStates states) const;
private:
std::vector<Ptr> mChildren;
SceneNode* mParent;
};
 
The draw() function allows our class to be used as shown in the following
code snippet:
sf::RenderWindow window(...);
SceneNode::Ptr node(...);
window.draw(*node); // note: no node->draw(window) here!
The window class internally calls our draw() function. No other classes need access
to it, so we can make it private.
I realy can,t understand what (internally calls our draw()function mean) :o ???

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: SFML Game Development project
« Reply #1 on: November 26, 2016, 04:45:20 pm »
The window (which is a sf::RenderTarget) is a friend (the C++ friend keyword) of sf::Drawable, thus the window gets access to the draw() function no matter whether you make it private, protected or public.

If you don't know the friend keyword, I suggest you look it up in one of your C++ resources.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

EGYPTIAN CODER

  • Newbie
  • *
  • Posts: 32
    • View Profile
    • Email
Re: SFML Game Development project
« Reply #2 on: November 27, 2016, 05:43:12 am »
I really know what friend mean but rendertarget is friend to drawable which don,t know anything
about our function in this program this is what i think
« Last Edit: November 27, 2016, 09:28:44 am by Laurent »