Cocos3 -- 4. js hot update, cocos34.js hot

Source: Internet
Author: User

Cocos3 -- 4. js hot update, cocos34.js hot

1. launch. js code:

// Launch: update filesvar _ failCount = 0; var AssetsManager = cc. scene. extend ({_ am: null, _ progress: null, _ percent: 0, _ percentByFile: 0, run: function () {// windows may not need update var not_update; if (cc. sys. OS = sys. OS _WINDOWS) {not_update = 1;} if (not_update |! Cc. sys. isNative) {this. loadGame (); return;} var layer = new cc. layer (); this. addChild (layer); this. _ progress = new cc. labelTTF. create ("download progress: 0%", "Arial", 12); this. _ progress. x = cc. winSize. width/2; this. _ progress. y = cc. winSize. height/2 + 50; layer. addChild (this. _ progress); // android:/data/com. huanle. magic/files/var storagePath = (jsb. fileUtils? Jsb. fileUtils. getWritablePath ():". /"); // storagePath indicates the local storage directory. The updated files will be downloaded to this directory. When the program loads scripts and resources, this directory will be preferentially queried. _ am = new jsb. assetsManager ("res/project. manifest ", storagePath); this. _ am. retain (); if (! This. _ am. getLocalManifest (). isLoaded () {cc. log ("Fail to update assets, step skipped. "); this. loadGame ();} else {var that = this; var listener = new jsb. eventListenerAssetsManager (this. _ am, function (event) {switch (event. getEventCode () {case jsb. eventAssetsManager. ERROR_NO_LOCAL_MANIFEST: cc. log ("No local manifest file found, skip assets update. "); that. loadGame (); break; case jsb. eventAssetsManager. UPDATE_PROGRESSION: that. _ percent = event. getPercent (); that. _ percentByFile = event. getPercentByFile (); cc. log (that. _ percent + "%"); var msg = event. getMessage (); if (msg) {cc. log (msg);} break; case jsb. eventAssetsManager. ERROR_DOWNLOAD_MANIFEST: case jsb. eventAssetsManager. ERROR_PARSE_MANIFEST: cc. log ("Fail to download manifest file, update skipped. "); that. loadGame (); break; case jsb. eventAssetsManager. ALREADY_UP_TO_DATE: case jsb. eventAssetsManager. UPDATE_FINISHED: cc. log ("Update finished. "); that. loadGame (); break; case jsb. eventAssetsManager. UPDATE_FAILED: cc. log ("Update failed. "+ event. getMessage (); _ failCount ++; if (_ failCount <5) {that. _ am. downloadFailedAssets ();} else {cc. log ("Reach maximum fail count, exit update process"); _ failCount = 0; that. loadGame ();} break; case jsb. eventAssetsManager. ERROR_UPDATING: cc. log ("Asset update error:" + event. getAssetId () + "," + event. getMessage (); that. loadGame (); break; case jsb. eventAssetsManager. ERROR_DECOMPRESS: cc. log (event. getMessage (); that. loadGame (); break; default: break;}); cc. eventManager. addListener (listener, 1); this. _ am. update (); cc. director. runScene (this);} this. schedule (this. updateProgress, 0.5) ;}, loadGame: function () {cc. loader. loadJs (["src/game. js "], function (err) {if (err) {cc. log ("error:" + err);} else {// run game logic game. run () ;}}) ;}, updateProgress: function (dt) {this. _ progress. string = "download progress:" + this. _ percent + "%" ;}, onExit: function () {this. _ am. release (); this. _ super ();}});

After the update, src/game. js is loaded, and game. run runs the main logic of the game. All the logic starts from there.


2. Configuration File

Add project. manifest in the res directory of the client:

{      "packageUrl" : "http://192.168.1.103/bw",    "remoteManifestUrl" : "http://192.168.1.103/bw/project.manifest",    "remoteVersionUrl" : "http://192.168.1.103/bw/version.manifest",    "version" : "1.0.0",    "groupVersions" : {        "1" : "1.0.0"      }  } 

The server can use everything to build http for testing:

Project. manifest:

{      "packageUrl" : "http://192.168.1.103/bw",      "remoteManifestUrl" : "http://192.168.1.103/bw/project.manifest",      "remoteVersionUrl" : "http://192.168.1.103/bw/version.manifest",     "version" : "1.0.5",      "groupVersions" : {          "1" : "1.0.5"      },    "engineVersion" : "3.0 rc0",      "assets" : {          "src/app.zip" : {"md5" : "6809C100A369FD8A79A97208B0278A2B",            "compressed" : true,            "group" : "1"          }      },      "searchPaths" : [          "src/"]  } 

Version. manifest:

{"packageUrl" : "http://192.168.1.103/bw","remoteManifestUrl" : "http://192.168.1.103/bw/project.manifest","remoteVersionUrl" : "http://192.168.1.103/bw/version.manifest","version" : "1.0.5","groupVersions": {"1" : "1.0.5"},"engineVersion" : "3.0 rc0"}

Do incremental package use groupVersions, can see http://cn.cocos2d-x.org/tutorial/show? Id = 1186

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.