-
Creator 版本:2.3.3
-
目标平台: web
我想变灰色之后 ,然后再次变回原来的颜色,可能是使用方式不对,出现了白色的情况。
除了保存之前的材质信息,直接新建材质要怎么操作?
ts 示例代码,点击按钮进行切换变换 材质。
public changeEffect(active: boolean): void {
if (active) {
//this.newMaterial = this.preMaterial;
this.newMaterial = cc.Material.createWithBuiltin(cc.Material.BUILTIN_NAME.SPRITE, 0);
} else {
this.newMaterial = cc.Material.createWithBuiltin(cc.Material.BUILTIN_NAME.GRAY_SPRITE, 0);
}
this.node.getComponent(cc.Sprite).setMaterial(0, this.newMaterial);
}