Tips.ts 830 B

12345678910111213141516171819202122232425262728293031323334
  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. const { ccclass, property } = cc._decorator;
  8. @ccclass
  9. export default class Tips extends cc.Component {
  10. static Instance: Tips = null;
  11. onLoad() {
  12. Tips.Instance = this
  13. }
  14. show(str: string) {
  15. this.unscheduleAllCallbacks()
  16. let tips = this.node.getChildByName("tips")
  17. tips.active = true
  18. tips.getComponentInChildren(cc.Label).string = str
  19. this.scheduleOnce(() => {
  20. tips.active = false
  21. }, 1)
  22. }
  23. // update (dt) {}
  24. }