直接更改透明度
對包含多個子對象疊加呜呐,修改node.alpha可以自動遍歷每個子對象去調節(jié)透明度。這樣的修改方式簡單蘑辑,但是會導致子對象之間會有穿透現(xiàn)象坠宴,你會看到一個對象遮擋后面的圖片的輪廓。尤其在龍骨動畫中喜鼓,你并不想讓人看到被遮擋的胳膊吧---這又不是拍x光片。
使用ColorMatrix濾鏡
代碼我放到這里庄岖,直接調用函數(shù)輸入值為0~1即可,對node調節(jié)能夠更改整體的透明度隅忿,像漸隱漸現(xiàn)一樣。
代碼植入
// 透明濾鏡
private colorMatrixFilter:egret.ColorMatrixFilter;
private alphaPlusVal:number = 1;
private colorMatrix = [
1, 0, 0, 0, 0,
0, 1, 0, 0, 0,
0, 0, 1, 0, 0,
0, 0, 0, 1, 0
];
public get alphaPlus():number{
return this.alphaPlusVal;
}
public set alphaPlus(val:number){
//let ap = Math.max(Math.min(val,1),0);
if(this.alphaPlusVal==val){
return;
}
if(val==1){
this.alphaPlusVal = val;
this.filters = null;
return;
}
this.alphaPlusVal=val;
this.colorMatrix[18] = this.alphaPlusVal;
if(!this.colorMatrixFilter){
this.colorMatrixFilter = new egret.ColorMatrixFilter(this.colorMatrix);
}else{
this.colorMatrixFilter.matrix = this.colorMatrix;
}
this.filters = [this.colorMatrixFilter];
}
調用方法
this.alphaPlus=.5;
改良后可使用tween
egret.Tween.get(this).to({
alphaPlus: 0
}, 300).call(() => {
})
效果
兩種方法比較
使用透明度設置方式
使用濾鏡方式
能明顯看到用透明度方式簡單粗暴刘陶,會看到角色的鹵蛋牢撼,假發(fā)疑苫,胳膊身體,沒有完整感.