main.795c9.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. window.boot = function () {
  2. var settings = window._CCSettings;
  3. window._CCSettings = undefined;
  4. var onProgress = null;
  5. var RESOURCES = cc.AssetManager.BuiltinBundleName.RESOURCES;
  6. var INTERNAL = cc.AssetManager.BuiltinBundleName.INTERNAL;
  7. var MAIN = cc.AssetManager.BuiltinBundleName.MAIN;
  8. function setLoadingDisplay () {
  9. // Loading splash scene
  10. var splash = document.getElementById('splash');
  11. var progressBar = splash.querySelector('.progress-bar span');
  12. onProgress = function (finish, total) {
  13. var percent = 100 * finish / total;
  14. if (progressBar) {
  15. progressBar.style.width = percent.toFixed(2) + '%';
  16. }
  17. };
  18. splash.style.display = 'block';
  19. progressBar.style.width = '0%';
  20. cc.director.once(cc.Director.EVENT_AFTER_SCENE_LAUNCH, function () {
  21. setTimeout(()=>{
  22. splash.style.display = 'none';
  23. }, 1000);
  24. });
  25. }
  26. var onStart = function () {
  27. cc.view.enableRetina(true);
  28. cc.view.resizeWithBrowserSize(true);
  29. if (cc.sys.isBrowser) {
  30. setLoadingDisplay();
  31. }
  32. if (cc.sys.isMobile) {
  33. if (settings.orientation === 'landscape') {
  34. cc.view.setOrientation(cc.macro.ORIENTATION_LANDSCAPE);
  35. }
  36. else if (settings.orientation === 'portrait') {
  37. cc.view.setOrientation(cc.macro.ORIENTATION_PORTRAIT);
  38. }
  39. cc.view.enableAutoFullScreen([
  40. cc.sys.BROWSER_TYPE_BAIDU,
  41. cc.sys.BROWSER_TYPE_BAIDU_APP,
  42. cc.sys.BROWSER_TYPE_WECHAT,
  43. cc.sys.BROWSER_TYPE_MOBILE_QQ,
  44. cc.sys.BROWSER_TYPE_MIUI,
  45. cc.sys.BROWSER_TYPE_HUAWEI,
  46. cc.sys.BROWSER_TYPE_UC,
  47. ].indexOf(cc.sys.browserType) < 0);
  48. }
  49. // Limit downloading max concurrent task to 2,
  50. // more tasks simultaneously may cause performance draw back on some android system / browsers.
  51. // You can adjust the number based on your own test result, you have to set it before any loading process to take effect.
  52. if (cc.sys.isBrowser && cc.sys.os === cc.sys.OS_ANDROID) {
  53. cc.assetManager.downloader.maxConcurrency = 2;
  54. cc.assetManager.downloader.maxRequestsPerFrame = 2;
  55. }
  56. var launchScene = settings.launchScene;
  57. var bundle = cc.assetManager.bundles.find(function (b) {
  58. return b.getSceneInfo(launchScene);
  59. });
  60. bundle.loadScene(launchScene, null, onProgress,
  61. function (err, scene) {
  62. if (!err) {
  63. cc.director.runSceneImmediate(scene);
  64. if (cc.sys.isBrowser) {
  65. // show canvas
  66. var canvas = document.getElementById('GameCanvas');
  67. canvas.style.visibility = '';
  68. var div = document.getElementById('GameDiv');
  69. if (div) {
  70. div.style.backgroundImage = '';
  71. }
  72. console.log('Success to load scene: ' + launchScene);
  73. }
  74. }
  75. }
  76. );
  77. };
  78. var option = {
  79. id: 'GameCanvas',
  80. debugMode: settings.debug ? cc.debug.DebugMode.INFO : cc.debug.DebugMode.ERROR,
  81. showFPS: settings.debug,
  82. frameRate: 60,
  83. groupList: settings.groupList,
  84. collisionMatrix: settings.collisionMatrix,
  85. };
  86. cc.assetManager.init({
  87. bundleVers: settings.bundleVers,
  88. remoteBundles: settings.remoteBundles,
  89. server: settings.server
  90. });
  91. var bundleRoot = [INTERNAL];
  92. settings.hasResourcesBundle && bundleRoot.push(RESOURCES);
  93. var count = 0;
  94. function cb (err) {
  95. if (err) return console.error(err.message, err.stack);
  96. count++;
  97. if (count === bundleRoot.length + 1) {
  98. cc.assetManager.loadBundle(MAIN, function (err) {
  99. if (!err) cc.game.run(option, onStart);
  100. });
  101. }
  102. }
  103. cc.assetManager.loadScript(settings.jsList.map(function (x) { return 'src/' + x;}), cb);
  104. for (var i = 0; i < bundleRoot.length; i++) {
  105. cc.assetManager.loadBundle(bundleRoot[i], cb);
  106. }
  107. };
  108. if (window.jsb) {
  109. var isRuntime = (typeof loadRuntime === 'function');
  110. if (isRuntime) {
  111. require('src/settings.c5c45.js');
  112. require('src/cocos2d-runtime.js');
  113. if (CC_PHYSICS_BUILTIN || CC_PHYSICS_CANNON) {
  114. require('src/physics.js');
  115. }
  116. require('jsb-adapter/engine/index.js');
  117. }
  118. else {
  119. require('src/settings.c5c45.js');
  120. require('src/cocos2d-jsb.js');
  121. if (CC_PHYSICS_BUILTIN || CC_PHYSICS_CANNON) {
  122. require('src/physics.js');
  123. }
  124. require('jsb-adapter/jsb-engine.js');
  125. }
  126. cc.macro.CLEANUP_IMAGE_CACHE = true;
  127. window.boot();
  128. }