buildload.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import gameData from "../../configData/gameData";
  2. const {ccclass, property} = cc._decorator;
  3. @ccclass
  4. export default class buildload extends cc.Component {
  5. private loadCount = 0;
  6. onLoad () {
  7. if (Math.random() < 0.5) {
  8. this.node.getChildByName('b1').opacity = 0;
  9. this.node.getChildByName('b2').opacity = 255;
  10. }
  11. else {
  12. this.node.getChildByName('b1').opacity = 255;
  13. this.node.getChildByName('b2').opacity = 0;
  14. }
  15. this.loadCount = 0;
  16. this.showBulidAct();
  17. }
  18. private showBulidAct() {
  19. if (this.loadCount == 10000) {
  20. return;
  21. }
  22. let times = (Number(gameData.instance().game_Const[1][2]) - 0.3) / 0.05;
  23. this.loadCount += 200 / times;
  24. let myprogress = this.node.getChildByName('hp_3').getComponent(cc.ProgressBar);
  25. myprogress.progress = this.loadCount / 200;
  26. if (this.loadCount >= 200) {
  27. myprogress.node.opacity = 0;
  28. this.node.getChildByName('hp_bg').opacity = 0;
  29. this.node.getChildByName('b1').opacity = 0;
  30. this.node.getChildByName('b2').opacity = 0;
  31. this.node.getChildByName('act').opacity = 255;
  32. this.node.getChildByName('act').getComponent(cc.Animation).play();
  33. this.scheduleOnce(() => {
  34. this.node.destroy();
  35. }, 0.4);
  36. return;
  37. }
  38. this.scheduleOnce(() => {
  39. this.showBulidAct();
  40. }, 0.05);
  41. }
  42. public stopDelate()
  43. {
  44. this.loadCount = 10000;
  45. this.unscheduleAllCallbacks();
  46. this.node.destroy();
  47. }
  48. }