-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimation.cpp
More file actions
48 lines (42 loc) · 975 Bytes
/
Animation.cpp
File metadata and controls
48 lines (42 loc) · 975 Bytes
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
#include "Animation.h"
Animation::Animation(sf::Texture* texture, sf::Vector2u imageCount, float switchTime)
{
this->imageCount = imageCount;
this->switchTime = switchTime;
totalTime = 0.0f;
currentImage.x = 0;
currentImage.y = 0;
uvRect.width = texture->getSize().x / imageCount.x;
uvRect.height = texture->getSize().y / imageCount.y;
}
void Animation::update(int rowY, float deltaTime, bool isfaceRight, bool isStanding)
{
currentImage.y = rowY;
totalTime += deltaTime;
if (totalTime >= switchTime)
{
totalTime -= switchTime;
if (!isStanding) {
currentImage.x++;
if (currentImage.x >= imageCount.x)
{
currentImage.x = 0;
}
}
else
{
currentImage.x = 0;
}
}
uvRect.top = currentImage.y * uvRect.height;
if (isfaceRight)
{
uvRect.left = (currentImage.x + 1) * abs(uvRect.width);
uvRect.width = -abs(uvRect.width);
}
else
{
uvRect.left = currentImage.x * abs(uvRect.width);
uvRect.width = abs(uvRect.width);
}
}