Guide.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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, { GuideType } from "../EventName/EventName";
  8. import LocalData from "../LocalData";
  9. import MyComponent from "../Template/MyComponent";
  10. const { ccclass, property } = cc._decorator;
  11. @ccclass
  12. export default class Guide extends MyComponent {
  13. @property(sp.Skeleton)
  14. Spine: sp.Skeleton = null;
  15. @property(cc.Node)
  16. BigDialogBox: cc.Node = null;
  17. @property(cc.Node)
  18. SmallDialogBox: cc.Node = null;
  19. @property(cc.Node)
  20. Hand: cc.Node = null;
  21. @property(cc.Node)
  22. Btn: cc.Node = null;
  23. start() {
  24. this.node.children.forEach(e => e.active = false)
  25. this.regEvent(EventName.ShowGuide, this.ShowGuide, this)
  26. }
  27. ShowGuide(str?: string) {
  28. //有记录了 直接返回
  29. if (LocalData.getInstance().getGuide(str)) {
  30. return
  31. }
  32. LocalData.getInstance().setGuide(str)
  33. this.showCommonGuide(() => {
  34. switch (str) {
  35. case GuideType.基本跳跃教学引导:
  36. //#region
  37. this.Spine.node.setScale(-2, 2)
  38. cc.tween(this.Spine.node)
  39. .to(1, { position: cc.v3(-240, -644) }, { easing: 'fadeOut' })
  40. .call(() => {
  41. this.Hand.active = true
  42. this.BigDialogBox.active = true
  43. this.BigDialogBox.getComponentInChildren(cc.Label).string = '请向下滑动屏幕使用抛物线跳跃。'
  44. this.showHandGuide()
  45. this.closeState = true
  46. })
  47. .start()
  48. //#endregion
  49. break;
  50. case GuideType.完整抛物线:
  51. //#region
  52. this.Spine.node.setScale(-2, 2)
  53. cc.tween(this.Spine.node)
  54. .to(1, { position: cc.v3(-240, -644) }, { easing: 'fadeOut' })
  55. .call(() => {
  56. this.BigDialogBox.active = true
  57. this.BigDialogBox.getComponentInChildren(cc.Label).string = '使用技能,可展示完整抛物线'
  58. this.closeState = true
  59. })
  60. .start()
  61. //#endregion
  62. break;
  63. default:
  64. break;
  65. }
  66. })
  67. }
  68. closeState = false
  69. clickBtn() {
  70. if (this.closeState) {
  71. this.closeState = false
  72. this.node.children.forEach(e => e.active = false)
  73. }
  74. }
  75. showCommonGuide(cb: Function) {
  76. this.Spine.node.setPosition(0, -500)
  77. this.BigDialogBox.active = false
  78. this.SmallDialogBox.active = false
  79. this.Hand.active = false
  80. this.Btn.active = true
  81. this.Spine.node.active = true
  82. let RoundState = this.Spine.setAnimation(0, '出场', false);
  83. this.scheduleOnce(() => {
  84. this.Spine.setAnimation(0, '待机', true);
  85. cb?.()
  86. }, RoundState.animationEnd)
  87. }
  88. showHandGuide() {
  89. if (this.Hand.active) {
  90. let spine = this.Hand.getComponent(sp.Skeleton)
  91. let RoundState = spine.setAnimation(0, '点击', false);
  92. this.scheduleOnce(() => {
  93. spine.setAnimation(0, '拉', false);
  94. this.scheduleOnce(() => {
  95. this.showHandGuide()
  96. }, 2)
  97. }, RoundState.animationEnd)
  98. }
  99. }
  100. clear() {
  101. LocalData.getInstance().$Guide = []
  102. LocalData.getInstance().save();
  103. }
  104. // update (dt) {}
  105. }