Skip to content

Commit cea7e1c

Browse files
author
SeanLin
committed
Merge pull request #744 from rboyd/739_stackable_actions
739 stackable actions
2 parents 3622929 + 8cd425c commit cea7e1c

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

cocos2d/actions/CCActionInterval.js

+18-5
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

@@ -1068,7 +1073,7 @@ cc.JumpBy = cc.ActionInterval.extend(/** @lends cc.JumpBy# */{
10681073
*/
10691074
startWithTarget:function (target) {
10701075
cc.ActionInterval.prototype.startWithTarget.call(this, target);
1071-
this._startPosition = target.getPosition();
1076+
this._previousPosition = this._startPosition = target.getPosition();
10721077
},
10731078

10741079
/**
@@ -1079,8 +1084,16 @@ cc.JumpBy = cc.ActionInterval.extend(/** @lends cc.JumpBy# */{
10791084
var frac = time * this._jumps % 1.0;
10801085
var y = this._height * 4 * frac * (1 - frac);
10811086
y += this._delta.y * time;
1087+
10821088
var x = this._delta.x * time;
1083-
this._target.setPosition(cc.p(this._startPosition.x + x, this._startPosition.y + y));
1089+
1090+
var currentPos = this._target.getPosition();
1091+
1092+
var diff = cc.pSub(currentPos, this._previousPosition);
1093+
this._startPosition = cc.pAdd(diff, this._startPosition);
1094+
var newPos = cc.pAdd(this._startPosition, cc.p(x, y));
1095+
this._target.setPosition(newPos);
1096+
this._previousPosition = newPos;
10841097
}
10851098
},
10861099

cocos2d/actions/CCActionManager.js

-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ cc.ActionManager = cc.Class.extend({
9898
}
9999
//creates a array for that eleemnt to hold the actions
100100
this._actionAllocWithHashElement(element);
101-
cc.Assert((element.actions.indexOf(action) == -1), "ActionManager.addAction(),");
102101

103102
element.actions.push(action);
104103
action.startWithTarget(target);

0 commit comments

Comments
 (0)