-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNode.cpp
48 lines (41 loc) · 1.27 KB
/
Node.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "Node.h"
namespace mercury {
void Node::Update(float dt) {
for (auto&& child : m_children) {
child->Update(dt);
}
}
// \return true if event is consumed otherwise false
bool Node::ProcessEvent(const sf::Event& event) {
// descend down the scene graph
for (auto&child : m_children) {
if (child->ProcessEvent(event)) {
return true; // event was consumed
}
}
// try to consume event at this Node
return m_listener && m_listener(event);
}
void Node::AddChild(Node *child) {
m_children.push_back(child);
child->m_parent = this;
}
void Node::RemoveChild(Node *child) {
auto it = std::find(m_children.begin(), m_children.end(), child);
if (it != m_children.end()) {
(*it)->m_parent = nullptr;
std::swap(m_children.back(), *it);
m_children.pop_back();
}
}
void Node::draw(sf::RenderTarget& target, sf::RenderStates states) const {
// apply the entity's transform -- combine it with the one that was passed by the caller
states.transform *= getTransform(); // getTransform() is defined by sf::Transformable
// you may also override states.shader or states.blendMode if you want
this->OnDraw(target, states);
// draw the vertex array
for (auto&& child : m_children) {
child->draw(target, states);
}
}
} // namespace mercury