Starting from version 1078, the API prefix has been changed from hbs to qg. The original prefix hbs is still supported.
Downloads subpackages and returns the LoadSubpackageTask object.
This API can be called in JavaScript code to download the designated subpackage (if the subpackage has not been downloaded) and load the game.js file (if the file has not been loaded).
Do not run qg.loadSubpackage repeatedly to load the same subpackage during the game execution unless the first loading fails. Even if you do so, the subpackage will not be downloaded repeatedly, and the game.js file in the subpackage will not be executed repeatedly.
Parameter | Type | Mandatory | Description |
|---|---|---|---|
subpackage | string | Yes | Subpackage name. |
success | function | No | Callback function triggered upon a successful API call. |
fail | function | No | Callback function triggered upon a failed API call. |
complete | function | No | If a function is passed, it will be called regardless of whether the API call succeeds or fails. |
Parameter | Type | Description |
|---|---|---|
LoadSubpackageTask | object | LoadSubpackageTask instance, used to obtain the subpackage loading status. |
Attribute | Type | Description |
|---|---|---|
onprogress | function | Callback function that listens for changes in the subpackage loading progress. |
Parameter | Type | Description |
|---|---|---|
progress | number | Subpackage download progress, in percentage. |
loadSize | number | Size of the downloaded data, in bytes. |
totalSize | number | Total data size, in bytes. |
onProgressCallback(res) {
console.log("onProgress" + JSON.stringify(res));
}
let loadSubpackageTask = qg.loadSubpackage({
subpackage: 'name',
success : function () {
console.log("loadSubpackage success" );
},
fail:function(){
console.log("loadSubpackage fail");
},
complete:function() {
console.log("loadSubpackage complete");
}
});
loadSubpackageTask.onprogress = this.onProgressCallback;