-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLightSprite.cpp
More file actions
55 lines (44 loc) · 1.67 KB
/
Copy pathLightSprite.cpp
File metadata and controls
55 lines (44 loc) · 1.67 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
#include "LightSprite.hpp"
LightSprite::LightSprite(){}
LightSprite::LightSprite(SpriteSheetDescription description, std::vector<sf::Texture*> textures) :
_rotation(0),
_description(description)
{
_light = nullptr;
_sprites = std::vector<sf::Sprite>(9);
for (unsigned int i = 0; i < _sprites.size(); ++i) _sprites[i].setTexture(*textures[i]);
_action = 0;
_dir = directions::none;
}
LightSprite::~LightSprite() { }
void LightSprite::update( sf::Vector2f pos, int dir, int action,int currentAnimation) {
_pos = pos;
_dir = directions(dir);
_action = action;
_currentAnimation = currentAnimation;
}
void LightSprite::draw(sf::RenderTarget* target) {
directions dir = directions::none;
if (_light != nullptr) dir = pointsToDirection8(_pos, _light->getPosition(), _rotation);
_sprites[dir].setTextureRect(_description[_action*4+_dir][_currentAnimation%_description[_action*4+_dir].size()]);
_sprites[dir].setPosition(_pos);
_sprites[dir].setRotation(_rotation);
target->draw(_sprites[dir]);
}
void LightSprite::draw(sf::RenderTarget* target, sf::Shader* shader) {
directions dir = directions::none;
if (_light != nullptr) dir = pointsToDirection8(_pos, _light->getPosition(), _rotation);
_sprites[dir].setTextureRect(_description[_action*4+_dir][_currentAnimation%_description[_action*4+_dir].size()]);
_sprites[dir].setPosition(_pos);
_sprites[dir].setRotation(_rotation);
target->draw(_sprites[dir], shader);
}
void LightSprite::setLight(Light* light) {
_light = light;
}
void LightSprite::setPosition(sf::Vector2f pos) {
_pos = pos;
}
void LightSprite::setRotation(float rotation){
_rotation = rotation;
}