CocosCreator 源码cc.ScaleBy详解

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

/* Scales a Node object a zoom factor by modifying it's scale property.
 * Relative to its changes.
 * @class ScaleBy
 * @extends ScaleTo
 */
/* 通过修改节点对象的缩放属性来缩放节点对象的缩放系数。
 * 相对于它的变化。
 * @class ScaleBy
 * @extends ScaleTo
 */
cc.ScaleBy = cc.Class({
    name: 'cc.ScaleBy',
    /* 继承自cc.ScaleTo */
    extends: cc.ScaleTo,

    /* 设置target */
    startWithTarget: function (target) {
        cc.ScaleTo.prototype.startWithTarget.call(this, target);
        /* end是当前的多少倍,减去当前。 */
        this._deltaX = this._startScaleX * this._endScaleX - this._startScaleX;
        this._deltaY = this._startScaleY * this._endScaleY - this._startScaleY;
    },
    /* 逆向action */
    reverse: function () {
        /* 产出一个新对象,设置最终的scalex,scaley,分别为原来scale的倒数 */
        var action = new cc.ScaleBy(this._duration, 1 / this._endScaleX, 1 / this._endScaleY);
        /* 复制当前属性给action */
        this._cloneDecoration(action);
        /* 把easelist里面的action 进行reverse */
        this._reverseEaseList(action);
        /* 返回action */
        return action;
    },
    /* 复制Action
     */
    clone: function () {
        /* 创建一个对象 */
        var action = new cc.ScaleBy();
        /* 对对象进行属性设置 */
        this._cloneDecoration(action);
        /* 初始化参数,endscalex,endscaley */
        action.initWithDuration(this._duration, this._endScaleX, this._endScaleY);
        return action;
    }
});
/**
 * !#en
 * Scales a Node object a zoom factor by modifying it's scale property.
 * Relative to its changes.
 * !#zh 按指定的倍数缩放节点大小。
 * @method scaleBy
 * @param {Number} duration duration in seconds
 * @param {Number} sx sx  scale parameter in X
 * @param {Number|Null} [sy=] sy scale parameter in Y, if Null equal to sx
 * @return {ActionInterval}
 * @example
 * // example without sy, it scales by 2 both in X and Y
 * var actionBy = cc.scaleBy(2, 2);
 *
 * //example with sy, it scales by 0.25 in X and 4.5 in Y
 * var actionBy2 = cc.scaleBy(2, 0.25, 4.5);
 */
/* 创建scaleBy对象  */
cc.scaleBy = function (duration, sx, sy) {
    return new cc.ScaleBy(duration, sx, sy);
};

  • 7
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值