mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-23 10:26:30 +01:00
feat: Adding draw method to the scenenode class
This commit is contained in:
parent
416c9cf617
commit
30fcab1ea0
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
|
# https://stackoverflow.com/a/3376483
|
||||||
|
|
||||||
compile:./game.cpp
|
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
|
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
|
#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
|
// Virtual functions are member functions whose behavior can be overridden in derived classes
|
||||||
// draw() function allows our class to be used like this:
|
// 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(...);
|
SceneNode::ScenePointer node(...);
|
||||||
window.draw(*node);
|
window.draw(*node);
|
||||||
*/
|
*/
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user