main.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. // QQPlay window need to be inited first
  2. if (false) {
  3. BK.Script.loadlib('GameRes://libs/qqplay-adapter.js');
  4. }
  5. var loadingBool = true;
  6. var loadingNum = 0;
  7. window.boot = function () {
  8. var settings = window._CCSettings;
  9. window._CCSettings = undefined;
  10. if (!settings.debug) {
  11. var uuids = settings.uuids;
  12. var rawAssets = settings.rawAssets;
  13. var assetTypes = settings.assetTypes;
  14. var realRawAssets = settings.rawAssets = {};
  15. for (var mount in rawAssets) {
  16. var entries = rawAssets[mount];
  17. var realEntries = realRawAssets[mount] = {};
  18. for (var id in entries) {
  19. var entry = entries[id];
  20. var type = entry[1];
  21. // retrieve minified raw asset
  22. if (typeof type === 'number') {
  23. entry[1] = assetTypes[type];
  24. }
  25. // retrieve uuid
  26. realEntries[uuids[id] || id] = entry;
  27. }
  28. }
  29. var scenes = settings.scenes;
  30. for (var i = 0; i < scenes.length; ++i) {
  31. var scene = scenes[i];
  32. if (typeof scene.uuid === 'number') {
  33. scene.uuid = uuids[scene.uuid];
  34. }
  35. }
  36. var packedAssets = settings.packedAssets;
  37. for (var packId in packedAssets) {
  38. var packedIds = packedAssets[packId];
  39. for (var j = 0; j < packedIds.length; ++j) {
  40. if (typeof packedIds[j] === 'number') {
  41. packedIds[j] = uuids[packedIds[j]];
  42. }
  43. }
  44. }
  45. var subpackages = settings.subpackages;
  46. for (var subId in subpackages) {
  47. var uuidArray = subpackages[subId].uuids;
  48. if (uuidArray) {
  49. for (var k = 0, l = uuidArray.length; k < l; k++) {
  50. if (typeof uuidArray[k] === 'number') {
  51. uuidArray[k] = uuids[uuidArray[k]];
  52. }
  53. }
  54. }
  55. }
  56. }
  57. function setLoadingDisplay() {
  58. // Loading splash scene
  59. var splash = document.getElementById('splash');
  60. // var progressBar = splash.querySelector('.progress-bar span');
  61. cc.loader.onProgress = function (completedCount, totalCount, item) {
  62. loadData.completedCount = completedCount;
  63. loadData.totalCount = totalCount;
  64. if (loadingBool) {
  65. var loadintT = document.getElementById("loadingText")
  66. }
  67. var percent = 100 * completedCount / totalCount;
  68. if (loadingBool && loadingNum >= 1 && totalCount > 1) {
  69. if (percent.toFixed(0) >= 100) {
  70. loadintT.innerHTML = 'loading......100' + '%';
  71. setTimeout(function () {
  72. loadingBool = false;
  73. loadintT.remove();
  74. }, 0.1 * 1000);
  75. clearInterval(timer);
  76. }
  77. }
  78. loadingNum++;
  79. // if(loadingBool){
  80. // var loadintT = document.getElementById("loadingText")
  81. // }
  82. // var percent = 100 * completedCount / totalCount;
  83. // if(loadingBool && loadingNum >= 1){
  84. // console.log("dskpi",loadingNum);
  85. // loadintT.innerHTML = 'loading......' + parseInt(percent) + '%';
  86. // if(percent.toFixed(0) >= 100){
  87. // loadingBool = false;
  88. // loadintT.remove();
  89. // }
  90. // }
  91. // loadingNum ++;
  92. // var percent = 100 * completedCount / totalCount;
  93. // if (progressBar) {
  94. // progressBar.style.width = percent.toFixed(2) + '%';
  95. // }
  96. };
  97. splash.style.display = 'block';
  98. // progressBar.style.width = '0%';
  99. cc.director.once(cc.Director.EVENT_AFTER_SCENE_LAUNCH, function () {
  100. splash.style.display = 'none';
  101. });
  102. }
  103. var onStart = function () {
  104. cc.loader.downloader._subpackages = settings.subpackages;
  105. cc.view.enableRetina(true);
  106. cc.view.resizeWithBrowserSize(true);
  107. if (!false && !false) {
  108. if (cc.sys.isBrowser) {
  109. setLoadingDisplay();
  110. }
  111. if (cc.sys.isMobile) {
  112. if (settings.orientation === 'landscape') {
  113. cc.view.setOrientation(cc.macro.ORIENTATION_LANDSCAPE);
  114. } else if (settings.orientation === 'portrait') {
  115. cc.view.setOrientation(cc.macro.ORIENTATION_PORTRAIT);
  116. }
  117. // cc.view.enableAutoFullScreen([
  118. // cc.sys.BROWSER_TYPE_BAIDU,
  119. // cc.sys.BROWSER_TYPE_WECHAT,
  120. // cc.sys.BROWSER_TYPE_MOBILE_QQ,
  121. // cc.sys.BROWSER_TYPE_MIUI,
  122. // ].indexOf(cc.sys.browserType) < 0);
  123. cc.view.enableAutoFullScreen(false);
  124. }
  125. // Limit downloading max concurrent task to 2,
  126. // more tasks simultaneously may cause performance draw back on some android system / browsers.
  127. // You can adjust the number based on your own test result, you have to set it before any loading process to take effect.
  128. if (cc.sys.isBrowser && cc.sys.os === cc.sys.OS_ANDROID) {
  129. cc.macro.DOWNLOAD_MAX_CONCURRENT = 2;
  130. }
  131. }
  132. // function loadScene(launchScene) {
  133. // cc.director.loadScene(launchScene, null,
  134. // function () {
  135. // if (cc.sys.isBrowser) {
  136. // // show canvas
  137. // var canvas = document.getElementById('GameCanvas');
  138. // canvas.style.visibility = '';
  139. // var div = document.getElementById('GameDiv');
  140. // if (div) {
  141. // div.style.backgroundImage = '';
  142. // }
  143. // }
  144. // cc.loader.onProgress = null;
  145. // console.log('Success to load scene: ' + launchScene);
  146. // }
  147. // );
  148. // }
  149. var launchScene = settings.launchScene;
  150. // load scene
  151. // loadScene(launchScene);
  152. var canvas;
  153. if (cc.sys.isBrowser) {
  154. canvas = document.getElementById('GameCanvas');
  155. }
  156. var launchScene = settings.launchScene;
  157. console.log("landscape,", launchScene);
  158. var MainManger = __require("MainManage");
  159. MainManger.init(launchScene, cc.sys.isBrowser, canvas.style.visibility);
  160. };
  161. // jsList
  162. var jsList = settings.jsList;
  163. if (false) {
  164. BK.Script.loadlib();
  165. } else {
  166. var bundledScript = settings.debug ? 'src/project.dev.js' : 'src/project.js';
  167. if (jsList) {
  168. jsList = jsList.map(function (x) {
  169. return 'src/' + x;
  170. });
  171. jsList.push(bundledScript);
  172. } else {
  173. jsList = [bundledScript];
  174. }
  175. }
  176. var option = {
  177. id: 'GameCanvas',
  178. scenes: settings.scenes,
  179. debugMode: settings.debug ? cc.debug.DebugMode.INFO : cc.debug.DebugMode.ERROR,
  180. showFPS: !false && settings.debug,
  181. frameRate: 60,
  182. jsList: jsList,
  183. groupList: settings.groupList,
  184. collisionMatrix: settings.collisionMatrix,
  185. }
  186. // init assets
  187. cc.AssetLibrary.init({
  188. libraryPath: 'res/import',
  189. rawAssetsBase: 'res/raw-',
  190. rawAssets: settings.rawAssets,
  191. packedAssets: settings.packedAssets,
  192. md5AssetsMap: settings.md5AssetsMap,
  193. subpackages: settings.subpackages
  194. });
  195. cc.game.run(option, onStart);
  196. };
  197. // main.js is qqplay and jsb platform entry file, so we must leave platform init code here
  198. if (false) {
  199. BK.Script.loadlib('GameRes://src/settings.js');
  200. BK.Script.loadlib();
  201. BK.Script.loadlib('GameRes://libs/qqplay-downloader.js');
  202. var ORIENTATIONS = {
  203. 'portrait': 1,
  204. 'landscape left': 2,
  205. 'landscape right': 3
  206. };
  207. BK.Director.screenMode = ORIENTATIONS[window._CCSettings.orientation];
  208. initAdapter();
  209. cc.game.once(cc.game.EVENT_ENGINE_INITED, function () {
  210. initRendererAdapter();
  211. });
  212. qqPlayDownloader.REMOTE_SERVER_ROOT = "";
  213. var prevPipe = cc.loader.md5Pipe || cc.loader.assetLoader;
  214. cc.loader.insertPipeAfter(prevPipe, qqPlayDownloader);
  215. window.boot();
  216. } else if (window.jsb) {
  217. var isRuntime = (typeof loadRuntime === 'function');
  218. if (isRuntime) {
  219. require('src/settings.js');
  220. require('src/cocos2d-runtime.js');
  221. require('jsb-adapter/engine/index.js');
  222. } else {
  223. require('src/settings.js');
  224. require('src/cocos2d-jsb.js');
  225. require('jsb-adapter/jsb-engine.js');
  226. }
  227. cc.macro.CLEANUP_IMAGE_CACHE = true;
  228. window.boot();
  229. }