更新之后提示 sprite.setState 需要使用 sprite.setMaterial 替换。
但是替换了之后也不能使用
下面这个是我的代码,修改之后没有效果,精灵没有变灰
更新之后提示 sprite.setState 需要使用 sprite.setMaterial 替换。
但是替换了之后也不能使用
下面这个是我的代码,修改之后没有效果,精灵没有变灰
顶顶顶顶顶顶
用法是这样的。
this.sprite.setMaterial(0, cc.Material.getBuiltinMaterial(‘gray-sprite’);
谢谢大佬
大佬,怎么重置回正常是sprite材质呢,我试了将gray-sprite改为sprite,能拿到材质,但是显示是一片白色
无效,还是无法变成灰色。
2.1.2版本写法
if(isGray){
sprite.setMaterial(0, cc.Material.getInstantiatedBuiltinMaterial(‘2d-gray-sprite’,sprite));
}else{
sprite.setMaterial(0,cc.Material.getInstantiatedBuiltinMaterial(‘2d-sprite’,sprite));
}
material = cc.Material.getBuiltinMaterial('sprite', this.sprite);
material.define('USE_TEXTURE', true);
this.sprite.setMaterial(0, material);
2.1.2:版本(2.1.1去掉cc.Material.getBuiltinMaterial() “2d-”前缀)
cc.Sprite.prototype.setState = function (state) {
this._state = this._state || cc.Sprite.State.NORMAL
if (this._state == state)
return
var material ;
if (state == cc.Sprite.State.GRAY) {
// material = this._graySpriteMaterial;
material = cc.Material.getBuiltinMaterial("2d-gray-sprite");
material = cc.Material.getInstantiatedMaterial(material, this);
} else {
material = cc.Material.getBuiltinMaterial("2d-sprite", this);
material = cc.Material.getInstantiatedMaterial(material, this);
material.define("USE_TEXTURE", true);
}
this._state = state
this.setMaterial(0, material);
};
cc.Sprite.prototype.getState = function(){
return this._state || cc.Sprite.State.NORMAL
};
谢谢反馈,下个版本我们会提供兼容代码。
请问下2.3.2应该怎么用
sp.setMaterial(0, cc.Material.getBuiltinMaterial('2d-sprite'));
sp.setMaterial(0, cc.Material.getBuiltinMaterial('2d-gray-sprite'));