目录

Loading by Subpackage

For quick games with extensive resources, Huawei offers a subpackage strategy. This approach allows a quick game package (up to 30 MB) to be divided into a main package and several subpackages based on specific rules. Players only download and load the main package upon entry; additional subpackages are downloaded on-demand during gameplay. This significantly reduces the initial loading time and minimizes data consumption.

If the packaged quick game exceeds 30 MB, use the subpackaging mode provided by your game engine. You can reduce the package size by offloading resources from each subpackage to a remote server. Reference strategies include those provided by Cocos and LayaAir.

Package Size Limits

Currently, released quick games with a package size exceeding 20 MB must be subpackaged.

Subpackaging Suggestions

Development Procedure

[h2]Configuring manifest.json

The following is an example of the directory structure after subpackaging:
├── assets
├── image
     └── icons.png 
     └── 1.png 
├── jsb-adapter
├── src
├── subpackages              // Subpackage directory.
      └── subpackageName1    // Subpackage 1.
             └── game.js     // Entry file of subpackage 1. The entry file of a subpackage must be named game.js.
             └── main.js
      └── subpackageName2    // Subpackage 2.
             └── config.3dbbc.json
             └── game.js     // Entry file of subpackage 2. The entry file of a subpackage must be named game.js.
├── game.js                  // Entry file of the main package.
├── manifest.json            // Configuration file.
  • A subpackage can contain multiple JS files, and its entry file must be named game.js. A game.js file cannot be defined as a subpackage on its own.
  • When game.js of a subpackage imports other internal JS files, the file paths must be defined from the root directory. For instance, if game.js in subpackageName1 needs to import main.js, the correct format is require('subpackageName1/main.js').
The subpackage configuration items in manifest.json are as follows:
{
   ...
   "subpackages":[
     {
       "name":"subpackageName1",     // Subpackage 1 name.
       "resource":"subpackageName1"  // Subpackage 1 path.
     },{
       "name":"subpackageName2",     // Subpackage 2 name.
       "resource":"subpackageName2"  // Subpackage 2 path.
     }
   ]
   ...
}

Files configured in subpackages will be packaged into several subpackages. Directories and files not configured in subpackages will be packaged into the main package.

[h2]Calling APIs

Call qg.loadSubpackage in the entry file game.js of the main package to download the specified subpackage and load its game.js file.

var task = qg.loadSubpackage({
        subpackage: 'subpackageName1',
        success : function () {
               console.log("loadSubpackage success");
        },
        fail:function(){
                console.log("loadSubpackage fail");
         },
        complete:function() {
                console.log("loadSubpackage complete");
        }
});
mycallback(res){  
      console.log("onProgress" +JSON.stringify(res));
}
task.onprogress=this.mycallback

Running/Debugging

Prior to release, you are advised to run and debug the subpackaged quick game in the latest version of QuickGameAssistant.

  1. Change the file name extension of the exported RPK file to .zip and decompress the file.
  2. Open a project in QuickGameAssistant and run and debug the subpackaged quick game. For details, please refer to Debugging and Analysis.

Links

[h2]FAQs

What should I do if subpackages of a runtime quick game occasionally fail to be loaded?