Skip to content

Commit 1dfa905

Browse files
committed
Merge pull request cocos2d#1839 from VisualSJ/develop-repeat
Issue #3943: Add the cc.action.repeat() and cc.action.repeatForever()
2 parents 60c141a + cbbc3eb commit 1dfa905

File tree

7 files changed

+310
-65
lines changed

7 files changed

+310
-65
lines changed

cocos2d/actions/CCAction.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ cc.FiniteTimeAction = cc.Action.extend(/** @lends cc.FiniteTimeAction# */{
214214
* @return {Number}
215215
*/
216216
getDuration:function () {
217-
return this._duration;
217+
return this._duration * (this._times || 1);
218218
},
219219

220220
/** set duration in seconds of the action

cocos2d/actions/CCActionCamera.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ cc.OrbitCamera = cc.ActionCamera.extend(/** @lends cc.OrbitCamera# */{
204204
},
205205

206206
update:function (dt) {
207+
dt = this._computeEaseTime(dt);
207208
var r = (this._radius + this._deltaRadius * dt) * cc.Camera.getZEye();
208209
var za = this._radZ + this._radDeltaZ * dt;
209210
var xa = this._radX + this._radDeltaX * dt;

cocos2d/actions/CCActionCatmullRom.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ cc.CardinalSplineTo = cc.ActionInterval.extend(/** @lends cc.CardinalSplineTo# *
189189
* @param {Number} time
190190
*/
191191
update:function (time) {
192+
time = this._computeEaseTime(time);
192193
var p, lt;
193194
var ps = this._points;
194195
// eg.

cocos2d/actions/CCActionEase.js

Lines changed: 84 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,11 @@ cc.easeIn = function (rate) {
237237
_rate: rate,
238238
easing: function (dt) {
239239
return Math.pow(dt, this._rate);
240-
}};
240+
},
241+
reverse: function(){
242+
return cc.easeIn(1 / this._rate);
243+
}
244+
};
241245
};
242246

243247
/**
@@ -284,7 +288,11 @@ cc.easeOut = function (rate) {
284288
_rate: rate,
285289
easing: function (dt) {
286290
return Math.pow(dt, 1 / this._rate);
287-
}};
291+
},
292+
reverse: function(){
293+
return cc.easeOut(1 / this._rate)
294+
}
295+
};
288296
};
289297

290298
/**
@@ -339,7 +347,11 @@ cc.easeInOut = function (rate) {
339347
return 0.5 * Math.pow(dt, this._rate);
340348
else
341349
return 1.0 - 0.5 * Math.pow(2 - dt, this._rate);
342-
}};
350+
},
351+
reverse: function(){
352+
return cc.easeInOut(this._rate);
353+
}
354+
};
343355
};
344356

345357
/**
@@ -383,6 +395,9 @@ cc.EaseExponentialIn.create = function (action) {
383395
cc._easeExponentialInObj = {
384396
easing: function(dt){
385397
return dt === 0 ? 0 : Math.pow(2, 10 * (dt - 1));
398+
},
399+
reverse: function(){
400+
return cc._easeExponentialOutObj;
386401
}
387402
};
388403
cc.easeExponentialIn = function(){
@@ -430,6 +445,9 @@ cc.EaseExponentialOut.create = function (action) {
430445
cc._easeExponentialOutObj = {
431446
easing: function(dt){
432447
return dt == 1 ? 1 : (-(Math.pow(2, -10 * dt)) + 1);
448+
},
449+
reverse: function(){
450+
return cc._easeExponentialInObj;
433451
}
434452
};
435453
cc.easeExponentialOut = function(){
@@ -491,6 +509,9 @@ cc._easeExponentialInOutObj = {
491509
return 0.5 * (-Math.pow(2, -10 * (dt - 1)) + 2);
492510
}
493511
return dt;
512+
},
513+
reverse: function(){
514+
return cc._easeExponentialInOutObj;
494515
}
495516
};
496517
cc.easeExponentialInOut = function(){
@@ -539,6 +560,9 @@ cc.EaseSineIn.create = function (action) {
539560
cc._easeSineInObj = {
540561
easing: function(dt){
541562
return (dt===0 || dt===1) ? dt : -1 * Math.cos(dt * Math.PI / 2) + 1;
563+
},
564+
reverse: function(){
565+
return cc._easeSineOutObj;
542566
}
543567
};
544568
cc.easeSineIn = function(){
@@ -587,6 +611,9 @@ cc.EaseSineOut.create = function (action) {
587611
cc._easeSineOutObj = {
588612
easing: function(dt){
589613
return (dt===0 || dt==1) ? dt : Math.sin(dt * Math.PI / 2);
614+
},
615+
reverse: function(){
616+
return cc._easeSineInObj;
590617
}
591618
};
592619
cc.easeSineOut = function(){
@@ -635,6 +662,9 @@ cc.EaseSineInOut.create = function (action) {
635662
cc._easeSineInOutObj = {
636663
easing: function(dt){
637664
return (dt === 0 || dt === 1) ? dt : -0.5 * (Math.cos(Math.PI * dt) - 1);
665+
},
666+
reverse: function(){
667+
return cc._easeSineInOutObj;
638668
}
639669
};
640670
cc.easeSineInOut = function(){
@@ -772,7 +802,10 @@ cc._easeElasticInObj = {
772802
return dt;
773803
dt = dt - 1;
774804
return -Math.pow(2, 10 * dt) * Math.sin((dt - (0.3 / 4)) * Math.PI * 2 / 0.3);
775-
}
805+
},
806+
reverse:function(){
807+
return cc._easeElasticOutObj;
808+
}
776809
};
777810

778811
cc.easeElasticIn = function (period) {
@@ -784,7 +817,14 @@ cc.easeElasticIn = function (period) {
784817
return dt;
785818
dt = dt - 1;
786819
return -Math.pow(2, 10 * dt) * Math.sin((dt - (this._period / 4)) * Math.PI * 2 / this._period);
787-
}};
820+
},
821+
/**
822+
* @return {cc.EaseElasticIn}
823+
*/
824+
reverse:function () {
825+
return cc.easeElasticOut(this._period);
826+
}
827+
};
788828
}
789829
return cc._easeElasticInObj;
790830
};
@@ -841,6 +881,9 @@ cc.EaseElasticOut.create = function (action, period) {
841881
cc._easeElasticOutObj = {
842882
easing: function (dt) {
843883
return (dt === 0 || dt === 1) ? dt : Math.pow(2, -10 * dt) * Math.sin((dt - (0.3 / 4)) * Math.PI * 2 / 0.3) + 1;
884+
},
885+
reverse:function(){
886+
return cc._easeElasticInObj;
844887
}
845888
};
846889

@@ -850,7 +893,11 @@ cc.easeElasticOut = function (period) {
850893
_period: period,
851894
easing: function (dt) {
852895
return (dt === 0 || dt === 1) ? dt : Math.pow(2, -10 * dt) * Math.sin((dt - (this._period / 4)) * Math.PI * 2 / this._period) + 1;
853-
}};
896+
},
897+
reverse:function(){
898+
return cc.easeElasticIn(this._period);
899+
}
900+
};
854901
}
855902
return cc._easeElasticOutObj;
856903
};
@@ -932,7 +979,11 @@ cc.easeElasticInOut = function (period) {
932979
newT = Math.pow(2, -10 * dt) * Math.sin((dt - s) * Math.PI * 2 / locPeriod) * 0.5 + 1;
933980
}
934981
return newT;
935-
}};
982+
},
983+
reverse: function(){
984+
return cc.EaseElasticInOut(this._period);
985+
}
986+
};
936987
};
937988

938989
/**
@@ -1043,6 +1094,9 @@ cc._bounceTime = function (time1) {
10431094
cc._easeBounceInObj = {
10441095
easing: function(dt){
10451096
return 1 - cc._bounceTime(1 - dt);
1097+
},
1098+
reverse: function(){
1099+
return cc._easeBounceOutObj;
10461100
}
10471101
};
10481102
cc.easeBounceIn = function(){
@@ -1092,6 +1146,9 @@ cc.EaseBounceOut.create = function (action) {
10921146
cc._easeBounceOutObj = {
10931147
easing: function(dt){
10941148
return cc._bounceTime(dt);
1149+
},
1150+
reverse:function () {
1151+
return cc._easeBounceInObj;
10951152
}
10961153
};
10971154
cc.easeBounceOut = function(){
@@ -1154,7 +1211,11 @@ cc._easeBounceInOutObj = {
11541211
newT = cc._bounceTime(time1 * 2 - 1) * 0.5 + 0.5;
11551212
}
11561213
return newT;
1157-
}};
1214+
},
1215+
reverse: function(){
1216+
return cc._easeBounceInOutObj;
1217+
}
1218+
};
11581219

11591220
cc.easeBounceInOut = function(){
11601221
return cc._easeBounceInOutObj;
@@ -1206,7 +1267,11 @@ cc._easeBackInObj = {
12061267
easing: function (time1) {
12071268
var overshoot = 1.70158;
12081269
return (time1===0 || time1===1) ? time1 : time1 * time1 * ((overshoot + 1) * time1 - overshoot);
1209-
}};
1270+
},
1271+
reverse: function(){
1272+
return cc._easeBackOutObj;
1273+
}
1274+
};
12101275

12111276
cc.easeBackIn = function(){
12121277
return cc._easeBackInObj;
@@ -1258,7 +1323,11 @@ cc._easeBackOutObj = {
12581323
var overshoot = 1.70158;
12591324
time1 = time1 - 1;
12601325
return time1 * time1 * ((overshoot + 1) * time1 + overshoot) + 1;
1261-
}};
1326+
},
1327+
reverse: function(){
1328+
return cc._easeBackInObj;
1329+
}
1330+
};
12621331

12631332
cc.easeBackOut = function(){
12641333
return cc._easeBackOutObj;
@@ -1321,7 +1390,11 @@ cc._easeBackInOutObj = {
13211390
time1 = time1 - 2;
13221391
return (time1 * time1 * ((overshoot + 1) * time1 + overshoot)) / 2 + 1;
13231392
}
1324-
}};
1393+
},
1394+
reverse: function(){
1395+
return cc._easeBackInOutObj;
1396+
}
1397+
};
13251398

13261399
cc.easeBackInOut = function(){
13271400
return cc._easeBackInOutObj;

0 commit comments

Comments
 (0)