-
Notifications
You must be signed in to change notification settings - Fork 0
/
animation.h
47 lines (35 loc) · 1.03 KB
/
animation.h
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
#pragma once
#include <SFML/Graphics.hpp>
#include "entity.h"
class Animation : public Entity {
protected:
float time;
sf::IntRect rectangle;
sf::Vector2i size;
sf::Vector2i frames;
public:
Animation(sf::Vector2f position, float rotation, float scale, std::string texture, sf::Vector2i _size, sf::Vector2i _frames, float _time, std::vector<Entity*> *renderQueue): Entity("animation", 1000, 0, position, rotation - 90.f, texture, scale, renderQueue), rectangle(0, 0, _size.x, _size.y) {
time = _time;
size = _size;
frames = _frames;
sprite.setTextureRect(rectangle);
sprite.setOrigin(size.x/2, size.y/2);
};
void animate() {
if (animationTime.asMilliseconds() >= time) {
if (rectangle.left >= size.x*frames.x) {
rectangle.left = 0;
rectangle.top += size.y;
}
else
rectangle.left += size.x;
if (rectangle.top >= size.y*frames.y) {
stop();
}
sprite.setTextureRect(rectangle);
animationTimer.restart();
}
}
void collide(Entity *entity) {};
void destroy() {stop();};
};