main.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. window.__zero__ = {
  2. "packageID": "1223"
  3. }
  4. window.boot = function () {
  5. var settings = window._CCSettings;
  6. window._CCSettings = undefined;
  7. var onStart = function () {
  8. cc.view.enableRetina(true);
  9. cc.view.resizeWithBrowserSize(true);
  10. var launchScene = settings.launchScene;
  11. // load scene
  12. cc.director.loadScene(launchScene, null,
  13. function () {
  14. console.log('Success to load scene: ' + launchScene);
  15. }
  16. );
  17. };
  18. var option = {
  19. id: 'GameCanvas',
  20. debugMode: settings.debug ? cc.debug.DebugMode.INFO : cc.debug.DebugMode.ERROR,
  21. showFPS: settings.debug,
  22. frameRate: 60,
  23. groupList: settings.groupList,
  24. collisionMatrix: settings.collisionMatrix,
  25. }
  26. cc.assetManager.init({
  27. bundleVers: settings.bundleVers,
  28. subpackages: settings.subpackages,
  29. remoteBundles: settings.remoteBundles,
  30. server: settings.server,
  31. subContextRoot: settings.subContextRoot
  32. });
  33. let { RESOURCES, INTERNAL, MAIN, START_SCENE } = cc.AssetManager.BuiltinBundleName;
  34. let bundleRoot = [INTERNAL];
  35. settings.hasResourcesBundle && bundleRoot.push(RESOURCES);
  36. settings.hasStartSceneBundle && bundleRoot.push(MAIN);
  37. var count = 0;
  38. function cb(err) {
  39. if (err) return console.error(err.message, err.stack);
  40. count++;
  41. if (count === bundleRoot.length + 1) {
  42. // if there is start-scene bundle. should load start-scene bundle in the last stage
  43. // Otherwise the main bundle should be the last
  44. cc.assetManager.loadBundle(settings.hasStartSceneBundle ? START_SCENE : MAIN, function (err) {
  45. if (!err) cc.game.run(option, onStart);
  46. });
  47. }
  48. }
  49. // load plugins
  50. cc.assetManager.loadScript(settings.jsList.map(function (x) { return 'src/' + x; }), cb);
  51. // load bundles
  52. for (let i = 0; i < bundleRoot.length; i++) {
  53. cc.assetManager.loadBundle(bundleRoot[i], cb);
  54. }
  55. };
  56. require('src/settings.js');
  57. require('src/cocos2d-runtime.js');
  58. require('libs/sdk-mini-game.js');
  59. if (CC_PHYSICS_BUILTIN || CC_PHYSICS_CANNON) {
  60. require('src/physics.js');
  61. }
  62. require('jsb-adapter/engine/index.js');
  63. cc.macro.CLEANUP_IMAGE_CACHE = true;
  64. window.boot();