start.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { _decorator, Component, game, instantiate, Label, Node, ProgressBar } from 'cc';
  2. import { ch_start_pack } from '../ch/start/ch_start_pack';
  3. import ch_sign from '../ch/sign/sign';
  4. import { MyGame } from './Game/MyGame';
  5. import { LoadRes } from './Config/LoadRes';
  6. const { ccclass, property } = _decorator;
  7. @ccclass('start')
  8. export class start extends ch_start_pack {
  9. @property(Node)
  10. private loadingPanel: Node = null;
  11. @property(Node)
  12. private progressBarNode: Node = null; // 进度条节点
  13. private totalResources: number = 17; // 总资源数,根据实际情况调整
  14. private loadedResources: number = 0;
  15. async start() {
  16. this.loadingPanel = this.node.getChildByName("LoadingPanel");
  17. this.progressBarNode = this.node.getChildByPath("LoadingPanel/ProgressBar");
  18. // 设置游戏帧率为60帧/秒
  19. game.frameRate = 60;
  20. if (MyGame.getInstance().getLastScene() == " ") {
  21. let ret = await this.try_init();
  22. chsdk.get_player_info();
  23. await MyGame.getInstance().loadData();
  24. ch_sign.getInstance().init(1, MyGame.getInstance().getSignData(), 7);
  25. MyGame.getInstance().MyPlayerInfo();
  26. }
  27. MyGame.getInstance().MyRankInfo();
  28. LoadRes.getInstance().setOnResourceLoaded(this.updateProgressBar.bind(this));
  29. LoadRes.getInstance().StartLoadRes();
  30. }
  31. //ch.
  32. update(deltaTime: number) {
  33. }
  34. private updateProgressBar() {
  35. this.loadedResources++;
  36. let progress = this.loadedResources / this.totalResources;
  37. if (this.progressBarNode && this.progressBarNode.getComponent(ProgressBar)) {
  38. let progressBar = this.progressBarNode.getComponent(ProgressBar);
  39. progressBar.progress = progress;
  40. if (progress == 1) {
  41. //移除progressBarNode节点
  42. this.progressBarNode.removeFromParent();
  43. this.loadingPanel.removeFromParent();
  44. let ui_Show = instantiate(LoadRes.getInstance().ui_Show);
  45. ui_Show.setParent(this.node);
  46. }
  47. }
  48. }
  49. }