2018-05-08 20:03:29 +08:00
|
|
|
#include "..\e2daction.h"
|
2018-09-05 13:33:39 +08:00
|
|
|
#include "..\e2dnode.h"
|
2018-05-08 20:03:29 +08:00
|
|
|
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
e2d::MoveBy::MoveBy(float duration, Point vector)
|
2018-05-22 22:29:42 +08:00
|
|
|
: FiniteTimeAction(duration)
|
2018-05-08 20:03:29 +08:00
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
delta_pos_ = vector;
|
2018-05-08 20:03:29 +08:00
|
|
|
}
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
void e2d::MoveBy::Init()
|
2018-05-08 20:03:29 +08:00
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
FiniteTimeAction::Init();
|
2018-05-10 00:58:43 +08:00
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
if (target_)
|
2018-05-08 20:03:29 +08:00
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
prev_pos_ = start_pos_ = target_->GetPos();
|
2018-05-08 20:03:29 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
void e2d::MoveBy::Update()
|
2018-05-08 20:03:29 +08:00
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
FiniteTimeAction::Update();
|
2018-05-08 20:03:29 +08:00
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
if (target_)
|
2018-05-08 20:03:29 +08:00
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
Point currentPos = target_->GetPos();
|
|
|
|
|
Point diff = currentPos - prev_pos_;
|
|
|
|
|
start_pos_ = start_pos_ + diff;
|
2018-05-29 22:12:01 +08:00
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
Point newPos = start_pos_ + (delta_pos_ * delta_);
|
|
|
|
|
target_->SetPos(newPos);
|
2018-05-29 22:12:01 +08:00
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
prev_pos_ = newPos;
|
2018-05-08 20:03:29 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
e2d::MoveBy * e2d::MoveBy::Clone() const
|
2018-05-08 20:03:29 +08:00
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
return new (e2d::autorelease) MoveBy(duration_, delta_pos_);
|
2018-05-08 20:03:29 +08:00
|
|
|
}
|
|
|
|
|
|
2018-09-04 22:42:34 +08:00
|
|
|
e2d::MoveBy * e2d::MoveBy::Reverse() const
|
2018-05-08 20:03:29 +08:00
|
|
|
{
|
2018-09-04 22:42:34 +08:00
|
|
|
return new (e2d::autorelease) MoveBy(duration_, -delta_pos_);
|
2018-05-08 20:03:29 +08:00
|
|
|
}
|