From 6aeda11e6e9ae3eb76e824f4b181efd945fb6a92 Mon Sep 17 00:00:00 2001 From: pandamicro Date: Thu, 7 Jan 2016 22:50:19 +0800 Subject: [PATCH 1/2] Made Action independent from retain release --- jsb/jsb-etc.js | 107 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) diff --git a/jsb/jsb-etc.js b/jsb/jsb-etc.js index 1f5e905a2a..71c65054af 100644 --- a/jsb/jsb-etc.js +++ b/jsb/jsb-etc.js @@ -78,6 +78,113 @@ cc.Scheduler.prototype.unschedule = function (callback, target) { this._unschedule(target, callback); }; +// Independent Action from retain/release +var actionArr = [ + cc.ActionEase, + cc.EaseExponentialIn, + cc.EaseExponentialOut, + cc.EaseExponentialInOut, + cc.EaseSineIn, + cc.EaseSineOut, + cc.EaseSineInOut, + cc.EaseBounce, + cc.EaseBounceIn, + cc.EaseBounceOut, + cc.EaseBounceInOut, + cc.EaseBackIn, + cc.EaseBackOut, + cc.EaseBackInOut, + cc.EaseRateAction, + cc.EaseIn, + cc.EaseElastic, + cc.EaseElasticIn, + cc.EaseElasticOut, + cc.EaseElasticInOut, + cc.RemoveSelf, + cc.FlipX, + cc.FlipY, + cc.Place, + cc.CallFunc, + cc.DelayTime, + cc.Sequence, + cc.Spawn, + cc.Speed, + cc.Repeat, + cc.RepeatForever, + cc.Follow, + cc.TargetedAction, + cc.Animate, + cc.OrbitCamera, + cc.GridAction, + cc.ProgressTo, + cc.ProgressFromTo, + cc.ActionInterval, + cc.RotateTo, + cc.RotateBy, + cc.MoveBy, + cc.MoveTo, + cc.SkewTo, + cc.SkewBy, + cc.JumpTo, + cc.JumpBy, + cc.ScaleTo, + cc.ScaleBy, + cc.Blink, + cc.FadeTo, + cc.FadeIn, + cc.FadeOut, + cc.TintTo, + cc.TintBy, +]; + +function getCtorReplacer (proto) { + var ctor = proto._ctor; + return function () { + ctor.apply(this, arguments); + this.retain(); + this._retained = true; + }; +} + +for (var i = 0; i < actionArr.length; ++i) { + var proto = actionArr[i].prototype; + proto._ctor = getCtorReplacer(proto); +} + +function setChainFuncReplacer (proto, name) { + var oldFunc = proto[name]; + proto[name] = function () { + if (this._retained) { + this.release(); + this._retained = false; + } + var newAction = oldFunc.apply(this, arguments); + newAction.retain(); + newAction._retained = true; + }; +} + +setChainFuncReplacer(cc.ActionInterval.prototype, 'repeat'); +setChainFuncReplacer(cc.ActionInterval.prototype, 'repeatForever'); +setChainFuncReplacer(cc.ActionInterval.prototype, 'easing'); + +var jsbRunAction = cc.Node.prototype.runAction; +cc.Node.prototype.runAction = function (action) { + if (action._retained) { + action.release(); + action._retained = false; + } + jsbRunAction.call(this, action); +}; +var jsbAddAction = cc.ActionManager.prototype.addAction; +cc.ActionManager.prototype.addAction = function (action, target, paused) { + if (action._retained) { + action.release(); + action._retained = false; + } + jsbAddAction.call(this, action, target, paused); +}; + // ccsg window._ccsg = { Node: cc.Node, From 1a4b7b8a25733f3eaab1bcfb6ef42d83beb9086c Mon Sep 17 00:00:00 2001 From: pandamicro Date: Thu, 7 Jan 2016 22:50:39 +0800 Subject: [PATCH 2/2] Fix touch listener may be released in native issue --- cocos2d/core/CCNode.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cocos2d/core/CCNode.js b/cocos2d/core/CCNode.js index dbee2bc0c9..c6fb91c224 100644 --- a/cocos2d/core/CCNode.js +++ b/cocos2d/core/CCNode.js @@ -869,6 +869,7 @@ var Node = cc.Class({ onTouchMoved: _touchMoveHandler, onTouchEnded: _touchEndHandler }); + this._touchListener.retain(); cc.eventManager.addListener(this._touchListener, this); } } @@ -884,6 +885,7 @@ var Node = cc.Class({ onMouseUp: _mouseUpHandler, onMouseScroll: _mouseWheelHandler, }); + this._mouseListener.retain(); cc.eventManager.addListener(this._mouseListener, this); } } @@ -917,6 +919,7 @@ var Node = cc.Class({ } cc.eventManager.removeListener(this._touchListener); + this._touchListener.release(); this._touchListener = null; } }, @@ -929,6 +932,7 @@ var Node = cc.Class({ } cc.eventManager.removeListener(this._mouseListener); + this._mouseListener.release(); this._mouseListener = null; } },