-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiceAnimation.cpp
More file actions
52 lines (39 loc) · 1.07 KB
/
DiceAnimation.cpp
File metadata and controls
52 lines (39 loc) · 1.07 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
#include "DiceAnimation.h"
//Init components
void DiceAnimation::initVariables()
{
this->currentImage.x = 0;
this->totalTime = 0.0f;
}
//Constructors / Destructors
DiceAnimation::DiceAnimation(sf::RectangleShape* texture, sf::Vector2u imageCount, float switchTime)
{
this->imageCount = imageCount;
this->switchTime = switchTime;
this->initVariables();
this->uvRect.width = texture->getSize().x / float(imageCount.x);
this->uvRect.height = texture->getSize().y / (float(imageCount.y));
}
void DiceAnimation::update(const float& dt)
{
currentImage.y = 5;
totalTime += dt;
if (totalTime >= switchTime)
{
totalTime -= switchTime;
currentImage.x++;
if (currentImage.x >= imageCount.x)
{
currentImage.x = 0;
}
}
uvRect.left = currentImage.x * uvRect.width;
uvRect.top = currentImage.y * uvRect.height;
}
void DiceAnimation::setFrame(unsigned short pos, const float& dt)
{
currentImage.y = 5;
currentImage.x = pos - 1;
uvRect.left = currentImage.x * uvRect.width;
uvRect.top = currentImage.y * uvRect.height;
}