feat: Adding draw method to the scenenode class

This commit is contained in:
PolishPigeon 2022-01-23 19:30:18 +01:00
parent 37e225b19c
commit fd449af98e
5 changed files with 20 additions and 2 deletions

Binary file not shown.

Binary file not shown.

View File

@ -1,4 +1,4 @@
CXXFLAGS = -Wextra -Wall -Wfloat-equal -Wundef -Wshadow -Wpointer-arith -Wcast-align -Wstrict-overflow=5 -Wwrite-strings -Wcast-qual -Wunreachable-code -pedantic -Wswitch-default
CXXFLAGS = -Wextra -Wall -Wfloat-equal -Wundef -Wshadow -Wpointer-arith -Wcast-align -Wstrict-overflow=5 -Wwrite-strings -Wcast-qual -Wunreachable-code -pedantic -Wswitch-default -Wno-unused-parameter
# https://stackoverflow.com/a/3376483
compile:./game.cpp

View File

@ -30,4 +30,22 @@ SceneNode::ScenePointer SceneNode::detachChild(const SceneNode& node) // finds n
return result; // and we return the pointer to the node
}
void SceneNode::drawCurrent(sf::RenderTarget& target, sf::RenderStates states) const
{
}
void SceneNode::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
states.transform *= getTransform();
// *= combines the parent's absolute transform with the relative one of the current node;
// states.transform contains the absolute world transform
drawCurrent(target, states); // now we can draw the derived object using states, this is similar to how sf::Sprite handles transforms
for (const ScenePointer& child : mChildren)
{
child -> draw(target, states); // we also need to draw all the child nodes
}
}
#endif

View File

@ -18,7 +18,7 @@ class SceneNode : public sf::Transformable, public sf::Drawable, private sf::Non
// Virtual functions are member functions whose behavior can be overridden in derived classes
// draw() function allows our class to be used like this:
/*
sf::RenderWindow window(...);
sf::RenderWindow window(...); // window class calls our draw() function
SceneNode::ScenePointer node(...);
window.draw(*node);
*/