factored generic Animation class out of Area::TileType
[Tsunagari.git] / src / animation.cpp
blobabcdbaaa0ca3650e3dc05b1a27f984d523ebe30b
1 #include "animation.h"
3 Animation::Animation()
4 : img(NULL),
5 animated(false),
6 frameLen(0),
7 animLen(0),
8 frameShowing(0)
12 void Animation::addFrame(ImageRef frame)
14 frames.push_back(frame);
15 animLen = frameLen * (int)frames.size();
16 if (frames.size() == 1)
17 img = frame.get();
18 if (frames.size() > 1)
19 animated = true;
22 void Animation::setFrameLen(int milliseconds)
24 frameLen = milliseconds;
25 animLen = frameLen * (int)frames.size();
28 bool Animation::needsUpdate(int milliseconds) const
30 if (animated) {
31 int frame = (milliseconds % animLen) / frameLen;
32 if (frame != frameShowing)
33 return true;
35 return false;
38 void Animation::updateFrame(int milliseconds)
40 if (animated) {
41 frameShowing = (milliseconds % animLen) / frameLen;
42 img = frames[frameShowing].get();
46 Gosu::Image* Animation::image() const
48 return img;