Magic_Game/core/Action/MoveBy.cpp

43 lines
673 B
C++
Raw Normal View History

#include "..\e2daction.h"
2018-05-10 14:03:54 +08:00
e2d::MoveBy::MoveBy(double duration, Vector vector)
: ActionGradual(duration)
{
_deltaPos = vector;
}
2018-05-17 12:22:52 +08:00
e2d::MoveBy * e2d::MoveBy::create(double duration, Vector vector)
{
return Create<MoveBy>(duration, vector);
}
void e2d::MoveBy::_init()
{
ActionGradual::_init();
2018-05-10 00:58:43 +08:00
if (_target)
{
_startPos = _target->getPos();
}
}
void e2d::MoveBy::_update()
{
ActionGradual::_update();
2018-05-10 00:58:43 +08:00
if (_target)
{
2018-05-10 00:58:43 +08:00
_target->setPos(_startPos + _deltaPos * _delta);
}
}
e2d::MoveBy * e2d::MoveBy::clone() const
{
2018-05-17 12:22:52 +08:00
return Create<MoveBy>(_duration, _deltaPos);
}
e2d::MoveBy * e2d::MoveBy::reverse() const
{
2018-05-17 12:22:52 +08:00
return Create<MoveBy>(_duration, -_deltaPos);
}