4545 * @param {Number } t
4646 * @return {cc.Point }
4747 */
48- cc . CardinalSplineAt = function ( p0 , p1 , p2 , p3 , tension , t ) {
48+ cc . CardinalSplineAt = function ( p0 , p1 , p2 , p3 , tension , t ) {
4949 var t2 = t * t ;
5050 var t3 = t2 * t ;
5151
6969 * returns a new copy of the array reversed.
7070 * @return {Array }
7171 */
72- cc . reverseControlPoints = function ( controlPoints ) {
72+ cc . reverseControlPoints = function ( controlPoints ) {
7373 var newArray = [ ] ;
7474 for ( var i = controlPoints . length - 1 ; i >= 0 ; i -- ) {
7575 newArray . push ( cc . p ( controlPoints [ i ] . x , controlPoints [ i ] . y ) ) ;
7676 }
7777 return newArray ;
7878} ;
7979
80- cc . copyControlPoints = function ( controlPoints ) {
80+ cc . copyControlPoints = function ( controlPoints ) {
8181 var newArray = [ ] ;
82- for ( var i = 0 ; i < controlPoints . length ; i ++ )
82+ for ( var i = 0 ; i < controlPoints . length ; i ++ )
8383 newArray . push ( cc . p ( controlPoints [ i ] . x , controlPoints [ i ] . y ) ) ;
8484 return newArray ;
8585} ;
@@ -90,8 +90,8 @@ cc.copyControlPoints = function( controlPoints){
9090 * @param {Number } pos
9191 * @return {Array }
9292 */
93- cc . getControlPointAt = function ( controlPoints , pos ) {
94- var p = Math . min ( controlPoints . length - 1 , Math . max ( pos , 0 ) ) ;
93+ cc . getControlPointAt = function ( controlPoints , pos ) {
94+ var p = Math . min ( controlPoints . length - 1 , Math . max ( pos , 0 ) ) ;
9595 return controlPoints [ p ] ;
9696} ;
9797
@@ -160,8 +160,8 @@ cc.CardinalSplineTo = cc.ActionInterval.extend(/** @lends cc.CardinalSplineTo# *
160160 * returns a new clone of the action
161161 * @returns {cc.CardinalSplineTo }
162162 */
163- clone :function ( ) {
164- var action = new cc . CardinalSplineTo ( ) ;
163+ clone :function ( ) {
164+ var action = new cc . CardinalSplineTo ( ) ;
165165 action . initWithDuration ( this . _duration , cc . copyControlPoints ( this . _points ) , this . _tension ) ;
166166 return action ;
167167 } ,
@@ -172,7 +172,7 @@ cc.CardinalSplineTo = cc.ActionInterval.extend(/** @lends cc.CardinalSplineTo# *
172172 startWithTarget :function ( target ) {
173173 cc . ActionInterval . prototype . startWithTarget . call ( this , target ) ;
174174 // Issue #1441 from cocos2d-iphone
175- this . _deltaT = 1 / ( this . _points . length - 1 ) ;
175+ this . _deltaT = 1 / ( this . _points . length - 1 ) ;
176176
177177 this . _previousPosition = this . _target . getPosition ( ) ;
178178 this . _accumulatedDiff = cc . p ( 0 , 0 ) ;
@@ -183,32 +183,39 @@ cc.CardinalSplineTo = cc.ActionInterval.extend(/** @lends cc.CardinalSplineTo# *
183183 */
184184 update :function ( time ) {
185185 var p , lt ;
186-
186+ var ps = this . _points ;
187187 // eg.
188188 // p..p..p..p..p..p..p
189189 // 1..2..3..4..5..6..7
190190 // want p to be 1, 2, 3, 4, 5, 6
191191 if ( time == 1 ) {
192- p = this . _points . length - 1 ;
192+ p = ps . length - 1 ;
193193 lt = 1 ;
194194 } else {
195- p = 0 | ( time / this . _deltaT ) ;
196- lt = ( time - this . _deltaT * p ) / this . _deltaT ;
195+ var locDT = this . _deltaT ;
196+ p = 0 | ( time / locDT ) ;
197+ lt = ( time - locDT * p ) / locDT ;
197198 }
198199
199200 var newPos = cc . CardinalSplineAt (
200- cc . getControlPointAt ( this . _points , p - 1 ) ,
201- cc . getControlPointAt ( this . _points , p - 0 ) ,
202- cc . getControlPointAt ( this . _points , p + 1 ) ,
203- cc . getControlPointAt ( this . _points , p + 2 ) ,
201+ cc . getControlPointAt ( ps , p - 1 ) ,
202+ cc . getControlPointAt ( ps , p - 0 ) ,
203+ cc . getControlPointAt ( ps , p + 1 ) ,
204+ cc . getControlPointAt ( ps , p + 2 ) ,
204205 this . _tension , lt ) ;
205206
206- if ( cc . ENABLE_STACKABLE_ACTIONS ) {
207- var node = this . _target ;
208- var diff = cc . pSub ( node . getPosition ( ) , this . _previousPosition ) ;
209- if ( diff . x != 0 || diff . y != 0 ) {
210- this . _accumulatedDiff = cc . pAdd ( this . _accumulatedDiff , diff ) ;
211- newPos = cc . pAdd ( newPos , this . _accumulatedDiff ) ;
207+ if ( cc . ENABLE_STACKABLE_ACTIONS ) {
208+ var tempX , tempY ;
209+ tempX = this . _target . getPositionX ( ) - this . _previousPosition . x ;
210+ tempY = this . _target . getPositionY ( ) - this . _previousPosition . y ;
211+ if ( tempX != 0 || tempY != 0 ) {
212+ var locAccDiff = this . _accumulatedDiff ;
213+ tempX = locAccDiff . x + tempX ;
214+ tempY = locAccDiff . y + tempY ;
215+ locAccDiff . x = tempX ;
216+ locAccDiff . y = tempY ;
217+ newPos . x += tempX ;
218+ newPos . y += tempY ;
212219 }
213220 }
214221 this . updatePosition ( newPos ) ;
@@ -315,20 +322,24 @@ cc.CardinalSplineBy = cc.CardinalSplineTo.extend(/** @lends cc.CardinalSplineBy#
315322 }
316323
317324 // convert to "diffs" to "reverse absolute"
318- var reverseArray = cc . reverseControlPoints ( copyConfig ) ;
325+ var reverseArray = cc . reverseControlPoints ( copyConfig ) ;
319326
320327 // 1st element (which should be 0,0) should be here too
321328 p = reverseArray [ reverseArray . length - 1 ] ;
322329 reverseArray . pop ( ) ;
323330
324- p = cc . pNeg ( p ) ;
331+ p . x = - p . x ;
332+ p . y = - p . y ;
333+
325334 reverseArray . unshift ( p ) ;
326- for ( i = 1 ; i < reverseArray . length ; ++ i ) {
335+ for ( var i = 1 ; i < reverseArray . length ; ++ i ) {
327336 current = reverseArray [ i ] ;
328- current = cc . pNeg ( current ) ;
329- var abs = cc . pAdd ( current , p ) ;
330- reverseArray [ i ] = abs ;
331- p = abs ;
337+ current . x = - current . x ;
338+ current . y = - current . y ;
339+ current . x += p . x ;
340+ current . y += p . y ;
341+ reverseArray [ i ] = current ;
342+ p = current ;
332343 }
333344 return cc . CardinalSplineBy . create ( this . _duration , reverseArray , this . _tension ) ;
334345 } ,
@@ -338,16 +349,19 @@ cc.CardinalSplineBy = cc.CardinalSplineTo.extend(/** @lends cc.CardinalSplineBy#
338349 * @param {cc.Point } newPos
339350 */
340351 updatePosition :function ( newPos ) {
341- var p = cc . pAdd ( newPos , this . _startPosition ) ;
342- this . _target . setPosition ( p ) ;
343- this . _previousPosition = p ;
352+ var pos = this . _startPosition ;
353+ var posX = newPos . x + pos . x ;
354+ var posY = newPos . y + pos . y ;
355+ this . _target . setPosition ( posX , posY ) ;
356+ this . _previousPosition . x = posX ;
357+ this . _previousPosition . y = posY ;
344358 } ,
345359
346360 /**
347361 * returns a new clone of the action
348362 * @returns {cc.CardinalSplineBy }
349363 */
350- clone :function ( ) {
364+ clone :function ( ) {
351365 var a = new cc . CardinalSplineBy ( ) ;
352366 a . initWithDuration ( this . _duration , cc . copyControlPoints ( this . _points ) , this . _tension ) ;
353367 return a ;
@@ -393,7 +407,7 @@ cc.CatmullRomTo = cc.CardinalSplineTo.extend(/** @lends cc.CatmullRomTo# */{
393407 * returns a new clone of the action
394408 * @returns {cc.CatmullRomTo }
395409 */
396- clone :function ( ) {
410+ clone :function ( ) {
397411 var action = new cc . CatmullRomTo ( ) ;
398412 action . initWithDuration ( this . _duration , cc . copyControlPoints ( this . _points ) ) ;
399413 return action ;
@@ -438,7 +452,7 @@ cc.CatmullRomBy = cc.CardinalSplineBy.extend({
438452 * returns a new clone of the action
439453 * @returns {cc.CatmullRomBy }
440454 */
441- clone :function ( ) {
455+ clone :function ( ) {
442456 var action = new cc . CatmullRomBy ( ) ;
443457 action . initWithDuration ( this . _duration , cc . copyControlPoints ( this . _points ) ) ;
444458 return action ;
0 commit comments