-
Notifications
You must be signed in to change notification settings - Fork 0
/
frameanimation.cpp
53 lines (43 loc) · 1 KB
/
frameanimation.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
#include "frameanimation.h"
FrameAnimation::FrameAnimation()
{
}
void FrameAnimation::initAnimation(std::vector<std::pair<QPixmap, int> > s)
{
this->sprites=s;
this->curSpriteIdx=0;
this->curSpriteLeftFrames=this->sprites[this->curSpriteIdx].second;
}
void FrameAnimation::update()
{
this->curSpriteLeftFrames--;
if(this->curSpriteLeftFrames==0)
{
this->nextSprite();
}
}
void FrameAnimation::nextSprite()
{
this->curSpriteIdx=(this->curSpriteIdx+1)%this->sprites.size();
this->curSpriteLeftFrames=this->sprites[this->curSpriteIdx].second;
}
int FrameAnimation::getCurSpriteIdx()
{
return this->curSpriteIdx;
}
void FrameAnimation::setCurSpriteIdx(int idx)
{
this->curSpriteIdx=idx;
}
int FrameAnimation::getCurSpriteLeftFrames()
{
return this->curSpriteLeftFrames;
}
void FrameAnimation::setCurSpriteLeftFrames(int frame)
{
this->curSpriteLeftFrames=frame;
}
QPixmap FrameAnimation::getCurSprite()
{
return this->sprites[this->curSpriteIdx].first;
}