51 lines
995 B
C++
51 lines
995 B
C++
|
|
#include "..\easy2d.h"
|
|||
|
|
#include "..\Win\winbase.h"
|
|||
|
|
|
|||
|
|
ActionMoveBy::ActionMoveBy(float duration, CVector vec) :
|
|||
|
|
Animation(duration)
|
|||
|
|
{
|
|||
|
|
m_MoveVector = vec;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
ActionMoveBy::~ActionMoveBy()
|
|||
|
|
{
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void ActionMoveBy::_init()
|
|||
|
|
{
|
|||
|
|
Animation::_init();
|
|||
|
|
m_BeginPos = m_pTargetSprite->getPos();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void ActionMoveBy::_exec(steady_clock::time_point nNow)
|
|||
|
|
{
|
|||
|
|
while (Animation::_isDelayEnough(nNow))
|
|||
|
|
{
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD>λ<EFBFBD><CEBB>
|
|||
|
|
float scale = float(m_nDuration) / m_nTotalDuration;
|
|||
|
|
// <20>ƶ<EFBFBD> Sprite
|
|||
|
|
m_pTargetSprite->setPos(int(m_BeginPos.x + m_MoveVector.x * scale),
|
|||
|
|
int(m_BeginPos.y + m_MoveVector.y * scale));
|
|||
|
|
// <20>ж϶<D0B6><CFB6><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
if (_isEnd())
|
|||
|
|
{
|
|||
|
|
this->stop();
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void ActionMoveBy::_reset()
|
|||
|
|
{
|
|||
|
|
Animation::_reset();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
ActionMoveBy * ActionMoveBy::copy() const
|
|||
|
|
{
|
|||
|
|
return new ActionMoveBy(m_nAnimationInterval / 1000.0f, m_MoveVector);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
ActionMoveBy * ActionMoveBy::reverse() const
|
|||
|
|
{
|
|||
|
|
return new ActionMoveBy(m_nTotalDuration / 1000.0f, CVector(-m_MoveVector.x, -m_MoveVector.y));
|
|||
|
|
}
|