2018-05-10 00:58:43 +08:00
|
|
|
#include "..\e2dcommon.h"
|
|
|
|
|
|
|
|
|
|
e2d::Animation::Animation()
|
|
|
|
|
: _interval(1)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
e2d::Animation::Animation(double interval)
|
|
|
|
|
: _interval(interval)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
e2d::Animation::Animation(double interval, const std::vector<Image*>& frames)
|
|
|
|
|
: _interval(interval)
|
|
|
|
|
{
|
|
|
|
|
this->add(frames);
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-10 17:02:18 +08:00
|
|
|
e2d::Animation::Animation(const std::vector<Image*>& frames)
|
|
|
|
|
: _interval(1)
|
2018-05-10 00:58:43 +08:00
|
|
|
{
|
|
|
|
|
this->add(frames);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
e2d::Animation::~Animation()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void e2d::Animation::setInterval(double interval)
|
|
|
|
|
{
|
|
|
|
|
_interval = max(interval, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void e2d::Animation::onDestroy()
|
|
|
|
|
{
|
|
|
|
|
for (auto frame : _frames)
|
|
|
|
|
{
|
2018-05-10 20:23:32 +08:00
|
|
|
SafeRelease(frame);
|
2018-05-10 00:58:43 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void e2d::Animation::add(Image * frame)
|
|
|
|
|
{
|
|
|
|
|
if (frame)
|
|
|
|
|
{
|
|
|
|
|
_frames.push_back(frame);
|
|
|
|
|
frame->retain();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-10 17:02:18 +08:00
|
|
|
void e2d::Animation::add(const std::vector<Image*>& frames)
|
2018-05-10 00:58:43 +08:00
|
|
|
{
|
|
|
|
|
for (const auto &image : frames)
|
|
|
|
|
{
|
|
|
|
|
this->add(image);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double e2d::Animation::getInterval() const
|
|
|
|
|
{
|
|
|
|
|
return _interval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const std::vector<e2d::Image*>& e2d::Animation::getFrames() const
|
|
|
|
|
{
|
|
|
|
|
return _frames;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
e2d::Animation * e2d::Animation::clone() const
|
|
|
|
|
{
|
2018-05-14 00:36:01 +08:00
|
|
|
auto animation = new (std::nothrow) Animation(_interval);
|
2018-05-10 00:58:43 +08:00
|
|
|
for (auto frame : _frames)
|
|
|
|
|
{
|
2018-05-14 00:36:01 +08:00
|
|
|
animation->add(frame);
|
2018-05-10 00:58:43 +08:00
|
|
|
}
|
2018-05-14 00:36:01 +08:00
|
|
|
return animation;
|
2018-05-10 00:58:43 +08:00
|
|
|
}
|