game.ejs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. function __initApp () { // init app
  2. globalThis.__wxRequire = require; // FIX: require cannot work in separate engine
  3. require('./web-adapter');
  4. var fundebug = require('./libs/fundebug.0.5.0.min.js')
  5. fundebug.init({
  6. apikey: "796a42db3e62a22c68543ea82568e9d30a7e3ab59b727c61b6711e923e2da876"
  7. });
  8. const firstScreen = require('./first-screen');
  9. <%- include(cocosTemplate, {}) %>
  10. // Adapt for IOS, swap if opposite
  11. const info = wx.getSystemInfoSync();
  12. if (canvas){
  13. var _w = canvas.width;
  14. var _h = canvas.height;
  15. if (info.screenWidth < info.screenHeight) {
  16. if (canvas.width > canvas.height) {
  17. _w = canvas.height;
  18. _h = canvas.width;
  19. }
  20. } else {
  21. if (canvas.width < canvas.height) {
  22. _w = canvas.height;
  23. _h = canvas.width;
  24. }
  25. }
  26. canvas.width = _w;
  27. canvas.height = _h;
  28. }
  29. // Adjust initial canvas size
  30. if (canvas && window.devicePixelRatio >= 2) {canvas.width *= info.devicePixelRatio; canvas.height *= info.devicePixelRatio;}
  31. const importMap = require("<%= importMapFile%>").default;
  32. System.warmup({
  33. importMap,
  34. importMapUrl: '<%= importMapFile%>',
  35. defaultHandler: (urlNoSchema) => {
  36. require('.' + urlNoSchema);
  37. },
  38. handlers: {
  39. 'plugin:': (urlNoSchema) => {
  40. requirePlugin(urlNoSchema);
  41. },
  42. 'project:': (urlNoSchema) => {
  43. require(urlNoSchema);
  44. },
  45. },
  46. });
  47. firstScreen.start('<%= alpha %>', '<%= antialias %>', '<%= useWebgl2 %>').then(() => {
  48. return System.import('<%= applicationJs %>');
  49. }).then((module) => {
  50. return firstScreen.setProgress(0.2).then(() => Promise.resolve(module));
  51. }).then(({ Application }) => {
  52. return new Application();
  53. }).then((application) => {
  54. return firstScreen.setProgress(0.4).then(() => Promise.resolve(application));
  55. }).then((application) => {
  56. return onApplicationCreated(application);
  57. }).catch((err) => {
  58. console.error(err);
  59. });
  60. function onApplicationCreated(application) {
  61. return System.import('cc').then((module) => {
  62. return firstScreen.setProgress(0.6).then(() => Promise.resolve(module));
  63. }).then((cc) => {
  64. require('./engine-adapter');
  65. return application.init(cc);
  66. }).then(() => {
  67. return firstScreen.end().then(() => application.start());
  68. });
  69. }
  70. } // init app
  71. // NOTE: on WeChat Android end, we can only get the correct screen size at the second tick of game.
  72. var sysInfo = wx.getSystemInfoSync();
  73. if (sysInfo.platform.toLocaleLowerCase() === 'android') {
  74. GameGlobal.requestAnimationFrame (__initApp);
  75. } else {
  76. __initApp();
  77. }