CocosCreator 源码cc.TargetedAction详解

/*
 * <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);
};

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值