mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-20 23:52:40 +08:00
Merge pull request #397 from pandamicro/master
Fix properties synchronize issue in action (JSB)
This commit is contained in:
@@ -251,7 +251,7 @@ cc.FlipX = cc.ActionInstant.extend({
|
||||
},
|
||||
|
||||
update:function (dt) {
|
||||
this.target.flippedX = this._flippedX;
|
||||
this.target.scaleX = Math.abs(this.target.scaleX) * (this._flippedX ? 1 : -1);
|
||||
},
|
||||
|
||||
reverse:function () {
|
||||
@@ -309,7 +309,7 @@ cc.FlipY = cc.ActionInstant.extend({
|
||||
},
|
||||
|
||||
update:function (dt) {
|
||||
this.target.flippedY = this._flippedY;
|
||||
this.target.scaleY = Math.abs(this.target.scaleY) * (this._flippedX ? 1 : -1);
|
||||
},
|
||||
|
||||
reverse:function () {
|
||||
|
||||
@@ -1044,6 +1044,7 @@ var Node = cc.Class({
|
||||
|
||||
if (cc.sys.isNative) {
|
||||
this._retainAction(action);
|
||||
this._sgNode._owner = this;
|
||||
}
|
||||
cc.director.getActionManager().addAction(action, this, false);
|
||||
return action;
|
||||
|
||||
@@ -21,6 +21,7 @@ require('./jsb-editbox');
|
||||
require('./jsb-particle');
|
||||
require('./jsb-enums');
|
||||
require('./jsb-event');
|
||||
require('./jsb-action');
|
||||
require('./jsb-etc');
|
||||
|
||||
// Check version
|
||||
|
||||
@@ -0,0 +1,262 @@
|
||||
// Independent Action from retain/release
|
||||
var actionArr = [
|
||||
'ActionEase',
|
||||
'EaseExponentialIn',
|
||||
'EaseExponentialOut',
|
||||
'EaseExponentialInOut',
|
||||
'EaseSineIn',
|
||||
'EaseSineOut',
|
||||
'EaseSineInOut',
|
||||
'EaseBounce',
|
||||
'EaseBounceIn',
|
||||
'EaseBounceOut',
|
||||
'EaseBounceInOut',
|
||||
'EaseBackIn',
|
||||
'EaseBackOut',
|
||||
'EaseBackInOut',
|
||||
'EaseRateAction',
|
||||
'EaseIn',
|
||||
'EaseElastic',
|
||||
'EaseElasticIn',
|
||||
'EaseElasticOut',
|
||||
'EaseElasticInOut',
|
||||
'RemoveSelf',
|
||||
'FlipX',
|
||||
'FlipY',
|
||||
'Place',
|
||||
'CallFunc',
|
||||
'DelayTime',
|
||||
'Sequence',
|
||||
'Spawn',
|
||||
'Speed',
|
||||
'Repeat',
|
||||
'RepeatForever',
|
||||
'Follow',
|
||||
'TargetedAction',
|
||||
'Animate',
|
||||
'OrbitCamera',
|
||||
'GridAction',
|
||||
'ProgressTo',
|
||||
'ProgressFromTo',
|
||||
'ActionInterval',
|
||||
'RotateTo',
|
||||
'RotateBy',
|
||||
'MoveBy',
|
||||
'MoveTo',
|
||||
'SkewTo',
|
||||
'SkewBy',
|
||||
'JumpTo',
|
||||
'JumpBy',
|
||||
'ScaleTo',
|
||||
'ScaleBy',
|
||||
'Blink',
|
||||
'FadeTo',
|
||||
'FadeIn',
|
||||
'FadeOut',
|
||||
'TintTo',
|
||||
'TintBy',
|
||||
];
|
||||
|
||||
function setCtorReplacer (proto) {
|
||||
var ctor = proto._ctor;
|
||||
proto._ctor = function () {
|
||||
ctor.apply(this, arguments);
|
||||
this.retain();
|
||||
this._retained = true;
|
||||
};
|
||||
}
|
||||
function setAliasReplacer (name, type) {
|
||||
var aliasName = name[0].toLowerCase() + name.substr(1);
|
||||
cc[aliasName] = function () {
|
||||
var action = type.create.apply(this, arguments);
|
||||
action.retain();
|
||||
action._retained = true;
|
||||
return action;
|
||||
};
|
||||
}
|
||||
|
||||
for (var i = 0; i < actionArr.length; ++i) {
|
||||
var name = actionArr[i];
|
||||
var type = cc[name];
|
||||
if (!type)
|
||||
continue;
|
||||
var proto = type.prototype;
|
||||
setCtorReplacer(proto);
|
||||
setAliasReplacer(name, type);
|
||||
}
|
||||
|
||||
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;
|
||||
return newAction;
|
||||
};
|
||||
}
|
||||
|
||||
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) {
|
||||
jsbRunAction.call(this, action);
|
||||
if (action._retained) {
|
||||
action.release();
|
||||
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();
|
||||
action._retained = false;
|
||||
}
|
||||
};
|
||||
|
||||
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]);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
function syncPositionUpdate (dt) {
|
||||
this._jsbUpdate(dt);
|
||||
var target = this.getTarget();
|
||||
if (target._owner) {
|
||||
target._owner.x = target.getPositionX();
|
||||
target._owner.y = target.getPositionY();
|
||||
}
|
||||
}
|
||||
|
||||
function syncRotationUpdate (dt) {
|
||||
this._jsbUpdate(dt);
|
||||
var target = this.getTarget();
|
||||
if (target._owner) {
|
||||
target._owner.rotation = target.getRotation();
|
||||
}
|
||||
}
|
||||
|
||||
function syncScaleUpdate (dt) {
|
||||
this._jsbUpdate(dt);
|
||||
var target = this.getTarget();
|
||||
if (target._owner) {
|
||||
target._owner.scaleX = target.getScaleX();
|
||||
target._owner.scaleY = target.getScaleY();
|
||||
}
|
||||
}
|
||||
|
||||
function syncRemoveSelfUpdate (dt) {
|
||||
this._jsbUpdate(dt);
|
||||
var target = this.getTarget();
|
||||
if (target._owner) {
|
||||
target._owner.removeFromParent();
|
||||
}
|
||||
}
|
||||
|
||||
function syncSkewUpdate (dt) {
|
||||
this._jsbUpdate(dt);
|
||||
var target = this.getTarget();
|
||||
if (target._owner) {
|
||||
target._owner.skewX = target.getSkewX();
|
||||
target._owner.skewY = target.getSkewY();
|
||||
}
|
||||
}
|
||||
|
||||
// function syncOpacityUpdate (dt) {
|
||||
// this._jsbUpdate(dt);
|
||||
// var target = this.getTarget();
|
||||
// if (target._owner) {
|
||||
// target._owner.opacity = target.getOpacity();
|
||||
// }
|
||||
// }
|
||||
|
||||
function syncColorUpdate (dt) {
|
||||
this._jsbUpdate(dt);
|
||||
var target = this.getTarget();
|
||||
if (target._owner) {
|
||||
target._owner.color = target.getColor();
|
||||
}
|
||||
}
|
||||
|
||||
var actionUpdate = {
|
||||
'MoveTo' : syncPositionUpdate,
|
||||
'MoveBy' : syncPositionUpdate,
|
||||
'JumpTo' : syncPositionUpdate,
|
||||
'JumpBy' : syncPositionUpdate,
|
||||
'Place' : syncPositionUpdate,
|
||||
'RotateTo' : syncRotationUpdate,
|
||||
'RotateBy' : syncRotationUpdate,
|
||||
'ScaleTo' : syncScaleUpdate,
|
||||
'ScaleBy' : syncScaleUpdate,
|
||||
'RemoveSelf' : syncRemoveSelfUpdate,
|
||||
'SkewTo' : syncSkewUpdate,
|
||||
'SkewBy' : syncSkewUpdate,
|
||||
// 'Blink' : syncOpacityUpdate,
|
||||
// 'FadeTo' : syncOpacityUpdate,
|
||||
// 'FadeIn' : syncOpacityUpdate,
|
||||
// 'FadeOut' : syncOpacityUpdate,
|
||||
'TintTo' : syncColorUpdate,
|
||||
'TintBy' : syncColorUpdate
|
||||
};
|
||||
|
||||
for (var key in actionUpdate) {
|
||||
var action = cc[key];
|
||||
action.prototype._jsbUpdate = action.prototype.update;
|
||||
action.prototype.update = actionUpdate[key];
|
||||
}
|
||||
-174
@@ -80,180 +80,6 @@ cc.Scheduler.prototype.unschedule = function (callback, target) {
|
||||
this._unschedule(target, callback);
|
||||
};
|
||||
|
||||
// Independent Action from retain/release
|
||||
var actionArr = [
|
||||
'ActionEase',
|
||||
'EaseExponentialIn',
|
||||
'EaseExponentialOut',
|
||||
'EaseExponentialInOut',
|
||||
'EaseSineIn',
|
||||
'EaseSineOut',
|
||||
'EaseSineInOut',
|
||||
'EaseBounce',
|
||||
'EaseBounceIn',
|
||||
'EaseBounceOut',
|
||||
'EaseBounceInOut',
|
||||
'EaseBackIn',
|
||||
'EaseBackOut',
|
||||
'EaseBackInOut',
|
||||
'EaseRateAction',
|
||||
'EaseIn',
|
||||
'EaseElastic',
|
||||
'EaseElasticIn',
|
||||
'EaseElasticOut',
|
||||
'EaseElasticInOut',
|
||||
'RemoveSelf',
|
||||
'FlipX',
|
||||
'FlipY',
|
||||
'Place',
|
||||
'CallFunc',
|
||||
'DelayTime',
|
||||
'Sequence',
|
||||
'Spawn',
|
||||
'Speed',
|
||||
'Repeat',
|
||||
'RepeatForever',
|
||||
'Follow',
|
||||
'TargetedAction',
|
||||
'Animate',
|
||||
'OrbitCamera',
|
||||
'GridAction',
|
||||
'ProgressTo',
|
||||
'ProgressFromTo',
|
||||
'ActionInterval',
|
||||
'RotateTo',
|
||||
'RotateBy',
|
||||
'MoveBy',
|
||||
'MoveTo',
|
||||
'SkewTo',
|
||||
'SkewBy',
|
||||
'JumpTo',
|
||||
'JumpBy',
|
||||
'ScaleTo',
|
||||
'ScaleBy',
|
||||
'Blink',
|
||||
'FadeTo',
|
||||
'FadeIn',
|
||||
'FadeOut',
|
||||
'TintTo',
|
||||
'TintBy',
|
||||
];
|
||||
|
||||
function setCtorReplacer (proto) {
|
||||
var ctor = proto._ctor;
|
||||
proto._ctor = function () {
|
||||
ctor.apply(this, arguments);
|
||||
this.retain();
|
||||
this._retained = true;
|
||||
};
|
||||
}
|
||||
function setAliasReplacer (name, type) {
|
||||
var aliasName = name[0].toLowerCase() + name.substr(1);
|
||||
cc[aliasName] = function () {
|
||||
var action = type.create.apply(this, arguments);
|
||||
action.retain();
|
||||
action._retained = true;
|
||||
return action;
|
||||
};
|
||||
}
|
||||
|
||||
for (var i = 0; i < actionArr.length; ++i) {
|
||||
var name = actionArr[i];
|
||||
var type = cc[name];
|
||||
if (!type)
|
||||
continue;
|
||||
var proto = type.prototype;
|
||||
setCtorReplacer(proto);
|
||||
setAliasReplacer(name, type);
|
||||
}
|
||||
|
||||
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;
|
||||
return newAction;
|
||||
};
|
||||
}
|
||||
|
||||
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) {
|
||||
jsbRunAction.call(this, action);
|
||||
if (action._retained) {
|
||||
action.release();
|
||||
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();
|
||||
action._retained = false;
|
||||
}
|
||||
};
|
||||
|
||||
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 = {
|
||||
|
||||
Reference in New Issue
Block a user