TipsAction.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { _decorator, Component, Label, Node, tween, Vec3 } from 'cc';
  2. import { Clips } from './Enums';
  3. import { AudioMgr } from './AudioMgr';
  4. import { Global } from './Global';
  5. const { ccclass, property } = _decorator;
  6. @ccclass('TipsAction')
  7. export class TipsAction extends Component {
  8. @property({ type: Label })
  9. level_label: Label = null;
  10. msg: string[] = [];
  11. running = false;
  12. start() {
  13. this.set_default();
  14. }
  15. set_default() {
  16. this.node.setPosition(0, -1000)
  17. }
  18. update(deltaTime: number) {
  19. }
  20. public show(str: string) {
  21. this.msg.push(str);
  22. // console.log("TipsAction>>>",str,this.level_label);
  23. if (!this.running) {
  24. this.play();
  25. }
  26. }
  27. /**
  28. *
  29. * @returns
  30. */
  31. private play() {
  32. let self = this;
  33. if (self.msg.length == 0) {
  34. self.running = false;
  35. return;
  36. }
  37. self.running = true;
  38. self.level_label.string = self.msg.shift();
  39. self.set_default();
  40. tween(self.node)
  41. .to(0.35, { position: new Vec3(0, 0, 0) }, Global.our_easing)
  42. .delay(1)
  43. .to(0.1, { position: new Vec3(0, 1000, 0) }, Global.our_easing)
  44. .call(() => {
  45. AudioMgr.ins.playSound(Clips.reng);
  46. // this.set_default();
  47. self.play();
  48. })
  49. .start();
  50. }
  51. }