参考cocos论坛:http://forum.cocos.com/t/1-5-2-demo/48200
demo: https://github.com/zhangjiangyi/HallAndChild
主要的是实现下载子游戏、跳转到子游戏,然后由子游戏返回到大厅。
我们知道、在启动cocos工程的时候,首先要加载main.js文件,加载准备工作,执行一些配置操作。而由大厅跳转到子游戏的话我们是否需要知道子游戏的配置文件setting.js跟main.js。然后由大厅跳转到子游戏的话其实就是获取子游戏的main.js文件就行了。
首先就是要用热更新的方式下载子游戏。但是热更新下载子游戏的话需要project.manifest文件跟远程文件做对比,但是一开始的时候是子游戏是空空如也的,那就只能用远程的方式获取project.manifest文件,然后进行热更新了。
checkUpdate: function () {
let UIRLFILE = "http://192.168.92.59/update/remote-assets";
let remoteManifestUrl = this._storagePath + "/project.manifest";
this.manifestUrl = remoteManifestUrl;
let customManifestStr = JSON.stringify({
"packageUrl": UIRLFILE,
"remoteManifestUrl": UIRLFILE + "/project.manifest",
"remoteVersionUrl": UIRLFILE + "/version.manifest",
"version": "1.0.0.0",
"assets": {},
"searchPaths": []
});
this._checkListener = new jsb.EventListenerAssetsManager(this._am, this.checkCb.bind(this));
cc.eventManager.addListener(this._checkListener, 1);
if (this._am.getState() === jsb.AssetsManager.State.UNINITED) {
if (jsb.fileUtils.isFileExist(remoteManifestUrl)) {
console.log('加载本地Manifest');
this._am.loadLocalManifest(this.manifestUrl);
} else {
console.log('加载网络Manifest');
let manifest = new jsb.Manifest(customManifestStr, this._storagePath);
this._am.loadLocalManifest(manifest, this._storagePath);
}
}
this.prmopt.string = '正在检查版本信息';
this._am.checkUpdate();
},
https://blog.csdn.net/a641832648/article/details/79451030(请跳转)
---------------------
作者:Burnner
来源:CSDN
原文:https://blog.csdn.net/a641832648/article/details/79451030
版权声明:本文为博主原创文章,转载请附上博文链接!