summary refs log tree commit diff stats
path: root/src/animation.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/animation.cpp')
-rw-r--r--src/animation.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/animation.cpp b/src/animation.cpp new file mode 100644 index 0000000..31ba21f --- /dev/null +++ b/src/animation.cpp
@@ -0,0 +1,35 @@
1#include "animation.h"
2
3AnimationSet::AnimationSet(
4 Texture texture,
5 int frameWidth,
6 int frameHeight,
7 int framesAcross) :
8 texture_(std::move(texture)),
9 frameWidth_(frameWidth),
10 frameHeight_(frameHeight),
11 framesAcross_(framesAcross)
12{
13}
14
15void AnimationSet::emplaceAnimation(
16 std::string animation,
17 size_t firstFrame,
18 size_t numFrames,
19 size_t delay)
20{
21 animations_.emplace(
22 std::piecewise_construct,
23 std::make_tuple(animation),
24 std::make_tuple(firstFrame, numFrames, delay));
25}
26
27Rectangle AnimationSet::getFrameRect(int frame) const
28{
29 return {
30 frameWidth_ * (frame % framesAcross_),
31 frameHeight_ * (frame / framesAcross_),
32 frameWidth_,
33 frameHeight_
34 };
35}