-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSceneRenderingSystem.cpp
More file actions
73 lines (54 loc) · 2.44 KB
/
SceneRenderingSystem.cpp
File metadata and controls
73 lines (54 loc) · 2.44 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//
// Created by Fabien on 11/01/2016.
//
#include "SceneRenderingSystem.hpp"
void SceneRenderingSystem::update(entityx::EntityManager &es, entityx::EventManager &events, entityx::TimeDelta dt)
{
sf::View view = mTarget.getView();
sf::FloatRect bounds;
bounds.left = view.getCenter().x - (view.getSize().x / 2.f);
bounds.top = view.getCenter().y - (view.getSize().y / 2.f);
bounds.width = view.getSize().x;
bounds.height = view.getSize().y;
//add a tile border to prevent gaps appearing
bounds.left -= static_cast<float>(TILE_SIZE);
bounds.top -= static_cast<float>(TILE_SIZE);
bounds.width += static_cast<float>(TILE_SIZE * 2);
bounds.height += static_cast<float>(TILE_SIZE * 2);
std::vector<tmx::MapLayer> &vector = mLoader.GetLayers();
for (auto &layer : vector)
layer.Cull(bounds);
for (auto &layer : vector)
{
if (layer.name == "player")
{
es.each<Drawable,Animable,Playable>([this](entityx::Entity entity, Drawable& drawable,Animable& animable, Playable& playable) {
sf::VertexArray quad(sf::Quads, 4);
float abs = drawable.vectorPos.x;
float ord = drawable.vectorPos.y;
quad[0].position = sf::Vector2f(abs, ord);
quad[1].position = sf::Vector2f(abs+TILE_SIZE, ord);
quad[2].position = sf::Vector2f(abs+TILE_SIZE, ord+TILE_SIZE);
quad[3].position = sf::Vector2f(abs, ord+TILE_SIZE);
if(animable.current != "")
{
Animation* animation = animable.animations[animable.current].get();
if(animation != nullptr)
{
sf::FloatRect currentRec = (*(animation->current));
quad[0].texCoords = sf::Vector2f(currentRec.left, currentRec.top);
quad[1].texCoords = sf::Vector2f(currentRec.left+currentRec.width, currentRec.top);
quad[2].texCoords = sf::Vector2f(currentRec.left+currentRec.width, currentRec.top+currentRec.height);
quad[3].texCoords = sf::Vector2f(currentRec.left, currentRec.top+currentRec.height);
this->mTarget.draw(quad,animable.states);
}
}
});
}
else
{
mTarget.draw(layer);
}
}
//mLoader.Draw(mTarget, tmx::MapLayer::Debug);
}