54 lines
1.3 KiB
JavaScript
54 lines
1.3 KiB
JavaScript
import { TmoAssembler } from "./TmoAssembler";
|
|
|
|
export default cc.Class({
|
|
extends: cc.Sprite,
|
|
|
|
/**
|
|
* 设置TextureIndex
|
|
*/
|
|
setTextureIdx(idx) {
|
|
this._textureIdx = idx
|
|
this.setVertsDirty();
|
|
},
|
|
|
|
_getDefaultMaterial() {
|
|
// 从TiledMap取得默认的材质
|
|
return this._getTiledMap().getObjectMaterial();
|
|
},
|
|
|
|
_updateMaterial() {
|
|
// make sure material is belong to self.
|
|
let material = this.getMaterial(0);
|
|
if (material) {
|
|
if (material.getDefine('USE_TEXTURE') !== undefined) {
|
|
material.define('USE_TEXTURE', true);
|
|
}
|
|
// 手动设置哈希值,避免无法合批
|
|
material.updateHash(999999);
|
|
|
|
// 增加WITH_COLOR宏定义
|
|
let noColor = this.isNoColor();
|
|
material.define('WITH_COLOR', !noColor);
|
|
}
|
|
|
|
cc.BlendFunc.prototype._updateMaterial.call(this);
|
|
},
|
|
|
|
_resetAssembler() {
|
|
// 修改默认Assembler
|
|
let assembler = this._assembler = new TmoAssembler();
|
|
assembler.init(this);
|
|
|
|
this._updateColor();
|
|
this.setVertsDirty();
|
|
},
|
|
|
|
_getTiledMap() {
|
|
return this.node._tiledMap;
|
|
},
|
|
|
|
isNoColor() {
|
|
return this._getTiledMap().isNoColor();
|
|
}
|
|
});
|