26 #include <boost/lexical_cast.hpp>
32 #include "util/base/exception.h"
33 #include "util/time/timemanager.h"
35 #include "animation.h"
37 #include "util/structures/rect.h"
43 m_animation_endtime(-1),
54 info.index = m_frames.size();
55 info.duration = duration;
57 m_frames.push_back(info);
59 std::map<uint32_t, FrameInfo>::const_iterator i(m_framemap.end());
60 if (i == m_framemap.begin()) {
62 m_animation_endtime = duration;
65 uint32_t frametime = i->first + i->second.duration;
66 m_framemap[frametime] = info;
67 m_animation_endtime = frametime + duration;
74 if ((static_cast<int32_t>(timestamp) <= m_animation_endtime) && (m_animation_endtime > 0)) {
75 std::map<uint32_t, FrameInfo>::const_iterator i(m_framemap.upper_bound(timestamp));
77 val = i->second.index;
82 bool Animation::isValidIndex(int32_t index)
const{
83 int32_t size = m_frames.size();
84 return size > 0 && index >= 0 && index < size;
88 if (isValidIndex(index)) {
89 ImagePtr image = m_frames[index].image;
90 if(image->getState() == IResource::RES_NOT_LOADED) {
101 if ((static_cast<int32_t>(timestamp) <= m_animation_endtime) && (m_animation_endtime > 0)) {
102 std::map<uint32_t, FrameInfo>::const_iterator i(m_framemap.upper_bound(timestamp));
104 val = i->second.image;
106 if(val && val->getState() == IResource::RES_NOT_LOADED) {
113 if (isValidIndex(index)) {
114 return m_frames[index].duration;
121 return m_frames.size();
int32_t getFrameDuration(int32_t index) const
void setDirection(uint32_t direction)
ImagePtr getFrameByTimestamp(uint32_t timestamp)
uint32_t getFrameCount() const
int32_t getFrameIndex(uint32_t timestamp)
ImagePtr getFrame(int32_t index)
void addFrame(ImagePtr image, uint32_t duration)
credit to phoku for his NodeDisplay example which the visitor code is adapted from ( he coded the qua...