how_to_play_game.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import global_model from "./global_model";
  2. const { ccclass, property } = cc._decorator;
  3. @ccclass
  4. export default class how_to_play_game extends cc.Component {
  5. @property(cc.Node)
  6. node_box: cc.Node = null;
  7. @property([cc.Node])
  8. showTiles: cc.Node[] = [];
  9. oldPos: any[] = [];
  10. @property(cc.Node)
  11. node_ui: cc.Node = null;
  12. start() {
  13. // 初始化节点相关属性
  14. this.initializeNodeAttributes();
  15. // 根据全局模型中所选关卡等级决定是否展示帮助界面并进行相应操作
  16. this.handleLevelBasedUI();
  17. }
  18. // 初始化节点的属性,如缩放、透明度等,并记录初始位置
  19. private initializeNodeAttributes(): void {
  20. this.node_ui.scale = 1;
  21. this.node.opacity = 255;
  22. this.node_ui.opacity = 0;
  23. this.oldPos[0] = this.showTiles[0].position;
  24. this.oldPos[1] = this.showTiles[1].position;
  25. this.oldPos[2] = this.showTiles[2].position;
  26. }
  27. // 根据全局模型中所选关卡等级来处理UI的显示与相关操作
  28. private handleLevelBasedUI(): void {
  29. if (global_model.game.selectedLevel === 1) {
  30. // 展示帮助界面相关节点并执行帮助动画
  31. this.showHelpUIAndAnimate();
  32. this.playHelp();
  33. } else {
  34. // 隐藏当前节点
  35. this.hideNode();
  36. }
  37. }
  38. // 展示帮助界面相关节点,设置其属性并启动动画
  39. private showHelpUIAndAnimate(): void {
  40. cc.tween(this.node_ui)
  41. .to(0.25, { scale: 1, opacity: 255 }, { easing: 'sineOut' })
  42. .start();
  43. }
  44. // 隐藏当前节点
  45. private hideNode(): void {
  46. this.node.active = false;
  47. }
  48. playHelp() {
  49. // 重置展示瓦片的缩放和位置
  50. this.resetShowTilesAttributes();
  51. // 对每个展示瓦片分别设置动画延迟和移动目标位置并启动动画
  52. this.animateShowTiles();
  53. // 在最后一个展示瓦片动画完成后执行后续操作
  54. this.handleShowTilesFinalAnimation();
  55. }
  56. // 重置展示瓦片的缩放为1,并设置回初始位置
  57. private resetShowTilesAttributes(): void {
  58. this.showTiles[0].scale = 1;
  59. this.showTiles[1].scale = 1;
  60. this.showTiles[2].scale = 1;
  61. this.showTiles[0].position = this.oldPos[0];
  62. this.showTiles[1].position = this.oldPos[1];
  63. this.showTiles[2].position = this.oldPos[2];
  64. }
  65. // 对每个展示瓦片分别设置动画延迟和移动目标位置并启动动画
  66. private animateShowTiles(): void {
  67. cc.tween(this.showTiles[0])
  68. .delay(0.9)
  69. .to(0.5, { x: -173.907, y: -231 })
  70. .start();
  71. cc.tween(this.showTiles[1])
  72. .delay(1.3)
  73. .to(0.5, { x: -86.697, y: -231 })
  74. .start();
  75. cc.tween(this.showTiles[2])
  76. .delay(1.7)
  77. .to(0.5, { x: 1.942, y: -231 })
  78. .start();
  79. }
  80. // 在最后一个展示瓦片动画完成后执行后续操作,如隐藏展示瓦片并再次执行相关逻辑(非递归)
  81. private handleShowTilesFinalAnimation(): void {
  82. cc.tween(this.showTiles[0])
  83. .to(0.2, { scale: 0 })
  84. .start();
  85. cc.tween(this.showTiles[1])
  86. .to(0.2, { scale: 0 })
  87. .start();
  88. cc.tween(this.showTiles[2])
  89. .to(0.2, { scale: 0 })
  90. .delay(0.8)
  91. .call(() => {
  92. // 这里不再递归调用playHelp,而是执行其他逻辑,比如重新展示UI等(这里暂未添加具体逻辑)
  93. })
  94. .start();
  95. }
  96. close(): void {
  97. this.hideNode();
  98. }
  99. }