BloodLabel.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { _decorator, Component, Node, Animation } from 'cc';
  2. import { BitmapFont } from '../../core/ui/BitmapFont';
  3. import { HitData } from '../HitData';
  4. const { ccclass, property } = _decorator;
  5. @ccclass('BloodLabel')
  6. export class BloodLabel extends Component {
  7. @property({ type: Node, tooltip: "暴击组" }) cri: Node;
  8. @property({ type: Node, tooltip: "普通组" }) normal: Node;
  9. @property({ type: Node, tooltip: "技能组" }) skill: Node;
  10. @property({ type: Node, tooltip: "闪避" }) miss: Node;
  11. @property({ type: Animation, tooltip: "动画组件" }) animation: Animation;
  12. start() {
  13. this.animation.on(Animation.EventType.FINISHED, () => {
  14. this.node.destroy();
  15. }, this);
  16. }
  17. public setData(data: HitData): void {
  18. let hit = data.hit > 10000 ? (data.hit / 1000).toFixed(1) + "k" : data.hit + "";
  19. if (data.isMiss) {
  20. this.miss.active = true;
  21. } else {
  22. if (data.isCri) {
  23. this.cri.getComponent(BitmapFont).string = "-" + hit;
  24. this.cri.active = true;
  25. } else if (data.isSkill) {
  26. this.skill.getComponent(BitmapFont).string = "-" + hit;
  27. this.skill.active = true;
  28. } else {
  29. this.normal.getComponent(BitmapFont).string = "-" + hit;
  30. this.normal.active = true;
  31. }
  32. }
  33. this.animation.play();
  34. }
  35. }