tips.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { _decorator, Component, Vec3, tween, isValid, UIOpacity, Color, Label, UITransform } from 'cc';
  2. import { poolManager } from './../../framework/poolManager';
  3. const { ccclass, property } = _decorator;
  4. @ccclass('tips')
  5. export class tips extends Component {
  6. @property(Label)
  7. public lbTips: Label = null!;
  8. @property(UIOpacity)
  9. public UIOpacityBg: UIOpacity = null!;
  10. public show(content: string, callback?: Function) {
  11. let size = this.lbTips?.node?.getComponent(UITransform)?.contentSize;
  12. if (!isValid(size)) {//size不存在,自我销毁
  13. poolManager.instance.putNode(this.node);
  14. return;
  15. }
  16. this.lbTips.string = content;
  17. this.UIOpacityBg.opacity = 255;
  18. this.node.setPosition(0, 220, 0);
  19. this.scheduleOnce(() => {
  20. tween(this.node)
  21. .to(0.9, { position: new Vec3(0, 450, 0) }, { easing: 'smooth' })
  22. .call(() => {
  23. callback && callback();
  24. poolManager.instance.putNode(this.node);
  25. })
  26. .start();
  27. tween(this.UIOpacityBg)
  28. .to(0.6, { opacity: 220 }, { easing: 'smooth' })
  29. .to(0.3, { opacity: 0 }, { easing: 'smooth' })
  30. .start();
  31. }, 0.8);
  32. }
  33. }