CocosCreator 源码cc.RotateBy详解

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

/*
 * Rotates a Node object clockwise a number of degrees by modifying its angle property.
 * Relative to its properties to modify.
 * @class RotateBy
 * @extends ActionInterval
 * @param {Number} duration duration in seconds
 * @param {Number} deltaAngle deltaAngle in degrees
 * @example
 * var actionBy = new cc.RotateBy(2, 360);
 */
/* /*
 * 通过修改 Node 对象的角度属性,将 Node 对象顺时针旋转一定角度。
 * 相对于其属性进行修改。
 * @类RotateBy
 * @extends ActionInterval
 * @param {Number} 持续时间 持续时间(以秒为单位)
 * @param {Number} deltaAngle deltaAngle 以度为单位
 * @例子
 * var actionBy = new cc.RotateBy(2, 360);
 */ * /
cc.RotateBy = cc.Class({
    name: 'cc.RotateBy',
    extends: cc.ActionInterval,

    statics: {
        _reverse: false,
    },

    /* 构造函数 */
    ctor: function (duration, deltaAngle) {
        deltaAngle *= cc.RotateBy._reverse ? 1 : -1;

        this._deltaAngle = 0;
        this._startAngle = 0;
        deltaAngle !== undefined && this.initWithDuration(duration, deltaAngle);
    },

    /*
     * Initializes the action.
     * @param {Number} duration duration in seconds
     * @param {Number} deltaAngle deltaAngle in degrees
     * @return {Boolean}
     */
    /* /*
     * 初始化操作。
     * @param {Number} 持续时间 持续时间(以秒为单位)
     * @param {Number} deltaAngle deltaAngle 以度为单位
     * @return {布尔值}
     */ */
    initWithDuration: function (duration, deltaAngle) {
        if (cc.ActionInterval.prototype.initWithDuration.call(this, duration)) {
            this._deltaAngle = deltaAngle;
            return true;
        }
        return false;
    },
    /* 复制Acton ,cc.RotateBy */
    clone: function () {
        var action = new cc.RotateBy();
        this._cloneDecoration(action);
        action.initWithDuration(this._duration, this._deltaAngle);
        return action;
    },

    /* 调用cc.ActionInterval 的startWithTarget 方法 */
    startWithTarget: function (target) {
        cc.ActionInterval.prototype.startWithTarget.call(this, target);
        this._startAngle = target.angle;
    },

    update: function (dt) {
        /* 时时更新 */
        dt = this._computeEaseTime(dt);
        if (this.target) {
            /* 当前angle更新,开始的angle + 总计划rotate的angle *帧时间 */
            this.target.angle = this._startAngle + this._deltaAngle * dt;
        }
    },

    reverse: function () {
        var action = new cc.RotateBy();
        action.initWithDuration(this._duration, -this._deltaAngle);
        this._cloneDecoration(action);
        this._reverseEaseList(action);
        return action;
    }
});

/**
 * !#en
 * Rotates a Node object clockwise a number of degrees by modifying its angle property.
 * Relative to its properties to modify.
 * !#zh 旋转指定的角度。
 * @method rotateBy
 * @param {Number} duration duration in seconds
 * @param {Number} deltaAngle deltaAngle in degrees
 * @return {ActionInterval}
 * @example
 * // example
 * var actionBy = cc.rotateBy(2, 360);
 */
/* 创建一个 rotateBy对象*/
cc.rotateBy = function (duration, deltaAngle) {
    return new cc.RotateBy(duration, deltaAngle);
};

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值