-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntity.cpp
More file actions
41 lines (35 loc) · 1.11 KB
/
Copy pathEntity.cpp
File metadata and controls
41 lines (35 loc) · 1.11 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
#include "Entity.h"
#include "TextureManager.h"
#include "GameEngine.h"
#include <iostream>
#include <string>
Entity::Entity() {
}
Entity::~Entity() {
if (sprite) delete sprite;
}
void Entity::draw() {
if (this->sprite != nullptr) {
sf::RenderWindow& window = GameEngine::getInstance().getWindow();
this->sprite->setScale(this->getSize());
this->sprite->setPosition(this->getPosition());
window.draw(*sprite);
}
}
void Entity::setTexture(std::string fileName, sf::IntRect frame) {
this->texture = TextureManager::getInstance().getTexture(fileName);
if (this->texture != nullptr) {
if (sprite) delete sprite;
sprite = new sf::Sprite(*texture);
sprite->setTextureRect(frame);
sprite->setOrigin({ (float)frame.size.x / 2.f, (float)frame.size.y / 2.f });
sprite->setScale(this->getSize());
sprite->setPosition({ this->getPosition().x, this->getPosition().y });
}
else {
std::cout << "Nie uda³o siê za³adowaæ tekstury: " << fileName << std::endl;
}
}
sf::FloatRect Entity::getBounds() {
return sprite->getGlobalBounds();
}