how_to_play_game.ts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. this.initializeUI();
  14. this.initializeTiles();
  15. this.checkLevelAndPlayHelp();
  16. }
  17. initializeUI() {
  18. this.node_ui.scale = 1;
  19. this.node.opacity = 255;
  20. this.node_ui.opacity = 0;
  21. }
  22. initializeTiles() {
  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. checkLevelAndPlayHelp() {
  28. if (global_model.game.selectedLevel == 1) {
  29. this.showHelpUI();
  30. this.playHelp();
  31. } else {
  32. this.deactivateNode();
  33. }
  34. }
  35. showHelpUI() {
  36. cc.tween(this.node_ui).to(0.25, { scale: 1, opacity: 255 }, { easing: 'sineOut' }).start();
  37. }
  38. deactivateNode() {
  39. this.node.active = false;
  40. }
  41. playHelp() {
  42. this.resetTiles();
  43. this.animateTiles();
  44. }
  45. resetTiles() {
  46. this.showTiles[0].scale = 1;
  47. this.showTiles[1].scale = 1;
  48. this.showTiles[2].scale = 1;
  49. this.showTiles[0].position = this.oldPos[0];
  50. this.showTiles[1].position = this.oldPos[1];
  51. this.showTiles[2].position = this.oldPos[2];
  52. }
  53. animateTiles() {
  54. cc.tween(this.showTiles[0]).delay(0.9).to(0.5, { x: -173.907, y: -231 }).start();
  55. cc.tween(this.showTiles[1]).delay(1.3).to(0.5, { x: -86.697, y: -231 }).start();
  56. cc.tween(this.showTiles[2]).delay(1.7).to(0.5, { x: 1.942, y: -231 }).delay(0.1).call(() => {
  57. this.shrinkTiles();
  58. this.repeatHelpAnimation();
  59. }).start();
  60. }
  61. shrinkTiles() {
  62. cc.tween(this.showTiles[0]).to(0.2, { scale: 0 }).start();
  63. cc.tween(this.showTiles[1]).to(0.2, { scale: 0 }).start();
  64. cc.tween(this.showTiles[2]).to(0.2, { scale: 0 }).start();
  65. }
  66. repeatHelpAnimation() {
  67. cc.tween(this.showTiles[2]).delay(0.8).call(() => {
  68. this.playHelp();
  69. }).start();
  70. }
  71. close(): void {
  72. this.node.active = false;
  73. }
  74. }