版本2.1.1.
由於有4m包限制,所以一般小游戲項目分成主包+遠程資源。
現在我新建一個remote目錄,該目錄下資源不發布到微信小游戲目錄下,而是服務器遠程加載。
發布時,勾線是否提取本地包
遠程資源目錄remote不需要勾選
這是發布出的項目有兩個文件夾,其中wxgame是常規項目,wxgame_pack是不含remote文件夾的項目
那么我們微信提交時,只需要提交主包wxgame_pack就行了。將remote資源放到服務器動態加載。
平時我們使用remote的圖片是這樣的。加載remote.atlas圖集,並顯示其中test1.jpg
Laya.loader.load("res/atlas/remote.atlas", Laya.Handler.create(this, ()=>{ let sp:Laya.Sprite = new Laya.Sprite(); sp.texture = Laya.loader.getRes("remote/test1.jpg"); this.addChild(sp); }));
Laya論壇有個方法。就是設置Url.basePath。這樣load的每個路徑都會自動加上basePath。
比如我們的遠程服務器路徑是http://127.0.0.1:8011/wxgame/,如下圖設置。
MiniAdpter.nativefiles白名單里的資源只會從本地加載,而沒有在名單里的資源都從遠程服務器加載。
Laya.URL.basePath = "http://127.0.0.1:8011/wxgame/"; Laya["MiniAdpter"].nativefiles = [ "wxlocal", "res/atlas/comp.atlas" ]
目前Laya這塊有Bug。白名單並不是都生效。