fix redraw at top-left of map
[Tsunagari.git] / src / animation.cpp
blobdd3c44c04b4cd05fa7fa8eba68a9d68e76fc794c
1 /******************************
2 ** Tsunagari Tile Engine **
3 ** animation.cpp **
4 ** Copyright 2011 OmegaSDG **
5 ******************************/
7 #include "animation.h"
9 Animation::Animation()
10 : img(NULL),
11 animated(false),
12 frameLen(0),
13 animLen(0),
14 frameShowing(0)
18 Animation::Animation(ImageRef frame)
20 Animation();
21 addFrame(frame);
24 void Animation::addFrame(ImageRef frame)
26 frames.push_back(frame);
27 animLen = frameLen * (int)frames.size();
28 if (frames.size() == 1)
29 img = frame.get();
30 if (frames.size() > 1)
31 animated = true;
34 void Animation::setFrameLen(int milliseconds)
36 frameLen = milliseconds;
37 animLen = frameLen * (int)frames.size();
40 bool Animation::needsRedraw(int milliseconds) const
42 if (animated) {
43 int frame = (milliseconds % animLen) / frameLen;
44 if (frame != frameShowing)
45 return true;
47 return false;
50 void Animation::updateFrame(int milliseconds)
52 if (animated) {
53 frameShowing = (milliseconds % animLen) / frameLen;
54 img = frames[frameShowing].get();
58 Gosu::Image* Animation::frame() const
60 return img;