Laya微信小游戏的4M包限制与动态资源

版本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。白名单并不是都生效。

猜你喜欢

转载自www.cnblogs.com/gamedaybyday/p/11545390.html