代码拉取完成,页面将自动刷新
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;
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。