From 7a28ddace2596da57b6ba3d431466b293111700d Mon Sep 17 00:00:00 2001 From: Nomango <569629550@qq.com> Date: Tue, 29 May 2018 22:12:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DMoveBy=E5=8A=A8=E4=BD=9C?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/Action/MoveBy.cpp | 11 +++++++++-- core/e2daction.h | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/core/Action/MoveBy.cpp b/core/Action/MoveBy.cpp index e4da97a6..5d14588d 100644 --- a/core/Action/MoveBy.cpp +++ b/core/Action/MoveBy.cpp @@ -14,7 +14,7 @@ void e2d::MoveBy::_init() if (_target) { - _startPos = _target->getPos(); + _prevPos = _startPos = _target->getPos(); } } @@ -24,7 +24,14 @@ void e2d::MoveBy::_update() if (_target) { - _target->setPos(_startPos + _deltaPos * _delta); + Point currentPos = _target->getPos(); + Vector diff = currentPos - _prevPos; + _startPos = _startPos + diff; + + Point newPos = _startPos + (_deltaPos * _delta); + _target->setPos(newPos); + + _prevPos = newPos; } } diff --git a/core/e2daction.h b/core/e2daction.h index de88ffb3..8b4bd63c 100644 --- a/core/e2daction.h +++ b/core/e2daction.h @@ -144,6 +144,7 @@ protected: protected: Point _startPos; + Point _prevPos; Vector _deltaPos; };