Skip to content

Commit 0a707e9

Browse files
authored
Merge pull request #3504 from pandamicro/develop
Fix action recycling issue with lock
2 parents df31451 + f65a230 commit 0a707e9

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

cocos2d/actions/CCActionInterval.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,7 @@ cc.RotateTo = cc.ActionInterval.extend(/** @lends cc.RotateTo# */{
10831083
initWithDuration: function (duration, deltaAngleX, deltaAngleY) {
10841084
if (cc.ActionInterval.prototype.initWithDuration.call(this, duration)) {
10851085
this._dstAngleX = deltaAngleX || 0;
1086-
this._dstAngleY = deltaAngleY || this._dstAngleX;
1086+
this._dstAngleY = deltaAngleY !== undefined ? deltaAngleY : this._dstAngleX;
10871087
return true;
10881088
}
10891089
return false;

cocos2d/core/CCActionManager.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ cc.HashElement = function () {
3636
this.actionIndex = 0;
3737
this.currentAction = null; //CCAction
3838
this.paused = false;
39+
this.lock = false;
3940
};
4041

4142
/**
@@ -84,6 +85,7 @@ cc.ActionManager = cc.Class.extend(/** @lends cc.ActionManager# */{
8485
element.currentAction = null;
8586
element.paused = false;
8687
element.target = null;
88+
element.lock = false;
8789
this._elementPool.push(element);
8890
},
8991

@@ -303,7 +305,7 @@ cc.ActionManager = cc.Class.extend(/** @lends cc.ActionManager# */{
303305

304306
_deleteHashElement:function (element) {
305307
var ret = false;
306-
if (element) {
308+
if (element && !element.lock) {
307309
if (this._hashTargets[element.target.__instanceId]) {
308310
delete this._hashTargets[element.target.__instanceId];
309311
var targets = this._arrayTargets;
@@ -329,6 +331,7 @@ cc.ActionManager = cc.Class.extend(/** @lends cc.ActionManager# */{
329331
this._currentTarget = locTargets[elt];
330332
locCurrTarget = this._currentTarget;
331333
if (!locCurrTarget.paused && locCurrTarget.actions) {
334+
locCurrTarget.lock = true;
332335
// The 'actions' CCMutableArray may change while inside this loop.
333336
for (locCurrTarget.actionIndex = 0; locCurrTarget.actionIndex < locCurrTarget.actions.length; locCurrTarget.actionIndex++) {
334337
locCurrTarget.currentAction = locCurrTarget.actions[locCurrTarget.actionIndex];
@@ -338,16 +341,16 @@ cc.ActionManager = cc.Class.extend(/** @lends cc.ActionManager# */{
338341
//use for speed
339342
locCurrTarget.currentAction.step(dt * ( locCurrTarget.currentAction._speedMethod ? locCurrTarget.currentAction._speed : 1 ) );
340343

341-
if (locCurrTarget.currentAction.isDone()) {
344+
if (locCurrTarget.currentAction && locCurrTarget.currentAction.isDone()) {
342345
locCurrTarget.currentAction.stop();
343346
var action = locCurrTarget.currentAction;
344-
// Make currentAction nil to prevent removeAction from salvaging it.
345347
locCurrTarget.currentAction = null;
346348
this.removeAction(action);
347349
}
348350

349351
locCurrTarget.currentAction = null;
350352
}
353+
locCurrTarget.lock = false;
351354
}
352355
// only delete currentTarget if no actions were scheduled during the cycle (issue #481)
353356
if (locCurrTarget.actions.length === 0) {

0 commit comments

Comments
 (0)