game.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. "use strict";
  2. require('adapter-min.js')
  3. __globalAdapter.init();
  4. // 判断版本号
  5. function compareVersion(v1, v2) {
  6. v1 = v1.split(".");
  7. v2 = v2.split(".");
  8. const len = Math.max(v1.length, v2.length);
  9. while (v1.length < len) {
  10. v1.push("0");
  11. }
  12. while (v2.length < len) {
  13. v2.push("0");
  14. }
  15. for (let i = 0; i < len; i++) {
  16. const num1 = parseInt(v1[i]);
  17. const num2 = parseInt(v2[i]);
  18. if (num1 > num2) {
  19. return 1;
  20. }
  21. if (num1 < num2) {
  22. return -1;
  23. }
  24. }
  25. return 0;
  26. }
  27. // 注入引擎,加载游戏
  28. var loaded = false;
  29. function loadGame() {
  30. if (loaded) {
  31. return;
  32. }
  33. // requirePlugin('cocos');//勾选了引擎分离
  34. //需要再game.json加入插件
  35. // "cocos": {
  36. // "provider": "wx7095f7fa398a2f30",
  37. // "version": "2.4.13",
  38. // "path": "cocos"
  39. // },
  40. require('cocos/cocos2d-js-min.js');//未勾选引擎分离
  41. __globalAdapter.adaptEngine();
  42. require('./ccRequire');
  43. require('./src/settings');
  44. require('./main');
  45. cc.view._maxPixelRatio = 4;
  46. if (cc.sys.platform !== cc.sys.WECHAT_GAME_SUB) {
  47. // Release Image objects after uploaded gl texture
  48. cc.macro.CLEANUP_IMAGE_CACHE = true;
  49. }
  50. require('./libs/htkSdk_gfWxXyx.js')
  51. window.boot();
  52. }
  53. // 当基础库版本>=2.1.0才能使用分包能力,当不支持分包功能时,会下载完整包,因此不需要展示加载封面
  54. if (compareVersion(wx.getSystemInfoSync().SDKVersion, '2.1.0') > -1) {
  55. try {
  56. // 在加载子包前,先加载封面插件
  57. GameGlobal.LoadingManager = requirePlugin("MinigameLoading", {
  58. customEnv: {
  59. wx,
  60. canvas,
  61. },
  62. }).default;
  63. GameGlobal.LoadingManager.create({
  64. images: [
  65. {
  66. // src: 'images/background.jpg'
  67. }
  68. ],
  69. contextType: 'webgl',
  70. // contextAttributes在接入点封面插件前获取,不同游戏可能不同
  71. contextAttributes: {
  72. alpha: false,
  73. antialias: false,
  74. depth: true,
  75. desynchronized: false,
  76. failIfMajorPerformanceCaveat: false,
  77. powerPreference: "default",
  78. premultipliedAlpha: true,
  79. preserveDrawingBuffer: false,
  80. stencil: true,
  81. xrCompatible: false,
  82. },
  83. showLoading: true
  84. }).then(() => {
  85. // 封面图已显示
  86. }).catch((err) => {
  87. console.error('封面图显示失败')
  88. })
  89. } catch (error) {
  90. // 当前客户端不支持使用插件,会黑屏(占比小于1%)
  91. console.error('当前环境不支持使用插件', error);
  92. }
  93. loadGame()
  94. } else {
  95. // 不支持分包能力
  96. loadGame()
  97. }