import { _decorator, Color, Font, Label, Node, tween, UIOpacity, UITransform, v3, Vec3 } from 'cc'; import { NodeEx } from '../../framework/pool/NodeEx'; import { FloatTextPool } from '../common/Pool'; const { ccclass, property } = _decorator; @ccclass('FloatTextNode') export class FloatTextNode extends NodeEx { protected onLoad() { } // init(pic, text, scale = 1, color = new Color('#ffffff'), direction = 1, speed = 0.3,) { // scale = 1 this.node.getComponent(Label).string = ''; let PosX = 0; let poxY = 100; if (typeof text == 'number') { this.node.setPosition(new Vec3(0, 0)) this.node.getComponent(Label).string = (text > 0) ? '+' + text : text + ''; } else { poxY = 200; PosX = PosX * direction; this.node.setPosition(new Vec3(PosX, 0)) this.node.getComponent(Label).string = text; speed = 0.5 this.node.getComponent(Label).fontSize = 20; // this.node.scale = new Vec3(0.3, 0.3, 1) } this.node.active = true; if (pic) { this.Sprite.State.spriteFrame = pic this.Sprite.State.node.setPosition(new Vec3(-(this.Sprite.State.getComponent(UITransform).width / 2 + this.node.getComponent(UITransform).width), 1.2)) } this.node.getComponent(Label).color = color; // tween(this.node.getComponent(UIOpacity)).to(speed, { opacity: 0 }).start(); tween(this.node).by(0.1, { scale: new Vec3(2.2, 2.2) }).to(speed, { position: v3(PosX, poxY) }).call(() => { this.node.scale = new Vec3(1, 1, 1) this.node.getComponent(UIOpacity).opacity = 255; this.node.active = false; FloatTextPool.putNode(this); }).start(); } protected onDestroy() { //如果该组件有事件自行取消注释 //Framework.event.removeEvent(this); super.onDestroy(); } //节点被放入池中时调用 unuse() { } //节点从池中取出时调用 reuse(...val: any[]) { } }