Tips.ts 986 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Learn TypeScript:
  2. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
  3. // Learn Attribute:
  4. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
  5. // Learn life-cycle callbacks:
  6. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html
  7. import EventName from "../EventName/EventName";
  8. import MyComponent from "../Template/MyComponent";
  9. const { ccclass, property } = cc._decorator;
  10. @ccclass
  11. export default class Tips extends MyComponent {
  12. @property(cc.Label)
  13. label: cc.Label = null;
  14. onLoad(): void {
  15. this.node.opacity = 0
  16. this.regEvent(EventName.Tips, this.Tips, this)
  17. }
  18. Tips(str: string) {
  19. this.runAnima()
  20. this.label.string = str
  21. }
  22. runAnima() {
  23. this.node.opacity = 255
  24. cc.tween(this.node)
  25. .to(0.5, { opacity: 255 })
  26. .delay(1)
  27. .to(0.5, { opacity: 0 })
  28. .start()
  29. }
  30. }