GuideLabel.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Learn TypeScript:
  2. // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
  3. // Learn Attribute:
  4. // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
  5. // Learn life-cycle callbacks:
  6. // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
  7. const {ccclass, property} = cc._decorator;
  8. @ccclass
  9. export default class GuideLabel extends cc.Component {
  10. // LIFE-CYCLE CALLBACKS:
  11. // onLoad () {}
  12. private labelStr = ""
  13. private isShow = false
  14. start () {
  15. // if(this.isShow){
  16. // return
  17. // }
  18. this.setView()
  19. }
  20. setView(){
  21. this.node.color = cc.color(233,136,78)
  22. let label = this.node.getComponent(cc.Label)
  23. if(!cc.isValid(label)){
  24. return
  25. }
  26. // if(this.isShow){
  27. // return
  28. // }
  29. this.isShow = true
  30. label.enableBold = true
  31. // this.labelStr = label.string
  32. // this.showTalk(0,this.labelStr)
  33. }
  34. onEnable(){
  35. }
  36. showTalk(index: number, str: string) {
  37. index++
  38. if (index > str.length) {
  39. return
  40. }
  41. if(!cc.isValid(this.node)){
  42. return
  43. }
  44. let showStr = str.substr(0, index)
  45. this.node.getComponent(cc.Label).string = showStr
  46. this.scheduleOnce(() => {
  47. this.showTalk(index, str)
  48. }, 0.06)
  49. }
  50. // update (dt) {}
  51. }