1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- function __initApp () { // init app
- globalThis.__wxRequire = require; // FIX: require cannot work in separate engine
- require('./web-adapter');
- const firstScreen = require('./first-screen');
- <%- include(cocosTemplate, {}) %>
- // Adapt for IOS, swap if opposite
- const info = wx.getSystemInfoSync();
- if (canvas){
- var _w = canvas.width;
- var _h = canvas.height;
- if (info.screenWidth < info.screenHeight) {
- if (canvas.width > canvas.height) {
- _w = canvas.height;
- _h = canvas.width;
- }
- } else {
- if (canvas.width < canvas.height) {
- _w = canvas.height;
- _h = canvas.width;
- }
- }
- canvas.width = _w;
- canvas.height = _h;
- }
- // Adjust initial canvas size
- if (canvas && window.devicePixelRatio >= 2) {canvas.width *= info.devicePixelRatio; canvas.height *= info.devicePixelRatio;}
- const importMap = require("<%= importMapFile%>").default;
- System.warmup({
- importMap,
- importMapUrl: '<%= importMapFile%>',
- defaultHandler: (urlNoSchema) => {
- require('.' + urlNoSchema);
- },
- handlers: {
- 'plugin:': (urlNoSchema) => {
- requirePlugin(urlNoSchema);
- },
- 'project:': (urlNoSchema) => {
- require(urlNoSchema);
- },
- },
- });
- firstScreen.start('<%= alpha %>', '<%= antialias %>', '<%= useWebgl2 %>').then(() => {
- return System.import('<%= applicationJs %>');
- }).then((module) => {
- return firstScreen.setProgress(0.2).then(() => Promise.resolve(module));
- }).then(({ Application }) => {
- return new Application();
- }).then((application) => {
- return firstScreen.setProgress(0.4).then(() => Promise.resolve(application));
- }).then((application) => {
- return onApplicationCreated(application);
- }).catch((err) => {
- console.error(err);
- });
- function onApplicationCreated(application) {
- return System.import('cc').then((module) => {
- return firstScreen.setProgress(0.6).then(() => Promise.resolve(module));
- }).then((cc) => {
- require('./engine-adapter');
- return application.init(cc);
- }).then(() => {
- return firstScreen.end().then(() => application.start());
- });
- }
- } // init app
- // NOTE: on WeChat Android end, we can only get the correct screen size at the second tick of game.
- var sysInfo = wx.getSystemInfoSync();
- if (sysInfo.platform.toLocaleLowerCase() === 'android') {
- GameGlobal.requestAnimationFrame (__initApp);
- } else {
- __initApp();
- }
|