Magic_Game/core/Action/ActionMoveBy.cpp

44 lines
767 B
C++
Raw Normal View History

#include "..\eaction.h"
2018-01-30 16:45:38 +08:00
2018-02-27 21:07:43 +08:00
e2d::ActionMoveBy::ActionMoveBy(double duration, Vector vector) :
ActionGradual(duration)
2018-01-30 16:45:38 +08:00
{
m_MoveVec = vector;
}
void e2d::ActionMoveBy::_init()
2018-01-30 16:45:38 +08:00
{
ActionGradual::_init();
2018-01-30 16:45:38 +08:00
if (m_pTarget)
{
m_BeginPos = m_pTarget->getPos();
}
}
void e2d::ActionMoveBy::_update()
2018-01-30 16:45:38 +08:00
{
ActionGradual::_update();
2018-01-30 16:45:38 +08:00
if (m_pTarget == nullptr)
{
this->stop();
return;
}
// <20>ƶ<EFBFBD><C6B6>ڵ<EFBFBD>
m_pTarget->setPos(
m_BeginPos.x + m_MoveVec.x * m_fRateOfProgress,
m_BeginPos.y + m_MoveVec.y * m_fRateOfProgress
);
}
e2d::ActionMoveBy * e2d::ActionMoveBy::clone() const
2018-01-30 16:45:38 +08:00
{
return new ActionMoveBy(m_fDuration, m_MoveVec);
2018-01-30 16:45:38 +08:00
}
e2d::ActionMoveBy * e2d::ActionMoveBy::reverse() const
2018-01-30 16:45:38 +08:00
{
return new ActionMoveBy(m_fDuration, Vector(-m_MoveVec.x, -m_MoveVec.y));
2018-01-30 16:45:38 +08:00
}