CocosCreator 源码cc.FadeTo详解

/* Fades an object that implements the cc.RGBAProtocol protocol. It modifies the opacity from the current value to a custom one.

 * @warning This action doesn't support "reverse"

 * @class FadeTo

 * @extends ActionInterval

 * @param {Number} duration

 * @param {Number} opacity 0-255, 0 is transparent

 * @example

 * var action = new cc.FadeTo(1.0, 0);

 */

/* 淡入淡出实现 cc.RGBAProtocol 协议的对象。它将不透明度从当前值修改为自定义值。

 * @警告此操作不支持“反向”

 * @class FadeTo

 * @extends ActionInterval

 * @param {Number} 持续时间

 * @param {Number} 不透明度0-255,0为透明

 * @例子

 * var action = new cc.FadeTo(1.0, 0);

 */

cc.FadeTo = cc.Class({

    name: 'cc.FadeTo',

    extends: cc.ActionInterval,



    ctor: function (duration, opacity) {

        this._toOpacity = 0;

        this._fromOpacity = 0;

        opacity !== undefined && cc.FadeTo.prototype.initWithDuration.call(this, duration, opacity);

    },



    /*

     * Initializes the action.

     * @param {Number} duration  duration in seconds

     * @param {Number} opacity

     * @return {Boolean}

     */

    /*

     * 初始化操作。

     * @param {Number} 持续时间 持续时间(以秒为单位)

     * @param {Number} 不透明度

     * @return {布尔值}

     */

    initWithDuration: function (duration, opacity) {

        if (cc.ActionInterval.prototype.initWithDuration.call(this, duration)) {

            this._toOpacity = opacity;

            return true;

        }

        return false;

    },



    clone: function () {

        var action = new cc.FadeTo();

        this._cloneDecoration(action);

        action.initWithDuration(this._duration, this._toOpacity);

        return action;

    },



    update: function (time) {

        time = this._computeEaseTime(time);

        var fromOpacity = this._fromOpacity !== undefined ? this._fromOpacity : 255;

        this.target.opacity = fromOpacity + (this._toOpacity - fromOpacity) * time;

    },



    startWithTarget: function (target) {

        cc.ActionInterval.prototype.startWithTarget.call(this, target);

        this._fromOpacity = target.opacity;

    }

});



/**

 * !#en

 * Fades an object that implements the cc.RGBAProtocol protocol.

 * It modifies the opacity from the current value to a custom one.

 * !#zh 修改透明度到指定值。

 * @method fadeTo

 * @param {Number} duration

 * @param {Number} opacity 0-255, 0 is transparent

 * @return {ActionInterval}

 * @example

 * // example

 * var action = cc.fadeTo(1.0, 0);

 */

/* 创建fadeTo对象 */

cc.fadeTo = function (duration, opacity) {

    return new cc.FadeTo(duration, opacity);

};

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值