forked from plastictown/Engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanimation.cpp
More file actions
64 lines (54 loc) · 1.12 KB
/
Copy pathanimation.cpp
File metadata and controls
64 lines (54 loc) · 1.12 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
53
54
55
56
57
58
59
60
61
62
63
64
/*
* https://github.com/plastictown/Engine
* Copyright (C) 2018 Mikhail Domchenkov
*/
#include <animation.h>
#include <thread>
Animation::Animation( const decltype(interval)& msec)
: interval {msec}
{
setType(GameObjectType::TypeAnimation);
this->start();
}
Animation::Animation( const uint32_t msec): interval {std::chrono::milliseconds{msec}}
{
setType(GameObjectType::TypeAnimation);
this->start();
}
void Animation::set_interval(const decltype(interval)& msec)
{
interval = msec;
}
void Animation::AddImage(const Image& img)
{
images.push_back(img);
index.set_max(images.size()-1);
index.set_value(0);
}
void Animation::AddImage(const vector<Image>& v)
{
for(auto& i:v)
{
AddImage(i);
}
}
const Image& Animation::getCurrentImage() const
{
if(images.empty())
throw runtime_error("can't return image: animation is empty!");
return images[index.get_current()];
}
const Image& Animation::getImage() const
{
return getCurrentImage();
}
void Animation::run()
{
index.next();
std::this_thread::sleep_for(interval);
}
Animation::~Animation()
{
if(this->running())
this->stop();
}