mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-07-04 16:43:05 +02:00
feat: Adding draw method to the scenenode class
This commit is contained in:
parent
37e225b19c
commit
fd449af98e
Binary file not shown.
Binary file not shown.
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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);
|
||||
*/
|
||||
|
||||
Loading…
Reference in New Issue
Block a user