Skip to content

Commit 3796062

Browse files
author
Robert Boyd
committed
Issue cocos2d#739: Updating MoveTo with stackable actions.
1 parent 89bb023 commit 3796062

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

cocos2d/actions/CCActionInterval.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ cc.MoveTo = cc.ActionInterval.extend(/** @lends cc.MoveTo# */{
780780
*/
781781
startWithTarget:function (target) {
782782
cc.ActionInterval.prototype.startWithTarget.call(this, target);
783-
this._startPosition = target.getPosition();
783+
this._previousPosition = this._startPosition = target.getPosition();
784784
this._delta = cc.pSub(this._endPosition, this._startPosition);
785785
},
786786

@@ -789,8 +789,13 @@ cc.MoveTo = cc.ActionInterval.extend(/** @lends cc.MoveTo# */{
789789
*/
790790
update:function (time) {
791791
if (this._target) {
792-
this._target.setPosition(cc.p(this._startPosition.x + this._delta.x * time,
793-
this._startPosition.y + this._delta.y * time));
792+
var currentPos = this._target.getPosition();
793+
var diff = cc.pSub(currentPos, this._previousPosition);
794+
this._startPosition = cc.pAdd(this._startPosition, diff);
795+
var newPos = cc.p(this._startPosition.x + this._delta.x * time,
796+
this._startPosition.y + this._delta.y * time);
797+
this._target.setPosition(newPos);
798+
this._previousPosition = newPos;
794799
}
795800
},
796801

0 commit comments

Comments
 (0)