mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 15:52:40 +08:00
Merge pull request #273 from pandamicro/master
Made ActionManager support cc.Node in JSB
This commit is contained in:
@@ -281,20 +281,35 @@ cc.ActionManager = cc._Class.extend(/** @lends cc.ActionManager# */{
|
||||
},
|
||||
|
||||
/**
|
||||
* Resume a set of targets (convenience function to reverse a pauseAllRunningActions call)
|
||||
* Resume a set of targets (convenience function to reverse a pauseAllRunningActions or pauseTargets call)
|
||||
* @method resumeTargets
|
||||
* @param {Array} targetsToResume
|
||||
*/
|
||||
resumeTargets:function(targetsToResume){
|
||||
if(!targetsToResume)
|
||||
if (!targetsToResume)
|
||||
return;
|
||||
|
||||
for(var i = 0 ; i< targetsToResume.length; i++){
|
||||
for (var i = 0; i< targetsToResume.length; i++) {
|
||||
if(targetsToResume[i])
|
||||
this.resumeTarget(targetsToResume[i]);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Pause a set of targets
|
||||
* @method pauseTargets
|
||||
* @param {Array} targetsToPause
|
||||
*/
|
||||
pauseTargets:function(targetsToPause){
|
||||
if (!targetsToPause)
|
||||
return;
|
||||
|
||||
for (var i = 0; i< targetsToPause.length; i++) {
|
||||
if (targetsToPause[i])
|
||||
this.pauseTarget(targetsToPause[i]);
|
||||
}
|
||||
},
|
||||
|
||||
/** purges the shared action manager. It releases the retained instance. <br/>
|
||||
* because it uses this, so it can not be static
|
||||
* @method purgeSharedManager
|
||||
|
||||
+9
-19
@@ -722,19 +722,15 @@ var Node = cc.Class({
|
||||
}
|
||||
}
|
||||
// activate or desactivate ActionManager, EventManager
|
||||
var target = this;
|
||||
if (cc.sys.isNative) {
|
||||
target = this._sgNode;
|
||||
}
|
||||
// Activate
|
||||
if (newActive) {
|
||||
cc.director.getActionManager().resumeTarget(target);
|
||||
cc.eventManager.resumeTarget(target);
|
||||
cc.director.getActionManager().resumeTarget(this);
|
||||
cc.eventManager.resumeTarget(this);
|
||||
}
|
||||
// Desactivate
|
||||
else {
|
||||
cc.director.getActionManager().pauseTarget(target);
|
||||
cc.eventManager.pauseTarget(target);
|
||||
cc.director.getActionManager().pauseTarget(this);
|
||||
cc.eventManager.pauseTarget(this);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1016,12 +1012,10 @@ var Node = cc.Class({
|
||||
return;
|
||||
cc.assert(action, cc._LogInfos.Node.runAction);
|
||||
|
||||
var target = this;
|
||||
if (cc.sys.isNative) {
|
||||
target = this._sgNode;
|
||||
this._retainAction(action);
|
||||
}
|
||||
cc.director.getActionManager().addAction(action, target, false);
|
||||
cc.director.getActionManager().addAction(action, this, false);
|
||||
return action;
|
||||
},
|
||||
|
||||
@@ -1030,8 +1024,7 @@ var Node = cc.Class({
|
||||
* @method stopAllActions
|
||||
*/
|
||||
stopAllActions: function () {
|
||||
var target = cc.sys.isNative ? this._sgNode : this;
|
||||
cc.director.getActionManager().removeAllActionsFromTarget(target);
|
||||
cc.director.getActionManager().removeAllActionsFromTarget(this);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -1053,8 +1046,7 @@ var Node = cc.Class({
|
||||
cc.log(cc._LogInfos.Node.stopActionByTag);
|
||||
return;
|
||||
}
|
||||
var target = cc.sys.isNative ? this._sgNode : this;
|
||||
cc.director.getActionManager().removeActionByTag(tag, target);
|
||||
cc.director.getActionManager().removeActionByTag(tag, this);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -1069,8 +1061,7 @@ var Node = cc.Class({
|
||||
cc.log(cc._LogInfos.Node.getActionByTag);
|
||||
return null;
|
||||
}
|
||||
var target = cc.sys.isNative ? this._sgNode : this;
|
||||
cc.director.getActionManager().getActionByTag(tag, target);
|
||||
cc.director.getActionManager().getActionByTag(tag, this);
|
||||
},
|
||||
|
||||
/** <p>Returns the numbers of actions that are running plus the ones that are schedule to run (actions in actionsToAdd and actions arrays).<br/>
|
||||
@@ -1081,8 +1072,7 @@ var Node = cc.Class({
|
||||
* @return {Number} The number of actions that are running plus the ones that are schedule to run
|
||||
*/
|
||||
getNumberOfRunningActions: function () {
|
||||
var target = cc.sys.isNative ? this._sgNode : this;
|
||||
cc.director.getActionManager().numberOfRunningActionsInTarget(target);
|
||||
cc.director.getActionManager().numberOfRunningActionsInTarget(this);
|
||||
},
|
||||
|
||||
_retainAction: function (action) {
|
||||
|
||||
@@ -191,8 +191,19 @@ cc.Node.prototype.runAction = function (action) {
|
||||
action._retained = false;
|
||||
}
|
||||
};
|
||||
|
||||
function getSGTarget (target) {
|
||||
if (target instanceof cc.Component) {
|
||||
target = target.node._sgNode;
|
||||
}
|
||||
if (target instanceof cc.Node) {
|
||||
target = target._sgNode;
|
||||
}
|
||||
return target;
|
||||
}
|
||||
var jsbAddAction = cc.ActionManager.prototype.addAction;
|
||||
cc.ActionManager.prototype.addAction = function (action, target, paused) {
|
||||
target = getSGTarget(target);
|
||||
jsbAddAction.call(this, action, target, paused);
|
||||
if (action._retained) {
|
||||
action.release();
|
||||
@@ -200,6 +211,48 @@ cc.ActionManager.prototype.addAction = function (action, target, paused) {
|
||||
}
|
||||
};
|
||||
|
||||
function actionMgrFuncReplacer (funcName, targetPos) {
|
||||
var proto = cc.ActionManager.prototype;
|
||||
var oldFunc = proto[funcName];
|
||||
proto[funcName] = function () {
|
||||
arguments[targetPos] = getSGTarget(arguments[targetPos]);
|
||||
return oldFunc.apply(this, arguments);
|
||||
};
|
||||
}
|
||||
|
||||
var targetRelatedFuncs = [
|
||||
['removeAllActionsFromTarget', 0],
|
||||
['removeActionByTag', 1],
|
||||
['getActionByTag', 1],
|
||||
['numberOfRunningActionsInTarget', 0],
|
||||
['pauseTarget', 0],
|
||||
['resumeTarget', 0]
|
||||
];
|
||||
|
||||
for (var i = 0; i < targetRelatedFuncs.length; ++i) {
|
||||
actionMgrFuncReplacer.apply(null, targetRelatedFuncs[i]);
|
||||
}
|
||||
|
||||
cc.ActionManager.prototype.resumeTargets = function (targetsToResume) {
|
||||
if (!targetsToResume)
|
||||
return;
|
||||
|
||||
for (var i = 0; i< targetsToResume.length; i++) {
|
||||
if (targetsToResume[i])
|
||||
this.resumeTarget(targetsToResume[i]);
|
||||
}
|
||||
};
|
||||
|
||||
cc.ActionManager.prototype.pauseTargets = function (targetsToPause) {
|
||||
if (!targetsToPause)
|
||||
return;
|
||||
|
||||
for (var i = 0; i< targetsToPause.length; i++) {
|
||||
if (targetsToPause[i])
|
||||
this.pauseTarget(targetsToPause[i]);
|
||||
}
|
||||
};
|
||||
|
||||
// ccsg
|
||||
window._ccsg = {
|
||||
Node: cc.Node,
|
||||
|
||||
+2
-2
@@ -166,7 +166,7 @@ cc.eventManager.pauseTarget = function (target, recursive) {
|
||||
if (target instanceof cc.Node) {
|
||||
target = target._sgNode;
|
||||
}
|
||||
this._pauseTarget(this, target, recursive || false);
|
||||
this._pauseTarget(target, recursive || false);
|
||||
};
|
||||
cc.eventManager._resumeTarget = cc.eventManager.resumeTarget;
|
||||
cc.eventManager.resumeTarget = function (target, recursive) {
|
||||
@@ -176,5 +176,5 @@ cc.eventManager.resumeTarget = function (target, recursive) {
|
||||
if (target instanceof cc.Node) {
|
||||
target = target._sgNode;
|
||||
}
|
||||
this._resumeTarget(this, target, recursive || false);
|
||||
this._resumeTarget(target, recursive || false);
|
||||
};
|
||||
Reference in New Issue
Block a user