Add documentation on placing tiles.
[Tsunagari.git] / src / animation.h
blobb91cf1d475ec24078fa9691a6087a53625641a6a
1 /*********************************
2 ** Tsunagari Tile Engine **
3 ** animation.h **
4 ** Copyright 2011-2012 OmegaSDG **
5 *********************************/
7 // **********
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to
10 // deal in the Software without restriction, including without limitation the
11 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12 // sell copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 // IN THE SOFTWARE.
25 // **********
28 #ifndef ANIMATED_H
29 #define ANIMATED_H
31 #include <vector>
33 #include "image.h"
34 #include "resourcer.h"
36 #define ANIM_INFINITE_CYCLES -1
38 /**
39 * An Animation is a sequence of bitmap images (called frames) used to creates
40 * the illusion of motion. Frames are cycled over with an even amount of time
41 * given to each, and the whole animation starts over after the last frame is
42 * displayed.
44 * Mechanically, it is a list of images and a period of time over which to
45 * play.
47 class Animation
49 public:
50 /**
51 * Constructs an empty, but safe, Animation. All methods on this
52 * object will be null.
54 Animation();
56 /**
57 * Constructs a single-frame Animation. It will function like a static
58 * image.
60 * @param frame static image
62 Animation(const ImageRef& frame);
64 /**
65 * Constructs a Animation from a list of frames.
67 * If given more than one frame, frameTime must be a positive,
68 * non-zero value.
70 * @param frames list of frames to cycle through
71 * @param frameTime length of time in milliseconds that each frame
72 * will display for
74 Animation(const std::vector<ImageRef>& frames, time_t frameTime);
76 /**
77 * Starts the animation over.
79 * @now current time in milliseconds
80 * @cycles number of animation cycles to play
81 * -1 : infinite
82 * 0 : none, static image
83 * >0 : limited number of cycles, will stop on last frame of last cycle
85 void startOver(time_t now, int cycles);
87 /**
88 * Has this Animation switched frames since frame() was last called?
90 * @now current time in milliseconds
92 bool needsRedraw(time_t now) const;
94 /**
95 * Returns the image that should be displayed at this time.
97 * @now current time in milliseconds
99 Image* frame(time_t now);
101 private:
103 typedef std::vector<ImageRef> ImageVec;
106 /** List of images in animation. */
107 ImageVec frames;
110 * How many animation cycles are we doing?
111 * -1 : infinite
112 * 0 : none, static image
113 * >0 : limited number of cycles, will stop on last frame of last cycle
115 int cycles;
117 /** Length of each frame in animation in milliseconds. */
118 time_t frameTime;
120 /** Length of one complete cycle through animation in milliseconds. */
121 time_t cycleTime;
123 /** Index of frame currently displaying on screen. */
124 size_t frameShowing;
126 /** Time offset to find current animation frame. */
127 time_t offset;
130 #endif