74 Star 626 Fork 353

木限东/CocosCreatorShader

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
FlashSpine.ts 1.42 KB
一键复制 编辑 原始数据 按行查看 历史
木限东 提交于 2022-08-17 13:57 +08:00 . update to 3.6.0
import { _decorator, Component, Material, Sprite, sp, AnimationState } from 'cc';
import { JSB } from 'cc/env';
const { ccclass, property } = _decorator;
@ccclass('FlashSpine')
export default class FlashSpine extends Component {
duration: number = 0.5;
_median: number = 0;
_time: number = 0;
_material: Material = null!;
_skeleton: sp.Skeleton = null!;
onLoad() {
this._median = this.duration / 2;
// 获取材质
this._skeleton = this.node.getComponent(sp.Skeleton)!;
this._material = this._skeleton.customMaterial!;
// 设置材质对应的属性
this._material.setProperty("u_rate", 1);
}
update(dt: number) {
if (this._time > 0) {
this._time -= dt;
this._time = this._time < 0 ? 0 : this._time;
let rate = Math.abs(this._time - this._median) * 2 / this.duration;
if (JSB) {
this._skeleton.getMaterial(0)!.setProperty("u_rate", rate);
// @ts-ignore
this._renderComponent._updateMaterial();
} else {
// @ts-ignore
let cache: any = this._skeleton._materialCache;
for (let i in cache) {
let material= cache[i];
material.setProperty("u_rate", rate);
}
}
}
}
clickFlash() {
this._time = this.duration;
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yeshao2069/cocos-creator-shader.git
git@gitee.com:yeshao2069/cocos-creator-shader.git
yeshao2069
cocos-creator-shader
CocosCreatorShader
v3.6.x

搜索帮助