Main.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import { Component, game, UIRenderer, _decorator, Game, SpriteFrame, ProgressBar } from 'cc';
  2. import { ViewID } from '../framework/config/LayerConf';
  3. import { Framework } from '../framework/Framework';
  4. import { GameEvent } from './data/GameEvent';
  5. import { MaterialUtil } from '../framework/util/MaterialUtil';
  6. import { NetManager } from './common/NetManager';
  7. import { FrameworkConf } from '../framework/config/FrameworkConf';
  8. import { resLoader } from '../framework/res/ResLoader';
  9. const { ccclass, property } = _decorator;
  10. // export let NetMgr: NetManager = null;
  11. //临时解决透明度为0还会渲染的bug
  12. // UIRenderer.prototype.updateAssembler = function updateAssembler(render: any) {
  13. // if (this._renderDataFlag) {
  14. // this._assembler!.updateRenderData(this, render);
  15. // this._renderDataFlag = false;
  16. // }
  17. // if (render._pOpacity > 0 && this._renderFlag) {
  18. // // console.log(render);
  19. // this._render(render);
  20. // }
  21. // }
  22. game.frameRate = 59;
  23. // 获取URL参数的函数
  24. function getParameterByName(name) {
  25. let url = window.location.href;
  26. name = name.replace(/[\[\]]/g, "\\$&");
  27. const regex = new RegExp(`[?&]${name}(=([^&#]*)|&|#|$)`);
  28. const results = regex.exec(url);
  29. if (!results) return null;
  30. if (!results[2]) return '';
  31. return decodeURIComponent(results[2].replace(/\+/g, ' '));
  32. // return results[2].replace(/\+/g, ' ')
  33. }
  34. @ccclass('Main')
  35. export class Main extends Component {
  36. private _uid = "";
  37. //切换后台的起始时间 单位ms
  38. hideTime = 0;
  39. //重连的时间 超过2秒就重连 单位ms
  40. reconnectTime = 2000;
  41. onLoad() {
  42. Framework.event.addEvent(FrameworkConf.Event.GAME_SHOW, this.gameEvent_onShow, this);
  43. Framework.event.addEvent(FrameworkConf.Event.GAME_HIDE, this.gameEvent_onHide, this);
  44. let loginbg = this.node.getChildByPath('loginbg');
  45. let loadRes = [
  46. 'bomb/game/icon_1'
  47. ];
  48. let loadNum = 0;
  49. let maxLoadNum = loadRes.length; // + MaterialUtil.init资源数量
  50. let finishBack = () => {
  51. loadNum++;
  52. if (loadNum >= maxLoadNum) {
  53. }
  54. };
  55. MaterialUtil.init(finishBack);
  56. for (let index = 0; index < loadRes.length; index++) {
  57. const element = loadRes[index];
  58. let path = `texture/${element}/spriteFrame`
  59. resLoader.load('package', path, SpriteFrame, (error: Error, res: SpriteFrame) => {
  60. if (!error) {
  61. finishBack();
  62. }
  63. });
  64. }
  65. // Framework.layer.open(ViewID.TowerUI, null,{});
  66. // Framework.layer.open(ViewID.ZombieUI, null,{});
  67. Framework.layer.open(ViewID.LoginUI, null, () => {
  68. // this.node.getChildByPath('UICamera/loginbg').destroy()
  69. });
  70. // this.connect()
  71. }
  72. gameEvent_onShow() {
  73. // let time = Date.now() - this.hideTime
  74. // if(time > this.reconnectTime){
  75. // this.connect()
  76. // }
  77. }
  78. gameEvent_onHide() {
  79. // this.hideTime = Date.now()
  80. }
  81. }