/*
* <p>
* Overrides the target of an action so that it always runs on the target<br/>
* specified at action creation rather than the one specified by runAction.
* </p>
* @class TargetedAction
* @extends ActionInterval
* @param {Node} target
* @param {FiniteTimeAction} action
*/
/*
* <p>
* 覆盖操作的目标,使其始终在目标上运行<br/>
* 在创建操作时指定,而不是在 runAction 中指定。
* </p>
* @class TargetedAction
* @extends ActionInterval
* @param {Node} 目标
* @param {FiniteTimeAction} 动作
*/
cc.TargetedAction = cc.Class({
name: 'cc.TargetedAction',
extends: cc.ActionInterval,
ctor: function (target, action) {
this._action = null;
this._forcedTarget = null;
action && this.initWithTarget(target, action);
},
/*
* Init an action with the specified action and forced target
* @param {Node} target
* @param {FiniteTimeAction} action
* @return {Boolean}
*/
initWithTarget: function (target, action) {
if (this.initWithDuration(action._duration)) {
this._forcedTarget = target;
this._action = action;
return true;
}
return false;
},
clone: function () {
var action = new cc.TargetedAction();
this._cloneDecoration(action);
action.initWithTarget(this._forcedTarget, this._action.clone());
return action;
},
startWithTarget: function (target) {
cc.ActionInterval.prototype.startWithTarget.call(this, target);
this._action.startWithTarget(this._forcedTarget);
},
stop: function () {
this._action.stop();
},
update: function (dt) {
dt = this._computeEaseTime(dt);
this._action.update(dt);
},
/*
* return the target that the action will be forced to run with
* @return {Node}
*/
/*
* 返回操作将被强制运行的目标
* @return {节点}
*/
getForcedTarget: function () {
return this._forcedTarget;
},
/*
* set the target that the action will be forced to run with
* @param {Node} forcedTarget
*/
/*
* 设置强制运行操作的目标
* @param {Node} 强制目标
*/
setForcedTarget: function (forcedTarget) {
if (this._forcedTarget !== forcedTarget)
this._forcedTarget = forcedTarget;
}
});
/**
* !#en Create an action with the specified action and forced target.
* !#zh 用已有动作和一个新的目标节点创建动作。
* @method targetedAction
* @param {Node} target
* @param {FiniteTimeAction} action
* @return {ActionInterval}
*/
cc.targetedAction = function (target, action) {
return new cc.TargetedAction(target, action);
};