-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathAnimation.cpp
More file actions
43 lines (33 loc) · 1.09 KB
/
Animation.cpp
File metadata and controls
43 lines (33 loc) · 1.09 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
#include "Animation.h"
Animation::Animation(sf::Texture* texture, const sf::Vector2<unsigned>& imageCount, float switchTime)
: imageCount(imageCount), switchTime(switchTime) {
currentImage.x = 0;
uvRect.width = texture->getSize().x / float(imageCount.x);
uvRect.height = texture->getSize().y / float(imageCount.y);
}
void Animation::updateAnimation(bool manualAnimation, bool isMovinge) {
//If the animated entity can either change animation on command or continuous change
//Continuous change
if (manualAnimation == false) {
if (elapsed() > switchTime) {
tp = std::chrono::steady_clock::now();
currentImage.x++;
if (currentImage.x >= imageCount.x) { currentImage.x = 0; }
}
}
//Changing animation based on command
else {
if (isMoving) {
if (elapsed() > switchTime) {
tp = std::chrono::steady_clock::now();
currentImage.x++;
if (currentImage.x >= imageCount.x) { currentImage.x = 0; }
}
}
else {
currentImage.x = 0;
}
}
uvRect.top = currentImage.y * uvRect.height;
uvRect.left = currentImage.x * uvRect.width;
}