• CocosCreator 图片置灰(Material/按钮/图片/Spine)


    版本:2.4.3

    图片置灰

    将内置灰色Material拖动到属性面板

    通过代码将内建灰色材质gray赋值给图片

    export default class test_setShader extends cc.Component {
        @property(cc.Sprite)
        head:cc.Sprite = null;     //图片
        @property(cc.Material)
        gray:cc.Material = null;   //内置灰色材质
    
        onLoad(){
            //获取所有材质
            console.log("getMaterials", this.head.getMaterials());
            //内建材质
            this.head.setMaterial(0, this.gray);
        }
    }
    

      

    图片变成灰色

    也可以通过cc.Material.getBuiltinMaterial("");  获取内置材质。

    export default class test_setShader extends cc.Component {
        @property(cc.Sprite)
        head:cc.Sprite = null;     //图片
    
        onLoad(){
            //内建材质
            let material:cc.Material = cc.Material.getBuiltinMaterial('2d-gray-sprite')
            this.head.setMaterial(0, material);
        }
    }
    

     

    Spine动画置灰

    在cocos示例项目中打开示例项目SpineBatch.fire,示例项目中有spine置灰的材质gray-spine。

    示例可以看到spine整体置灰效果

    @ccclass
    export default class test_setShader extends cc.Component {
    
        @property(sp.Skeleton)
        sp: sp.Skeleton = null;     //spine动画
    
        @property(cc.Material)
        gray: cc.Material = null;   //灰色材质
    
        @property(cc.Material)
        normal:cc.Material = null;  //正常材质
    
        onLoad() {
            this.sp.setMaterial(0, this.gray);     //spine置灰
            (this.sp as any).markForRender(true);  
        }
    }
    

     

    图片置绿

    比如图片要显示中毒效果,想让图片整体变绿色,使用正常的材质,调整color就能使图片变色。

    spine动画同样是调整color。

    对象及其子对象置灰

    搜了一下没发现...

  • 相关阅读:
    js获取input file文件二进制码
    nginx新手入门
    代码神器Atom,最常用的几大插件,你值得拥有。
    css3 3d 与案例分析
    express搭建简易web的服务器
    hosts文件管理和nginx总结
    css3 3D
    问题大神
    面试题整理
    版本控制简介,git使用----使用GitHub托管代码
  • 原文地址:https://www.cnblogs.com/gamedaybyday/p/13878638.html
Copyright © 2020-2023  润新知