相关文章推荐
眉毛粗的登山鞋  ·  cocos3——4.js熱更新·  2 月前    · 
眉毛粗的登山鞋  ·  SHIMA BOAT HOUSE ...·  2 月前    · 
眉毛粗的登山鞋  ·  GoDaddy SSL ...·  2 月前    · 
眉毛粗的登山鞋  ·  Express ...·  2 月前    · 

1.launch.js代碼:

// 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(下載進度:0%, Arial, 12);        this._progress.x = cc.winSize.width / 2;        this._progress.y = cc.winSize.height / 2 + 50;        layer.addChild(this._progress);        // android: /data/data/com.huanle.magic/files/          var storagePath = (jsb.fileUtils ? jsb.fileUtils.getWritablePath() : ./);// storagePath表示本地的儲存目錄,更新的檔案將下載到此目錄下,程式載入指令碼和資源時,也將優先從此目錄查詢          this._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 = 下載進度: + this._percent + %;    },    onExit: function () {        this._am.release();        this._super();    }});

更新完後會載入src/game.js,然後game.run跑遊戲的主邏輯,所有邏輯從那裡開始就可以了。

2.設定檔

在用戶端的res目錄下添加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.0,    groupVersions : {        1 : 1.0.0      }  } 

服務端可用everything搭建http做測試:

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}

做增量包的話要用groupVersions,可以參見www.bkjia.com

本文章原先以中文撰寫並發佈於 aliyun.com,亦設英文版本,僅作資訊用途。本網站不對文章的準確性,完整性或可靠性或其任何翻譯作出任何明示或暗示的陳述或保證。如對該文章有任何疑慮或投訴,請傳送電郵至 [email protected] 並提供相關疑慮或投訴的詳細說明。職員會於 5 個工作天內與您聯絡,一經驗證之後,即會刪除該侵權內容。

相關關鍵詞: node js sails js kitkat 4 4 4 kitkat 4 4 4 keystone js js encode js min js php 漂亮簡單Javascript 調色盤代碼 javascript的indexOf忽略大小寫方法_javascript技巧 JavaScript的parseInt 取整使用 用js一招破解所有網頁的加密原始碼的方法 Wireshark基本介紹和學習TCP三向交握,wiresharktcp jQuery AJAX timeout 逾時問題詳解,jqueryajax

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: [email protected] 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

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

Get Started for Free //intl.aliyun.com/pricing //intl.aliyun.com/trust-center //intl.aliyun.com/free-trial/enterprise //intl.aliyun.com/startup //intl.aliyun.com/partner