FIFE
|
#include <animation.h>
Classes | |
struct | FrameInfo |
Contains information about one animation frame (duration + frame index + frame pointer) More... | |
Public Member Functions | |
Animation () | |
Constructor. More... | |
~Animation () | |
Destructor. More... | |
void | addFrame (ImagePtr image, uint32_t duration) |
Adds new frame into animation Frames must be added starting from first frame. More... | |
int32_t | getFrameIndex (uint32_t timestamp) |
Get the frame index that matches given timestamp. More... | |
ImagePtr | getFrame (int32_t index) |
Gets the frame iamge that matches the given index. More... | |
ImagePtr | getFrameByTimestamp (uint32_t timestamp) |
Gets the frame image that matches the given timestamp. More... | |
int32_t | getFrameDuration (int32_t index) const |
Gets the frame duration for given (indexed) frame. More... | |
uint32_t | getFrameCount () const |
Get the number of frames. More... | |
void | setActionFrame (int32_t num) |
Sets the action frame. More... | |
int32_t | getActionFrame () const |
Gets the action frame. More... | |
void | setDirection (uint32_t direction) |
Animation direction tells how this animation is associated with movement when played starting from frame 0 E.g. More... | |
uint32_t | getDirection () const |
Gets the animation direction. More... | |
uint32_t | getDuration () const |
Gets the total duration for the whole animation. More... | |
![]() | |
FifeClass () | |
virtual | ~FifeClass () |
fifeid_t | getFifeId () |
Gets unique id of this instance inside the engine. More... | |
Private Member Functions | |
bool | isValidIndex (int32_t index) const |
Checks for animation frame index overflows. More... | |
Private Attributes | |
std::map< uint32_t, FrameInfo > | m_framemap |
std::vector< FrameInfo > | m_frames |
int32_t | m_action_frame |
int32_t | m_animation_endtime |
uint32_t | m_direction |
A container of Images describing an animation. Animation itself does not take care of animating the images. Instead it contains images having associated timestamps. It is the responsibility of the animation user to query frames based on current timestamp and show returned images on screen.
Definition at line 56 of file animation.h.
|
explicit |
Constructor.
Definition at line 41 of file animation.cpp.
FIFE::Animation::~Animation | ( | ) |
Destructor.
Decreases the reference count of all referred images.
Definition at line 47 of file animation.cpp.
void FIFE::Animation::addFrame | ( | ImagePtr | image, |
uint32_t | duration | ||
) |
Adds new frame into animation Frames must be added starting from first frame.
Increases the reference count of the given image.
image | Pointer to Image. Does not transfer the ownership |
duration | Duration for given frame in the animation |
Definition at line 52 of file animation.cpp.
References FIFE::Animation::FrameInfo::duration, FIFE::Animation::FrameInfo::image, FIFE::Animation::FrameInfo::index, m_animation_endtime, m_framemap, and m_frames.
Referenced by FIFE::AnimationLoader::load(), and FIFE::ObjectLoader::load().
|
inline |
Gets the action frame.
Definition at line 110 of file animation.h.
References m_action_frame.
Referenced by FIFE::LayerCache::updateVisual().
|
inline |
Gets the animation direction.
Definition at line 125 of file animation.h.
References m_direction.
|
inline |
Gets the total duration for the whole animation.
Definition at line 129 of file animation.h.
References m_animation_endtime.
Referenced by FIFE::Cursor::draw(), FIFE::ObjectLoader::load(), FIFE::LightRendererAnimationInfo::render(), FIFE::OffRendererAnimationInfo::render(), FIFE::GenericRendererAnimationInfo::render(), FIFE::Camera::renderOverlay(), and FIFE::LayerCache::updateVisual().
ImagePtr FIFE::Animation::getFrame | ( | int32_t | index | ) |
Gets the frame iamge that matches the given index.
If no matches found, returns an invalid ImagePtr
Definition at line 87 of file animation.cpp.
References FIFE::IResource::getState(), isValidIndex(), FIFE::Image::load(), m_frames, and FIFE::IResource::RES_NOT_LOADED.
ImagePtr FIFE::Animation::getFrameByTimestamp | ( | uint32_t | timestamp | ) |
Gets the frame image that matches the given timestamp.
Definition at line 99 of file animation.cpp.
References FIFE::IResource::getState(), FIFE::Image::load(), m_animation_endtime, m_framemap, and FIFE::IResource::RES_NOT_LOADED.
Referenced by FIFE::Cursor::draw(), FIFE::LightRendererAnimationInfo::render(), FIFE::OffRendererAnimationInfo::render(), FIFE::GenericRendererAnimationInfo::render(), FIFE::Camera::renderOverlay(), and FIFE::LayerCache::updateVisual().
uint32_t FIFE::Animation::getFrameCount | ( | ) | const |
int32_t FIFE::Animation::getFrameDuration | ( | int32_t | index | ) | const |
Gets the frame duration for given (indexed) frame.
Returns negative value in case of incorrect index
Definition at line 112 of file animation.cpp.
References isValidIndex(), and m_frames.
int32_t FIFE::Animation::getFrameIndex | ( | uint32_t | timestamp | ) |
Get the frame index that matches given timestamp.
In case there is no exact match, correct frame is calculated. E.g. if there are frames for timestamps 50 and 100 and frame for 75 is asked, frame associated with value 50 is given back. In case the timestamp is past the sequence, negative value is returned
Definition at line 72 of file animation.cpp.
References m_animation_endtime, and m_framemap.
Referenced by FIFE::LayerCache::updateVisual().
|
private |
Checks for animation frame index overflows.
Definition at line 82 of file animation.cpp.
References m_frames.
Referenced by getFrame(), and getFrameDuration().
|
inline |
Sets the action frame.
Action frame is the frame when the related action actually happens. E.g. in case of punch animation, action frame is the frame when punch hits the target. In case there is no associated action frame, value is negative
num | index of the action frame. |
Definition at line 105 of file animation.h.
References m_action_frame.
Referenced by FIFE::AnimationLoader::load(), and FIFE::ObjectLoader::load().
void FIFE::Animation::setDirection | ( | uint32_t | direction | ) |
Animation direction tells how this animation is associated with movement when played starting from frame 0 E.g.
in walking animation there should be direction assigned so that engine can choose the correct animation when characters are moved around the map area
direction | direction to set |
Definition at line 124 of file animation.cpp.
References m_direction.
|
private |
Definition at line 149 of file animation.h.
Referenced by getActionFrame(), and setActionFrame().
|
private |
Definition at line 151 of file animation.h.
Referenced by addFrame(), getDuration(), getFrameByTimestamp(), and getFrameIndex().
|
private |
Definition at line 153 of file animation.h.
Referenced by getDirection(), and setDirection().
|
private |
Definition at line 145 of file animation.h.
Referenced by addFrame(), getFrameByTimestamp(), and getFrameIndex().
|
private |
Definition at line 147 of file animation.h.
Referenced by addFrame(), getFrame(), getFrameCount(), getFrameDuration(), and isValidIndex().