WeChat mini game resource loading

WeChat mini game resource loading

Please follow me on Weibo: @NormanLin_BadPixel Bad Pixel


We know that the package size of the mini-game cannot exceed 4MB, and additional resources must be downloaded through the network request.

CCC has already done most of the processing of resource loading for us, we just need to use it.

Here I teach you how to use the local server to test.

ccc official tutorial .

Download NodeJs

  1. Download address .
  2. Install
  3. Open the cmd administrator window and enter npm -v to check whether node.js is installed successfully: imagehere my nodeJs version is 5.6.0.
  4. Then enter npm install http-server -g on the command line to install the local server globally: I have already installed it, and the texture has no reference value.
  5. Create a directory to store project resource files, such as F:\TempGameRes . Open this directory, press Shift + right button , and open a console window here. Or just use cmd + cd to enter the directory.
  6. Enter http-server on the command line to open the server under this file:image
  7. Open the browser, enter the domain name and port number (you can try several, use 127.0.0.1:8080 locally, try the first one on the LAN), at this time, you should be able to see our files on the browser Folder structure, but it is now an empty folder where we need to put our project resources.
  8. Export the cocos project and check MD5 Cache. Because we are going to debug with a real machine, I use the first address.image
  9. After building, cut the res folder in the project directory to the resource directory created earlier. Refresh your browser to see our folder structure.
  10. Open WeChat developer tools, check the details page in the upper right cornerimage
  11. Compile and run.

We see that the game.json file in the project directory is a bit different from what we used before.

require('libs/weapp-adapter/index');
var Parser = require('libs/xmldom/dom-parser');
window.DOMParser = Parser.DOMParser;
require('libs/wx-downloader.js');
wxDownloader.REMOTE_SERVER_ROOT = "http://192.168.1.231:8080";
wxDownloader.SUBCONTEXT_ROOT = "";
require('src/settings.57089');
require('main.23b04');

In addition to wxDownloader.REMOTE_SERVER_ROOT , we also see wxDownloader.SUBCONTEXT_ROOT . This should be the resource server address of the subdomain. The practice should be the same as that of the main domain, just repeat the steps.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325838177&siteId=291194637