CocosCreator 源码cc.RepeatForever详解

欢迎关注公众号:“Cocos Creator 源码讲解”,一起学习。

/*
 * Repeats an action for ever.  <br/>
 * To repeat the an action for a limited number of times use the Repeat action. <br/>
 * @warning This action can't be Sequenceable because it is not an IntervalAction
 * @class RepeatForever
 * @extends ActionInterval
 * @param {FiniteTimeAction} action
 * @example
 * var rep = new cc.RepeatForever(cc.sequence(jump2, jump1), 5);
 */
/* /*
 * 永远重复一个动作。 <br/>
 * 要重复操作有限次数,请使用“重复”操作。 <br/>
 * @警告此操作无法进行排序,因为它不是 IntervalAction
 * @类重复永远
 * @extends ActionInterval
 * @param {FiniteTimeAction} 动作
 * @例子
 * var rep = new cc.RepeatForever(cc.sequence(jump2, jump1), 5);
 */ * /
cc.RepeatForever = cc.Class({
    name: 'cc.RepeatForever',
    extends: cc.ActionInterval,

    /* 构造函数 */
    ctor: function (action) {
        this._innerAction = null;
        action && this.initWithAction(action);
    },

    /*
     * @param {ActionInterval} action
     * @return {Boolean}
     */
    /* 初始化 init action */
    initWithAction: function (action) {
        if (!action) {
            cc.errorID(1026);
            return false;
        }

        this._innerAction = action;
        return true;
    },
    /* 复制action cc.RepeatForever */
    clone: function () {
        var action = new cc.RepeatForever();
        this._cloneDecoration(action);
        action.initWithAction(this._innerAction.clone());
        return action;
    },
    /* cc.RepeatForever 调用 cc.ActionInterval,传入参数 target*/
    startWithTarget: function (target) {
        cc.ActionInterval.prototype.startWithTarget.call(this, target);
        this._innerAction.startWithTarget(target);
    },

    step: function (dt) {
        /* 声明局部变量,获取当前action */
        var locInnerAction = this._innerAction;
        /* 当前action执行step */
        locInnerAction.step(dt);
        /* action已经执行完毕了 */
        if (locInnerAction.isDone()) {
            //var diff = locInnerAction.getElapsed() - locInnerAction._duration;
            locInnerAction.startWithTarget(this.target);
            // to prevent jerk. issue #390 ,1247
            //this._innerAction.step(0);
            //this._innerAction.step(diff);
            locInnerAction.step(locInnerAction.getElapsed() - locInnerAction._duration);
        }
    },

    isDone: function () {
        return false;
    },
    /* 反向一个action */
    reverse: function () {
        var action = new cc.RepeatForever(this._innerAction.reverse());
        this._cloneDecoration(action);
        this._reverseEaseList(action);
        return action;
    },

    /*
     * Set inner action.
     * @param {ActionInterval} action
     */
    /* 设置当前action */
    setInnerAction: function (action) {
        if (this._innerAction !== action) {
            this._innerAction = action;
        }
    },

    /*
     * Get inner action.
     * @return {ActionInterval}
     */
    /* 获取当前action */
    getInnerAction: function () {
        return this._innerAction;
    }
});

/**
 * !#en Create a acton which repeat forever, as it runs forever, it can't be added into cc.sequence and cc.spawn.
 * !#zh 永远地重复一个动作,有限次数内重复一个动作请使用 repeat 动作,由于这个动作不会停止,所以不能被添加到 cc.sequence 或 cc.spawn 中。
 * @method repeatForever
 * @param {FiniteTimeAction} action
 * @return {ActionInterval}
 * @example
 * // example
 * var repeat = cc.repeatForever(cc.rotateBy(1.0, 360));
 */
cc.repeatForever = function (action) {
    return new cc.RepeatForever(action);
};

  • 9
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值