/* 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);
};
CocosCreator 源码cc.FadeTo详解
文章介绍了Cocos2D引擎中的cc.FadeTo类,它是一个继承自ActionInterval的类,用于改变实现了cc.RGBAProtocol协议的对象的不透明度,支持指定时间和目标值。
摘要由CSDN通过智能技术生成