import { _decorator, Component, Node, Tween, tween, UIOpacity } from 'cc'; const { ccclass, property } = _decorator; @ccclass('Item') export class Item extends Component { @property itemType: number = 0; onLoad() { this.node.on("init", this.init, this); this.node.on("initShow", this.initShow, this); this.setBlink(); } init() { this.node.active = true; setTimeout(() => { if (this.node) { this.node.active = false; } }, 0.5 * 1000); } initShow(index: number) { Tween.stopAllByTarget(this.node.getComponent(UIOpacity)); this.node.getComponent(UIOpacity).opacity = 1; tween(this.node.getComponent(UIOpacity)).to(index * 0.2, { opacity: 255 }).start(); } setBlink() { let random = Math.random(); setTimeout(() => { let time = Math.random() * 2 + 0.5; let e1 = this.node.getChildByName("e1"); let e2 = this.node.getChildByName("e2"); let tw = tween(this).delay(time).call(() => { e1.active = !e1.active; e2.active = !e2.active; }); tween(this).repeatForever(tw).start(); }, random * 1000); } start() { } update(deltaTime: number) { } }