Magic_Game/core/Action/Animation.cpp

90 lines
1.3 KiB
C++
Raw Normal View History

2017-10-19 00:50:04 +08:00
#include "..\eactions.h"
2018-01-30 16:45:38 +08:00
e2d::EAnimation::EAnimation()
: m_nFrameIndex(0)
2017-10-19 00:50:04 +08:00
{
}
2018-01-30 16:45:38 +08:00
e2d::EAnimation::EAnimation(float invertal)
: m_nFrameIndex(0)
, m_fInterval(invertal)
2017-10-19 00:50:04 +08:00
{
}
e2d::EAnimation::~EAnimation()
{
2018-02-03 22:04:43 +08:00
for (auto frame : m_vFrames)
{
2018-02-03 22:04:43 +08:00
SafeRelease(&frame);
}
2017-10-19 00:50:04 +08:00
}
2018-01-30 16:45:38 +08:00
void e2d::EAnimation::setInterval(float interval)
{
m_fInterval = max(interval, 0);
}
void e2d::EAnimation::_init()
2017-10-19 00:50:04 +08:00
{
EAction::_init();
}
void e2d::EAnimation::_update()
2017-10-19 00:50:04 +08:00
{
EAction::_update();
2017-11-03 12:51:01 +08:00
if (m_pTarget == nullptr)
{
this->stop();
return;
}
2017-11-03 12:51:01 +08:00
2017-10-19 00:50:04 +08:00
// <20>ж<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>
2018-01-30 16:45:38 +08:00
while ((ETime::getTotalTime() - m_fLast) >= m_fInterval)
2017-10-19 00:50:04 +08:00
{
// <20><><EFBFBD>¼<EFBFBD>¼ʱ<C2BC><CAB1>
2018-01-30 16:45:38 +08:00
m_fLast += m_fInterval;
// <20><><EFBFBD>عؼ<D8B9>֡
2018-02-06 15:34:47 +08:00
static_cast<ESprite*>(m_pTarget)->loadFrom(m_vFrames[m_nFrameIndex]);
m_nFrameIndex++;
// <20>ж϶<D0B6><CFB6><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
if (m_nFrameIndex == m_vFrames.size())
{
this->stop();
break;
}
2017-10-19 00:50:04 +08:00
}
}
2018-02-06 15:34:47 +08:00
void e2d::EAnimation::reset()
2017-10-19 00:50:04 +08:00
{
2018-02-06 15:34:47 +08:00
EAction::reset();
m_nFrameIndex = 0;
}
2018-02-03 22:04:43 +08:00
void e2d::EAnimation::addKeyframe(EImage * frame)
{
if (frame)
{
m_vFrames.push_back(frame);
frame->retain();
}
}
e2d::EAnimation * e2d::EAnimation::clone() const
{
2018-01-30 16:45:38 +08:00
auto a = new EAnimation(m_fInterval);
2018-02-03 22:04:43 +08:00
for (auto frame : m_vFrames)
{
2018-02-03 22:04:43 +08:00
a->addKeyframe(frame);
}
return a;
}
e2d::EAnimation * e2d::EAnimation::reverse() const
{
auto a = this->clone();
a->m_vFrames.reserve(m_vFrames.size());
return a;
2017-10-19 00:50:04 +08:00
}