Skip to content

Commit e261ceb

Browse files
author
SeanLin
committed
Merge pull request #753 from rboyd/739_stackable_bezier_and_spline
739 stackable bezier and spline
2 parents 3707ff2 + 233af6e commit e261ceb

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

cocos2d/actions/CCActionCatmullRom.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ cc.CardinalSplineTo = cc.ActionInterval.extend(/** @lends cc.CardinalSplineTo# *
146146
startWithTarget:function (target) {
147147
this._super(target);
148148
this._deltaT = 1 / this._points.length;
149+
150+
this._previousPosition = this._target.getPosition();
151+
this._accumulatedDiff = cc.p(0, 0);
149152
},
150153

151154
/**
@@ -169,6 +172,14 @@ cc.CardinalSplineTo = cc.ActionInterval.extend(/** @lends cc.CardinalSplineTo# *
169172
cc.getControlPointAt( this._points, p + 1),
170173
cc.getControlPointAt( this._points, p + 2),
171174
this._tension, lt);
175+
176+
var node = this._target;
177+
var diff = cc.pSub(node.getPosition(), this._previousPosition);
178+
if (diff.x != 0 || diff.y != 0) {
179+
this._accumulatedDiff = cc.pAdd(this._accumulatedDiff, diff);
180+
newPos = cc.pAdd(newPos, this._accumulatedDiff);
181+
}
182+
172183
this.updatePosition(newPos);
173184
},
174185

@@ -187,6 +198,7 @@ cc.CardinalSplineTo = cc.ActionInterval.extend(/** @lends cc.CardinalSplineTo# *
187198
*/
188199
updatePosition:function (newPos) {
189200
this._target.setPosition(newPos);
201+
this._previousPosition = newPos;
190202
},
191203

192204
/**
@@ -295,7 +307,9 @@ cc.CardinalSplineBy = cc.CardinalSplineTo.extend(/** @lends cc.CardinalSplineBy#
295307
* @param {cc.Point} newPos
296308
*/
297309
updatePosition:function (newPos) {
298-
this._target.setPosition(cc.pAdd(newPos, this._startPosition));
310+
var p = cc.pAdd(newPos, this._startPosition);
311+
this._target.setPosition(p)
312+
this._previousPosition = p;
299313
}
300314
});
301315

cocos2d/actions/CCActionInterval.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,7 @@ cc.BezierBy = cc.ActionInterval.extend(/** @lends cc.BezierBy# */{
11981198
*/
11991199
startWithTarget:function (target) {
12001200
cc.ActionInterval.prototype.startWithTarget.call(this, target);
1201-
this._startPosition = target.getPosition();
1201+
this._previousPosition = this._startPosition = target.getPosition();
12021202
},
12031203

12041204
/**
@@ -1218,7 +1218,14 @@ cc.BezierBy = cc.ActionInterval.extend(/** @lends cc.BezierBy# */{
12181218

12191219
var x = cc.bezierat(xa, xb, xc, xd, time);
12201220
var y = cc.bezierat(ya, yb, yc, yd, time);
1221-
this._target.setPosition(cc.pAdd(this._startPosition, cc.p(x, y)));
1221+
1222+
var currentPos = this._target.getPosition();
1223+
var diff = cc.pSub(currentPos, this._previousPosition);
1224+
this._startPosition = cc.pAdd(this._startPosition, diff);
1225+
var newPos = cc.pAdd(this._startPosition, cc.p(x, y));
1226+
1227+
this._target.setPosition(newPos);
1228+
this._previousPosition = newPos;
12221229
}
12231230
},
12241231

0 commit comments

Comments
 (0)