-
Notifications
You must be signed in to change notification settings - Fork 1
/
TurretAnimation.cpp
102 lines (78 loc) · 1.78 KB
/
TurretAnimation.cpp
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include "TurretAnimation.h"
TurretAnimation::TurretAnimation(sf::Texture* texture, sf::Vector2u imageCount, float switchTime)
{
this->imageCount = imageCount;
this->switchTime = switchTime;
totalTime = 0.0f;
currentImage.x = 0;
uvRect.width = (texture->getSize().x) / float(imageCount.x);
uvRect.height = texture->getSize().y / float(imageCount.y);
}
TurretAnimation::~TurretAnimation()
{
}
void TurretAnimation::Update(int row, float deltaTime, bool faceRight)
{
currentImage.y = row;
totalTime += deltaTime;
if (totalTime >= switchTime)
{
totalTime -= switchTime;
currentImage.x++;
if (currentImage.x == 8)
{
currentImage.x = 0;
}
}
uvRect.top = currentImage.y*uvRect.height;
if (faceRight)
{
uvRect.left = currentImage.x*uvRect.width;
uvRect.width = abs(uvRect.width);
}
else
{
uvRect.left = (currentImage.x + 1)*abs(uvRect.width);
uvRect.width = -abs(uvRect.width);
}
}
/*
#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;
uvRect.width = texture->getSize().x / float(imageCount.x);
uvRect.height = texture->getSize().y / float(imageCount.y);
}
Animation::~Animation()
{
}
void Animation :: Update(int row, float deltaTime, bool faceRight)
{
currentImage.y = row;
totalTime += deltaTime;
if (totalTime >= switchTime)
{
totalTime -= switchTime;
currentImage.x++;
if (currentImage.x == 3)
{
currentImage.x = 0;
}
}
uvRect.top = currentImage.y*uvRect.height;
if (faceRight)
{
uvRect.left = currentImage.x*uvRect.width;
uvRect.width = abs(uvRect.width);
}
else
{
uvRect.left = (currentImage.x+1)*abs(uvRect.width);
uvRect.width = -abs(uvRect.width);
}
}
*/