53 lines
980 B
C++
53 lines
980 B
C++
|
|
#include "..\eactions.h"
|
|||
|
|
|
|||
|
|
|
|||
|
|
e2d::ActionMoveBy::ActionMoveBy(float duration, EVec vector) :
|
|||
|
|
Animation(duration)
|
|||
|
|
{
|
|||
|
|
m_MoveVector = vector;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
e2d::ActionMoveBy::~ActionMoveBy()
|
|||
|
|
{
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void e2d::ActionMoveBy::_init()
|
|||
|
|
{
|
|||
|
|
Animation::_init();
|
|||
|
|
m_BeginPos = m_pTarget->getPos();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void e2d::ActionMoveBy::_exec()
|
|||
|
|
{
|
|||
|
|
while (Animation::_isDelayEnough())
|
|||
|
|
{
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD>λ<EFBFBD><CEBB>
|
|||
|
|
float scale = static_cast<float>(m_nDuration) / m_nTotalDuration;
|
|||
|
|
// <20>ƶ<EFBFBD> Sprite
|
|||
|
|
m_pTarget->setPos(
|
|||
|
|
m_BeginPos.x + m_MoveVector.x * scale,
|
|||
|
|
m_BeginPos.y + m_MoveVector.y * scale
|
|||
|
|
);
|
|||
|
|
// <20>ж϶<D0B6><CFB6><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
if (_isEnd())
|
|||
|
|
{
|
|||
|
|
this->stop();
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void e2d::ActionMoveBy::_reset()
|
|||
|
|
{
|
|||
|
|
Animation::_reset();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
e2d::ActionMoveBy * e2d::ActionMoveBy::copy() const
|
|||
|
|
{
|
|||
|
|
return new ActionMoveBy(m_nAnimationInterval / 1000.0f, m_MoveVector);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
e2d::ActionMoveBy * e2d::ActionMoveBy::reverse() const
|
|||
|
|
{
|
|||
|
|
return new ActionMoveBy(m_nTotalDuration / 1000.0f, EVec(-m_MoveVector.x, -m_MoveVector.y));
|
|||
|
|
}
|