SFML community forums

Help => General => Topic started by: EGYPTIAN CODER on November 26, 2016, 12:48:37 pm

Title: SFML Game Development project
Post by: EGYPTIAN CODER 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 ???
Title: Re: SFML Game Development project
Post by: eXpl0it3r 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.
Title: Re: SFML Game Development project
Post by: EGYPTIAN CODER 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