1 /*********************************
2 ** Tsunagari Tile Engine **
4 ** Copyright 2011-2012 OmegaSDG **
5 *********************************/
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
34 #include "resourcer.h"
36 #define ANIM_INFINITE_CYCLES -1
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
44 * Mechanically, it is a list of images and a period of time over which to
51 * Constructs an empty, but safe, Animation. All methods on this
52 * object will be null.
57 * Constructs a single-frame Animation. It will function like a static
60 * @param frame static image
62 Animation(const ImageRef
& frame
);
65 * Constructs a Animation from a list of frames.
67 * If given more than one frame, frameTime must be a positive,
70 * @param frames list of frames to cycle through
71 * @param frameTime length of time in milliseconds that each frame
74 Animation(const std::vector
<ImageRef
>& frames
, time_t frameTime
);
77 * Starts the animation over.
79 * @now current time in milliseconds
80 * @cycles number of animation cycles to play
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
);
88 * Has this Animation switched frames since frame() was last called?
90 * @now current time in milliseconds
92 bool needsRedraw(time_t now
) const;
95 * Returns the image that should be displayed at this time.
97 * @now current time in milliseconds
99 Image
* frame(time_t now
);
103 typedef std::vector
<ImageRef
> ImageVec
;
106 /** List of images in animation. */
110 * How many animation cycles are we doing?
112 * 0 : none, static image
113 * >0 : limited number of cycles, will stop on last frame of last cycle
117 /** Length of each frame in animation in milliseconds. */
120 /** Length of one complete cycle through animation in milliseconds. */
123 /** Index of frame currently displaying on screen. */
126 /** Time offset to find current animation frame. */